diff --git a/examples/examples_go_test.go b/examples/examples_go_test.go index c3c5c645d7..e38245b2e3 100644 --- a/examples/examples_go_test.go +++ b/examples/examples_go_test.go @@ -27,14 +27,10 @@ func TestWriteOnlyGo(t *testing.T) { With(integration.ProgramTestOptions{ ExpectRefreshChanges: false, Dir: filepath.Join(getCwd(t), "write-only-go"), - Config: map[string]string{ - "aws-native:defaultTags": `{ - "defaultTag": "defaultTagValue" - }`, - }, ExtraRuntimeValidation: func(t *testing.T, stack integration.RuntimeValidationStackInfo) { // We should see both the default tag and the local tag in the log group tags. - // If the default tag is missing, it's because there was a missing output from the provider and the SDK filled in the value with the original input. + // If the default tag is missing, it's because there was a missing output from the provider + // because write-only properties aren't returned in the read result and the SDK filled in the value with the original input. tags := stack.Outputs["tags"].(map[string]interface{}) assert.Equal(t, map[string]interface{}{ "defaultTag": "defaultTagValue", diff --git a/examples/examples_py_test.go b/examples/examples_py_test.go index c31edf560b..79c0ae9a00 100644 --- a/examples/examples_py_test.go +++ b/examples/examples_py_test.go @@ -27,7 +27,9 @@ func TestDefaultTagsPython(t *testing.T) { Dir: filepath.Join(getCwd(t), "default-tags-py"), Config: map[string]string{ "aws-native:defaultTags": `{ - "defaultTag": "defaultTagValue" + "tags": { + "defaultTag": "defaultTagValue" + } }`, }, ExtraRuntimeValidation: func(t *testing.T, stackInfo integration.RuntimeValidationStackInfo) { diff --git a/examples/write-only-go/go.mod b/examples/write-only-go/go.mod index cd88a9f2d8..760354e687 100644 --- a/examples/write-only-go/go.mod +++ b/examples/write-only-go/go.mod @@ -1,4 +1,4 @@ -module github.com/pulumi/pulumi-aws-native/examples/simple-go +module github.com/pulumi/pulumi-aws-native/examples/write-only-go go 1.21 @@ -64,6 +64,7 @@ require ( github.com/santhosh-tekuri/jsonschema/v5 v5.0.0 // indirect github.com/sergi/go-diff v1.3.1 // indirect github.com/skeema/knownhosts v1.2.1 // indirect + github.com/spf13/cast v1.4.1 // indirect github.com/spf13/cobra v1.7.0 // indirect github.com/spf13/pflag v1.0.5 // indirect github.com/texttheater/golang-levenshtein v1.0.1 // indirect @@ -88,5 +89,4 @@ require ( gopkg.in/warnings.v0 v0.1.2 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect lukechampine.com/frand v1.4.2 // indirect - pgregory.net/rapid v0.6.1 // indirect ) diff --git a/examples/write-only-go/go.sum b/examples/write-only-go/go.sum index 1318db67a4..92ba512d6c 100644 --- a/examples/write-only-go/go.sum +++ b/examples/write-only-go/go.sum @@ -289,6 +289,8 @@ github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasO github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ= github.com/spf13/cast v1.3.0/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE= github.com/spf13/cast v1.3.1/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE= +github.com/spf13/cast v1.4.1 h1:s0hze+J0196ZfEMTs80N7UlFt0BDuQ7Q+JDnHiMWKdA= +github.com/spf13/cast v1.4.1/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE= github.com/spf13/cobra v1.0.0/go.mod h1:/6GTrnGXV9HjY+aR4k0oJ5tcvakLuG6EuKReYlHNrgE= github.com/spf13/cobra v1.7.0 h1:hyqWnYt1ZQShIddO5kBpj3vu05/++x6tJ6dg8EC572I= github.com/spf13/cobra v1.7.0/go.mod h1:uLxZILRyS/50WlhOIKD7W6V5bgeIt+4sICxh6uRMrb0= @@ -530,6 +532,6 @@ honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWh honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= lukechampine.com/frand v1.4.2 h1:RzFIpOvkMXuPMBb9maa4ND4wjBn71E1Jpf8BzJHMaVw= lukechampine.com/frand v1.4.2/go.mod h1:4S/TM2ZgrKejMcKMbeLjISpJMO+/eZ1zu3vYX9dtj3s= -pgregory.net/rapid v0.6.1 h1:4eyrDxyht86tT4Ztm+kvlyNBLIk071gR+ZQdhphc9dQ= -pgregory.net/rapid v0.6.1/go.mod h1:PY5XlDGj0+V1FCq0o192FdRhpKHGTRIWBgqjDBTrq04= +pgregory.net/rapid v0.5.5 h1:jkgx1TjbQPD/feRoK+S/mXw9e1uj6WilpHrXJowi6oA= +pgregory.net/rapid v0.5.5/go.mod h1:PY5XlDGj0+V1FCq0o192FdRhpKHGTRIWBgqjDBTrq04= sourcegraph.com/sourcegraph/appdash v0.0.0-20190731080439-ebfcffb1b5c0/go.mod h1:hI742Nqp5OhwiqlzhgfbWU4mW4yO10fP+LoT9WOswdU= diff --git a/examples/write-only-go/main.go b/examples/write-only-go/main.go index b8519bcbf2..64345d8b8b 100644 --- a/examples/write-only-go/main.go +++ b/examples/write-only-go/main.go @@ -15,19 +15,33 @@ package main import ( + awsNative "github.com/pulumi/pulumi-aws-native/sdk/go/aws" ssm "github.com/pulumi/pulumi-aws-native/sdk/go/aws/ssm" "github.com/pulumi/pulumi/sdk/v3/go/pulumi" + "github.com/pulumi/pulumi/sdk/v3/go/pulumi/config" ) func main() { pulumi.Run(func(ctx *pulumi.Context) error { + awsNativeConfig := config.New(ctx, "aws-native") + awsNativeProvider, err := awsNative.NewProvider(ctx, "aws-native", &awsNative.ProviderArgs{ + Region: pulumi.String(awsNativeConfig.Require("region")), + DefaultTags: awsNative.ProviderDefaultTagsArgs{ + Tags: pulumi.StringMap{ + "defaultTag": pulumi.String("defaultTagValue"), + }, + }, + }) + if err != nil { + return err + } logGroup, err := ssm.NewParameter(ctx, "log-test", &ssm.ParameterArgs{ Type: ssm.ParameterTypeString, Value: pulumi.String("test"), Tags: pulumi.StringMap{ "localTag": pulumi.String("localTagValue"), }, - }) + }, pulumi.Provider(awsNativeProvider)) if err != nil { return err } diff --git a/provider/pkg/provider/provider.go b/provider/pkg/provider/provider.go index 05ae4ad54e..c38cc57c2c 100644 --- a/provider/pkg/provider/provider.go +++ b/provider/pkg/provider/provider.go @@ -461,12 +461,21 @@ func (p *cfnProvider) Configure(ctx context.Context, req *pulumirpc.ConfigureReq } if defaultTagsJson, ok := vars["aws-native:config:defaultTags"]; ok { - var defaultTags map[string]string + type DefaultTags struct { + Tags map[string]string `json:"tags"` + } + var defaultTags DefaultTags err := json.Unmarshal([]byte(defaultTagsJson), &defaultTags) - if err != nil { - return nil, fmt.Errorf("failed to unmarshal 'skipCredentialsValidation' config: %w", err) + if err == nil { + p.defaultTags = defaultTags.Tags + } else { + // As a fallback, we also try to unmarshal the default tags as a simple map[string]string + // as this was originally supported when implementing defaultTags. + fallbackErr := json.Unmarshal([]byte(defaultTagsJson), &p.defaultTags) + if fallbackErr != nil { + return nil, fmt.Errorf("failed to unmarshal 'defaultTags' config: %w", err) + } } - p.defaultTags = defaultTags } else { p.defaultTags = nil }