Transformations (#3174)
Adds the ability to provide `transformations` to modify the properties and resource options that will be used for any child resource of a component or stack.
This offers an "escape hatch" to modify the behaviour of a component by peeking behind it's abstraction. For example, it can be used to add a resource option (`additionalSecretOutputs`, `aliases`, `protect`, etc.) to a specific known child of a component, or to modify some input property to a child resource if the component does not (yet) expose the ability to control that input directly. It could also be used for more interesting scenarios - such as:
1. Automatically applying tags to all resources that support them in a stack (or component)
2. Injecting real dependencies between stringly-referenced resources in a Helm Chart
3. Injecting explicit names using a preferred naming convention across all resources in a stack
4. Injecting `import` onto all resources by doing a lookup into a name=>id mapping
Because this feature makes it possible to peek behind a component abstraction, it must be used with care in cases where the component is versioned independently of the use of transformations. Also, this can result in "spooky action at a distance", so should be used judiciously. That said - this can be used as an escape hatch to unblock a wide variety of common use cases without waiting on changes to be made in a component implementation.
Each transformation is passed the `resource`, `name`, `type`, `props` and `opts` that are passed into the `Resource` constructor for any resource descended from the resource that has the transformation applied. The transformation callback can optionally return alternate versions of the `props` and `opts` to be used in place of the original values provided to the resource constructor.
Fixes #2068.
2019-09-29 18:27:37 +00:00
|
|
|
// Copyright 2016-2018, Pulumi Corporation. All rights reserved.
|
2023-01-30 19:30:30 +00:00
|
|
|
//go:build !xplatform_acceptance
|
Transformations (#3174)
Adds the ability to provide `transformations` to modify the properties and resource options that will be used for any child resource of a component or stack.
This offers an "escape hatch" to modify the behaviour of a component by peeking behind it's abstraction. For example, it can be used to add a resource option (`additionalSecretOutputs`, `aliases`, `protect`, etc.) to a specific known child of a component, or to modify some input property to a child resource if the component does not (yet) expose the ability to control that input directly. It could also be used for more interesting scenarios - such as:
1. Automatically applying tags to all resources that support them in a stack (or component)
2. Injecting real dependencies between stringly-referenced resources in a Helm Chart
3. Injecting explicit names using a preferred naming convention across all resources in a stack
4. Injecting `import` onto all resources by doing a lookup into a name=>id mapping
Because this feature makes it possible to peek behind a component abstraction, it must be used with care in cases where the component is versioned independently of the use of transformations. Also, this can result in "spooky action at a distance", so should be used judiciously. That said - this can be used as an escape hatch to unblock a wide variety of common use cases without waiting on changes to be made in a component implementation.
Each transformation is passed the `resource`, `name`, `type`, `props` and `opts` that are passed into the `Resource` constructor for any resource descended from the resource that has the transformation applied. The transformation callback can optionally return alternate versions of the `props` and `opts` to be used in place of the original values provided to the resource constructor.
Fixes #2068.
2019-09-29 18:27:37 +00:00
|
|
|
|
|
|
|
package ints
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2021-03-17 13:20:05 +00:00
|
|
|
"github.com/pulumi/pulumi/pkg/v3/testing/integration"
|
|
|
|
"github.com/pulumi/pulumi/sdk/v3/go/common/resource"
|
|
|
|
"github.com/pulumi/pulumi/sdk/v3/go/common/tokens"
|
2020-09-02 16:11:15 +00:00
|
|
|
"github.com/stretchr/testify/assert"
|
Transformations (#3174)
Adds the ability to provide `transformations` to modify the properties and resource options that will be used for any child resource of a component or stack.
This offers an "escape hatch" to modify the behaviour of a component by peeking behind it's abstraction. For example, it can be used to add a resource option (`additionalSecretOutputs`, `aliases`, `protect`, etc.) to a specific known child of a component, or to modify some input property to a child resource if the component does not (yet) expose the ability to control that input directly. It could also be used for more interesting scenarios - such as:
1. Automatically applying tags to all resources that support them in a stack (or component)
2. Injecting real dependencies between stringly-referenced resources in a Helm Chart
3. Injecting explicit names using a preferred naming convention across all resources in a stack
4. Injecting `import` onto all resources by doing a lookup into a name=>id mapping
Because this feature makes it possible to peek behind a component abstraction, it must be used with care in cases where the component is versioned independently of the use of transformations. Also, this can result in "spooky action at a distance", so should be used judiciously. That said - this can be used as an escape hatch to unblock a wide variety of common use cases without waiting on changes to be made in a component implementation.
Each transformation is passed the `resource`, `name`, `type`, `props` and `opts` that are passed into the `Resource` constructor for any resource descended from the resource that has the transformation applied. The transformation callback can optionally return alternate versions of the `props` and `opts` to be used in place of the original values provided to the resource constructor.
Fixes #2068.
2019-09-29 18:27:37 +00:00
|
|
|
)
|
|
|
|
|
2020-09-02 16:11:15 +00:00
|
|
|
var Dirs = []string{
|
Transformations (#3174)
Adds the ability to provide `transformations` to modify the properties and resource options that will be used for any child resource of a component or stack.
This offers an "escape hatch" to modify the behaviour of a component by peeking behind it's abstraction. For example, it can be used to add a resource option (`additionalSecretOutputs`, `aliases`, `protect`, etc.) to a specific known child of a component, or to modify some input property to a child resource if the component does not (yet) expose the ability to control that input directly. It could also be used for more interesting scenarios - such as:
1. Automatically applying tags to all resources that support them in a stack (or component)
2. Injecting real dependencies between stringly-referenced resources in a Helm Chart
3. Injecting explicit names using a preferred naming convention across all resources in a stack
4. Injecting `import` onto all resources by doing a lookup into a name=>id mapping
Because this feature makes it possible to peek behind a component abstraction, it must be used with care in cases where the component is versioned independently of the use of transformations. Also, this can result in "spooky action at a distance", so should be used judiciously. That said - this can be used as an escape hatch to unblock a wide variety of common use cases without waiting on changes to be made in a component implementation.
Each transformation is passed the `resource`, `name`, `type`, `props` and `opts` that are passed into the `Resource` constructor for any resource descended from the resource that has the transformation applied. The transformation callback can optionally return alternate versions of the `props` and `opts` to be used in place of the original values provided to the resource constructor.
Fixes #2068.
2019-09-29 18:27:37 +00:00
|
|
|
"simple",
|
|
|
|
}
|
|
|
|
|
2023-12-16 14:06:27 +00:00
|
|
|
func Validator(t *testing.T, stack integration.RuntimeValidationStackInfo) {
|
|
|
|
randomResName := "testprovider:index:Random"
|
|
|
|
foundRes1 := false
|
|
|
|
foundRes2Child := false
|
|
|
|
foundRes3 := false
|
|
|
|
foundRes4Child := false
|
|
|
|
foundRes5Child := false
|
|
|
|
for _, res := range stack.Deployment.Resources {
|
|
|
|
// "res1" has a transformation which adds additionalSecretOutputs
|
|
|
|
if res.URN.Name() == "res1" {
|
|
|
|
foundRes1 = true
|
|
|
|
assert.Equal(t, res.Type, tokens.Type(randomResName))
|
|
|
|
assert.Contains(t, res.AdditionalSecretOutputs, resource.PropertyKey("result"))
|
|
|
|
}
|
|
|
|
// "res2" has a transformation which adds additionalSecretOutputs to it's
|
|
|
|
// "child"
|
|
|
|
if res.URN.Name() == "res2-child" {
|
|
|
|
foundRes2Child = true
|
|
|
|
assert.Equal(t, res.Type, tokens.Type(randomResName))
|
|
|
|
assert.Equal(t, res.Parent.Type(), tokens.Type("my:component:MyComponent"))
|
|
|
|
assert.Contains(t, res.AdditionalSecretOutputs, resource.PropertyKey("result"))
|
|
|
|
assert.Contains(t, res.AdditionalSecretOutputs, resource.PropertyKey("length"))
|
|
|
|
}
|
|
|
|
// "res3" is impacted by a global stack transformation which sets
|
|
|
|
// optionalDefault to "stackDefault"
|
|
|
|
if res.URN.Name() == "res3" {
|
|
|
|
foundRes3 = true
|
|
|
|
assert.Equal(t, res.Type, tokens.Type(randomResName))
|
|
|
|
optionalPrefix := res.Inputs["prefix"]
|
|
|
|
assert.NotNil(t, optionalPrefix)
|
|
|
|
assert.Equal(t, "stackDefault", optionalPrefix.(string))
|
|
|
|
}
|
|
|
|
// "res4" is impacted by two component parent transformations which set
|
|
|
|
// optionalDefault to "default1" and then "default2" and also a global stack
|
|
|
|
// transformation which sets optionalDefault to "stackDefault". The end
|
|
|
|
// result should be "stackDefault".
|
|
|
|
if res.URN.Name() == "res4-child" {
|
|
|
|
foundRes4Child = true
|
|
|
|
assert.Equal(t, res.Type, tokens.Type(randomResName))
|
|
|
|
assert.Equal(t, res.Parent.Type(), tokens.Type("my:component:MyComponent"))
|
|
|
|
optionalPrefix := res.Inputs["prefix"]
|
|
|
|
assert.NotNil(t, optionalPrefix)
|
|
|
|
assert.Equal(t, "stackDefault", optionalPrefix.(string))
|
|
|
|
}
|
|
|
|
// "res5" modifies one of its children to depend on another of its children.
|
|
|
|
if res.URN.Name() == "res5-child1" {
|
|
|
|
foundRes5Child = true
|
|
|
|
assert.Equal(t, res.Type, tokens.Type(randomResName))
|
|
|
|
assert.Equal(t, res.Parent.Type(), tokens.Type("my:component:MyOtherComponent"))
|
|
|
|
// TODO[pulumi/pulumi#3282] Due to this bug, the dependency information
|
|
|
|
// will not be correctly recorded in the state file, and so cannot be
|
|
|
|
// verified here.
|
|
|
|
//
|
|
|
|
// assert.Len(t, res.PropertyDependencies, 1)
|
|
|
|
input := res.Inputs["length"]
|
|
|
|
assert.NotNil(t, input)
|
|
|
|
assert.Equal(t, 5.0, input.(float64))
|
2019-10-15 00:35:00 +00:00
|
|
|
}
|
|
|
|
}
|
2023-12-16 14:06:27 +00:00
|
|
|
assert.True(t, foundRes1)
|
|
|
|
assert.True(t, foundRes2Child)
|
|
|
|
assert.True(t, foundRes3)
|
|
|
|
assert.True(t, foundRes4Child)
|
|
|
|
assert.True(t, foundRes5Child)
|
2019-10-15 00:35:00 +00:00
|
|
|
}
|