From 6f526ba0febe60ef834dea9b498f80dcc595cc87 Mon Sep 17 00:00:00 2001 From: Cory Hall <43035978+corymhall@users.noreply.github.com> Date: Mon, 18 Nov 2024 09:41:00 -0500 Subject: [PATCH] Add configuration for controlling the autonaming behavior (#1831) This PR adds some new functionality to control the auto naming behavior. The new behavior lives behind a provider config variable and must be explicitly enabled by the user. The existing behavior will remain the default behavior of the provider. **What's new** - `autoTrim`: When this is set to true the provider will automatically trim the generated name to fit within the `maxLength` requirement. - `randomSuffixMinLength`: Set this to control the minimum length of the random suffix that is generated. This is especially useful in combination with `autoTrim` to ensure that you still end up with unique names (e.g. a random suffix of 1 character is not very unique) closes https://github.com/pulumi/pulumi-aws-native/issues/1816, re https://github.com/pulumi/pulumi-cdk/issues/62 --- examples/autonaming-overlay/index.ts | 7 +- examples/examples_nodejs_test.go | 21 ++ .../pulumi-resource-aws-native/schema.json | 62 ++++++ provider/pkg/autonaming/application.go | 60 +++++- provider/pkg/autonaming/application_test.go | 142 ++++++++++++- provider/pkg/provider/provider.go | 11 +- provider/pkg/provider/provider_test.go | 83 ++++++++ provider/pkg/resources/extension_resource.go | 2 +- provider/pkg/schema/config.go | 20 ++ provider/pkg/schema/gen.go | 12 ++ sdk/dotnet/Config/Config.cs | 22 +++ sdk/dotnet/Inputs/ProviderAutoNamingArgs.cs | 36 ++++ sdk/dotnet/Provider.cs | 6 + sdk/go/aws/config/config.go | 5 + sdk/go/aws/config/pulumiTypes.go | 21 ++ sdk/go/aws/provider.go | 7 + sdk/go/aws/pulumiTypes.go | 187 ++++++++++++++++++ sdk/nodejs/config/vars.ts | 11 ++ sdk/nodejs/provider.ts | 5 + sdk/nodejs/types/input.ts | 25 +++ sdk/nodejs/types/output.ts | 25 +++ sdk/python/pulumi_aws_native/_inputs.py | 60 ++++++ .../pulumi_aws_native/config/__init__.pyi | 5 + .../pulumi_aws_native/config/outputs.py | 38 ++++ sdk/python/pulumi_aws_native/config/vars.py | 7 + sdk/python/pulumi_aws_native/provider.py | 20 ++ 26 files changed, 888 insertions(+), 12 deletions(-) create mode 100644 sdk/dotnet/Inputs/ProviderAutoNamingArgs.cs diff --git a/examples/autonaming-overlay/index.ts b/examples/autonaming-overlay/index.ts index de7de5b922..94ba248efd 100644 --- a/examples/autonaming-overlay/index.ts +++ b/examples/autonaming-overlay/index.ts @@ -1,6 +1,9 @@ +import * as pulumi from '@pulumi/pulumi'; import * as aws from "@pulumi/aws-native"; -new aws.iam.Role("myRole".repeat(11), { +const config = new pulumi.Config(); +const name = config.require('roleName'); +const role = new aws.iam.Role(name, { assumeRolePolicyDocument: { Version: "2012-10-17", Statement: [ @@ -14,3 +17,5 @@ new aws.iam.Role("myRole".repeat(11), { ], }, }); + +export const roleName = role.roleName; diff --git a/examples/examples_nodejs_test.go b/examples/examples_nodejs_test.go index 079b9e1292..199e152853 100644 --- a/examples/examples_nodejs_test.go +++ b/examples/examples_nodejs_test.go @@ -148,6 +148,9 @@ func TestAutoNamingOverlay(t *testing.T) { With(integration.ProgramTestOptions{ Dir: filepath.Join(getCwd(t), "autonaming-overlay"), Stderr: &buf, + Config: map[string]string{ + "roleName": "myReallyLongRoleNameThatIsLongerThan64CharactersOneTwoThreeFour", + }, ExpectFailure: true, ExtraRuntimeValidation: func(t *testing.T, stackInfo integration.RuntimeValidationStackInfo) { assert.Contains(t, buf.String(), "is too large to fix max length constraint of 64") @@ -157,6 +160,24 @@ func TestAutoNamingOverlay(t *testing.T) { integration.ProgramTest(t, &test) } +func TestAutoNamingOverlayWithConfig(t *testing.T) { + test := getJSBaseOptions(t). + With(integration.ProgramTestOptions{ + Dir: filepath.Join(getCwd(t), "autonaming-overlay"), + Config: map[string]string{ + "aws-native:autoNaming": `{"autoTrim": true, "randomSuffixMinLength": 7}`, + "roleName": "myReallyLongRoleNameThatIsLongerThan64CharactersOneTwoThreeFour", + }, + ExtraRuntimeValidation: func(t *testing.T, stackInfo integration.RuntimeValidationStackInfo) { + roleName := stackInfo.Outputs["roleName"].(string) + assert.Equal(t, 64, len(roleName)) + assert.Regexp(t, "myReallyLongRoleNameThatIsLon64CharactersOneTwoThreeFour-[a-z0-9]{7}", roleName) + }, + }) + + integration.ProgramTest(t, &test) +} + func TestParallelTs(t *testing.T) { test := getJSBaseOptions(t). With(integration.ProgramTestOptions{ diff --git a/provider/cmd/pulumi-resource-aws-native/schema.json b/provider/cmd/pulumi-resource-aws-native/schema.json index fd89175adf..79b465ec61 100644 --- a/provider/cmd/pulumi-resource-aws-native/schema.json +++ b/provider/cmd/pulumi-resource-aws-native/schema.json @@ -282,6 +282,10 @@ "$ref": "#/types/aws-native:config:AssumeRole", "description": "Configuration for retrieving temporary credentials from the STS service." }, + "autoNaming": { + "$ref": "#/types/aws-native:config:AutoNaming", + "description": "The configuration for automatically naming resources." + }, "defaultTags": { "$ref": "#/types/aws-native:config:DefaultTags", "description": "Configuration block with resource tag settings to apply across all resources handled by this provider. This is designed to replace redundant per-resource `tags` configurations. Provider tags can be overridden with new values, but not excluded from specific resources. To override provider tag values, use the `tags` argument within a resource to configure new tag values for matching keys." @@ -28740,6 +28744,31 @@ }, "type": "object" }, + "aws-native:config:AutoNaming": { + "description": "The configuration for automatically naming resources.", + "properties": { + "autoTrim": { + "type": "boolean", + "description": "Automatically trim the auto-generated name to meet the maximum length constraint.", + "language": { + "python": { + "mapCase": false + } + } + }, + "randomSuffixMinLength": { + "type": "integer", + "description": "The minimum length of the random suffix to append to the auto-generated name.", + "default": 1, + "language": { + "python": { + "mapCase": false + } + } + } + }, + "type": "object" + }, "aws-native:config:DefaultTags": { "description": "The configuration with resource tag settings to apply across all resources handled by this provider. This is designed to replace redundant per-resource `tags` configurations. Provider tags can be overridden with new values, but not excluded from specific resources. To override provider tag values, use the `tags` argument within a resource to configure new tag values for matching keys.", "properties": { @@ -62272,6 +62301,31 @@ }, "type": "object" }, + "aws-native:index:ProviderAutoNaming": { + "description": "The configuration for automatically naming resources.", + "properties": { + "autoTrim": { + "type": "boolean", + "description": "Automatically trim the auto-generated name to meet the maximum length constraint.", + "language": { + "python": { + "mapCase": false + } + } + }, + "randomSuffixMinLength": { + "type": "integer", + "description": "The minimum length of the random suffix to append to the auto-generated name.", + "default": 1, + "language": { + "python": { + "mapCase": false + } + } + } + }, + "type": "object" + }, "aws-native:index:ProviderDefaultTags": { "description": "The configuration with resource tag settings to apply across all resources handled by this provider. This is designed to replace redundant per-resource `tags` configurations. Provider tags can be overridden with new values, but not excluded from specific resources. To override provider tag values, use the `tags` argument within a resource to configure new tag values for matching keys.", "properties": { @@ -169588,6 +169642,10 @@ "$ref": "#/types/aws-native:index:ProviderAssumeRole", "description": "Configuration for retrieving temporary credentials from the STS service." }, + "autoNaming": { + "$ref": "#/types/aws-native:index:ProviderAutoNaming", + "description": "The configuration for automatically naming resources." + }, "defaultTags": { "$ref": "#/types/aws-native:index:ProviderDefaultTags", "description": "Configuration block with resource tag settings to apply across all resources handled by this provider. This is designed to replace redundant per-resource `tags` configurations. Provider tags can be overridden with new values, but not excluded from specific resources. To override provider tag values, use the `tags` argument within a resource to configure new tag values for matching keys." @@ -169677,6 +169735,10 @@ "$ref": "#/types/aws-native:index:ProviderAssumeRole", "description": "Configuration for retrieving temporary credentials from the STS service." }, + "autoNaming": { + "$ref": "#/types/aws-native:index:ProviderAutoNaming", + "description": "The configuration for automatically naming resources." + }, "defaultTags": { "$ref": "#/types/aws-native:index:ProviderDefaultTags", "description": "Configuration block with resource tag settings to apply across all resources handled by this provider. This is designed to replace redundant per-resource `tags` configurations. Provider tags can be overridden with new values, but not excluded from specific resources. To override provider tag values, use the `tags` argument within a resource to configure new tag values for matching keys." diff --git a/provider/pkg/autonaming/application.go b/provider/pkg/autonaming/application.go index 36563b0692..498d09091f 100644 --- a/provider/pkg/autonaming/application.go +++ b/provider/pkg/autonaming/application.go @@ -4,23 +4,30 @@ package autonaming import ( "fmt" + "math" "github.com/pulumi/pulumi-aws-native/provider/pkg/metadata" "github.com/pulumi/pulumi/sdk/v3/go/common/resource" ) +type AutoNamingConfig struct { + AutoTrim bool `json:"autoTrim"` + RandomSuffixMinLength int `json:"randomSuffixMinLength"` +} + func ApplyAutoNaming( spec *metadata.AutoNamingSpec, urn resource.URN, randomSeed []byte, olds, news resource.PropertyMap, + config *AutoNamingConfig, ) error { if spec == nil { return nil } // Auto-name fields if not already specified - val, err := getDefaultName(randomSeed, urn, spec, olds, news) + val, err := getDefaultName(randomSeed, urn, spec, olds, news, config) if err != nil { return err } @@ -39,6 +46,7 @@ func getDefaultName( autoNamingSpec *metadata.AutoNamingSpec, olds, news resource.PropertyMap, + config *AutoNamingConfig, ) (resource.PropertyValue, error) { sdkName := autoNamingSpec.SdkName @@ -58,10 +66,23 @@ func getDefaultName( return resource.PropertyValue{}, err } + var autoTrim bool + // resource.NewUniqueName does not allow for a random suffix shorter than 1. + randomSuffixMinLength := 1 + if config != nil { + autoTrim = config.AutoTrim + if config.RandomSuffixMinLength != 0 { + randomSuffixMinLength = config.RandomSuffixMinLength + } + } + // Generate random name that fits the length constraints. name := urn.Name() prefix := name + "-" - randLength := 7 + randLength := 7 // Default value + if randomSuffixMinLength > randLength { + randLength = randomSuffixMinLength + } if len(prefix)+namingTrivia.Length()+randLength < autoNamingSpec.MinLength { randLength = autoNamingSpec.MinLength - len(prefix) - namingTrivia.Length() } @@ -70,6 +91,19 @@ func getDefaultName( if autoNamingSpec.MaxLength > 0 { left := autoNamingSpec.MaxLength - len(prefix) - namingTrivia.Length() + if left <= 0 && autoTrim { + autoTrimMaxLength := autoNamingSpec.MaxLength - namingTrivia.Length() - randomSuffixMinLength + if autoTrimMaxLength <= 0 { + return resource.PropertyValue{}, fmt.Errorf("failed to auto-generate value for %[1]q."+ + " Prefix: %[2]q is too large to fix max length constraint of %[3]d"+ + " with required suffix length %[4]d. Please provide a value for %[1]q", + sdkName, prefix, autoNamingSpec.MaxLength, randomSuffixMinLength) + } + prefix = trimName(prefix, autoTrimMaxLength) + randLength = randomSuffixMinLength + left = randomSuffixMinLength + } + if left <= 0 { if namingTrivia.Length() > 0 { return resource.PropertyValue{}, fmt.Errorf("failed to auto-generate value for %[1]q."+ @@ -101,3 +135,25 @@ func getDefaultName( return resource.NewStringProperty(random), nil } + +// trimName will trim the prefix to fit within the max length constraint. +// It will cut out part of the middle, keeping the beginning and the end of the string. +// This is so that really long generated names can still be unique. For example, if the +// user creates a resource name by appending the parent onto the child, you could end up +// with names like: +// - "topParent-middleParent-bottonParent-child1" +// - "topParent-middleParent-bottonParent-child2" +// +// If the max length is 30, the trimmed generated name for both would be something like +// "topParent-middleParent-bottonP" and you would not be able to tell them apart. +// +// By trimming from the middle you would end up with something like this, preserving +// the uniqueness of the generated names: +// - "topParent-middlonParent-child1" +// - "topParent-middlonParent-child2" +func trimName(name string, maxLength int) string { + floorHalf := math.Floor(float64(maxLength) / 2) + half := int(floorHalf) + left := maxLength - half + return name[0:half] + name[len(name)-left:] +} diff --git a/provider/pkg/autonaming/application_test.go b/provider/pkg/autonaming/application_test.go index fb4be3adc4..05e38ea55c 100644 --- a/provider/pkg/autonaming/application_test.go +++ b/provider/pkg/autonaming/application_test.go @@ -8,6 +8,7 @@ import ( "github.com/pulumi/pulumi-aws-native/provider/pkg/metadata" "github.com/pulumi/pulumi/sdk/v3/go/common/resource" + "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) @@ -20,7 +21,7 @@ func Test_getDefaultName(t *testing.T) { olds resource.PropertyMap news resource.PropertyMap err error - comparison func(actual resource.PropertyValue) bool + comparison func(t *testing.T, actual resource.PropertyValue) bool }{ { name: "Name specified explicitly", @@ -73,14 +74,14 @@ func Test_getDefaultName(t *testing.T) { MinLength: tt.minLength, MaxLength: tt.maxLength, } - got, err := getDefaultName(nil, urn, autoNamingSpec, tt.olds, tt.news) + got, err := getDefaultName(nil, urn, autoNamingSpec, tt.olds, tt.news, nil) if tt.err != nil { require.EqualError(t, err, tt.err.Error()) return } else { require.NoError(t, err) } - if !tt.comparison(got) { + if !tt.comparison(t, got) { t.Errorf("getDefaultName() = %v for spec: %+v", got, autoNamingSpec) } t.Logf("getDefaultName() = %v for spec: %+v", got, autoNamingSpec) @@ -88,15 +89,142 @@ func Test_getDefaultName(t *testing.T) { } } -func equals(expected resource.PropertyValue) func(resource.PropertyValue) bool { - return func(actual resource.PropertyValue) bool { +func Test_getDefaultName_withAutoNameConfig(t *testing.T) { + const sdkName = "autoName" + tests := []struct { + name string + resourceName string + autoNameConfig AutoNamingConfig + minLength int + maxLength int + olds resource.PropertyMap + news resource.PropertyMap + err error + comparison func(t *testing.T, actual resource.PropertyValue) bool + }{ + { + name: "Name specified explicitly", + resourceName: "myName", + news: resource.PropertyMap{ + resource.PropertyKey(sdkName): resource.NewStringProperty("newName"), + }, + autoNameConfig: AutoNamingConfig{ + AutoTrim: true, + RandomSuffixMinLength: 1, + }, + maxLength: 2, + comparison: equals(resource.NewStringProperty("newName")), + }, + { + name: "Use old name", + resourceName: "myName", + olds: resource.PropertyMap{ + resource.PropertyKey(sdkName): resource.NewStringProperty("oldName"), + }, + autoNameConfig: AutoNamingConfig{ + AutoTrim: true, + RandomSuffixMinLength: 1, + }, + maxLength: 2, + comparison: equals(resource.NewStringProperty("oldName")), + }, + { + resourceName: "myReallyLongName", + name: "Autoname with constraints on max length", + maxLength: 12, + autoNameConfig: AutoNamingConfig{ + AutoTrim: true, + }, + comparison: startsWith("myReagName", 1), + }, + { + resourceName: "myReallyLongName", + name: "Autoname with odd constraints on max length", + maxLength: 13, + autoNameConfig: AutoNamingConfig{ + AutoTrim: true, + }, + comparison: startsWith("myRealgName", 1), + }, + { + name: "Autoname with max length too small and no auto trim", + resourceName: "myName", + maxLength: 4, + autoNameConfig: AutoNamingConfig{ + RandomSuffixMinLength: 2, + }, + comparison: within(15, 15), + err: fmt.Errorf("failed to auto-generate value for %[1]q. Prefix: \"myName-\" is too large to fix max length constraint of 4. Please provide a value for %[1]q", sdkName), + }, + { + name: "Autoname with constraints on min and max length", + minLength: 13, + resourceName: "myReallyLongName", + autoNameConfig: AutoNamingConfig{ + RandomSuffixMinLength: 2, + AutoTrim: true, + }, + maxLength: 13, + comparison: startsWith("myReagName", 2), + }, + { + name: "Autoname with long random suffix", + resourceName: "myReallyLongName", + autoNameConfig: AutoNamingConfig{ + RandomSuffixMinLength: 14, + AutoTrim: true, + }, + maxLength: 13, + comparison: within(13, 13), + err: fmt.Errorf("failed to auto-generate value for %[1]q. Prefix: \"myReallyLongName-\" is too large to fix max length constraint of 13 with required suffix length 14. Please provide a value for %[1]q", sdkName), + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + urn := resource.URN(fmt.Sprintf("urn:pulumi:dev::test::test-provider:testModule:TestResource::%s", tt.resourceName)) + autoNamingSpec := &metadata.AutoNamingSpec{ + SdkName: "autoName", + MinLength: tt.minLength, + MaxLength: tt.maxLength, + } + + autoNameConfig := tt.autoNameConfig + got, err := getDefaultName(nil, urn, autoNamingSpec, tt.olds, tt.news, &autoNameConfig) + if tt.err != nil { + require.EqualError(t, err, tt.err.Error()) + return + } else { + require.NoError(t, err) + } + if !tt.comparison(t, got) { + t.Errorf("getDefaultName() = %v for spec: %+v", got, autoNamingSpec) + } + t.Logf("getDefaultName() = %v for spec: %+v", got, autoNamingSpec) + }) + } +} + +func equals(expected resource.PropertyValue) func(t *testing.T, actual resource.PropertyValue) bool { + return func(t *testing.T, actual resource.PropertyValue) bool { return expected == actual } } -func within(min, max int) func(value resource.PropertyValue) bool { - return func(actual resource.PropertyValue) bool { +func startsWith(prefix string, randomLen int) func(t *testing.T, actual resource.PropertyValue) bool { + return func(t *testing.T, actual resource.PropertyValue) bool { + return assert.Regexp(t, fmt.Sprintf("^%s-[a-z0-9]{%d}", prefix, randomLen), actual.StringValue()) + } +} + +func within(min, max int) func(t *testing.T, value resource.PropertyValue) bool { + return func(t *testing.T, actual resource.PropertyValue) bool { l := len(actual.V.(string)) return min <= l && l <= max } } + +func Test_trimName(t *testing.T) { + assert.Equal(t, "mysupgname", trimName("mysuperlongname", 10)) + assert.Equal(t, "mysupernam", trimName("mysupernam", 10)) +} diff --git a/provider/pkg/provider/provider.go b/provider/pkg/provider/provider.go index c058c243f7..5f78c8db75 100644 --- a/provider/pkg/provider/provider.go +++ b/provider/pkg/provider/provider.go @@ -107,6 +107,7 @@ type cfnProvider struct { partition partition resourceMap *metadata.CloudAPIMetadata roleArn *string + autoNamingConfig *autonaming.AutoNamingConfig allowedAccountIds []string forbiddenAccountIds []string defaultTags map[string]string @@ -519,6 +520,14 @@ func (p *cfnProvider) Configure(ctx context.Context, req *pulumirpc.ConfigureReq metadata.CfnCustomResourceToken: resources.NewCfnCustomResource(p.name, s3Client, lambdaClient), } + if autoNaming, ok := vars["aws-native:config:autoNaming"]; ok { + var autoNamingConfig autonaming.AutoNamingConfig + if err := json.Unmarshal([]byte(autoNaming), &autoNamingConfig); err != nil { + return nil, fmt.Errorf("failed to unmarshal 'autoNaming' config: %w", err) + } + p.autoNamingConfig = &autoNamingConfig + } + p.configured = true return &pulumirpc.ConfigureResponse{ @@ -743,7 +752,7 @@ func (p *cfnProvider) Check(ctx context.Context, req *pulumirpc.CheckRequest) (* return nil, errors.Errorf("resource type %s not found", resourceToken) } - if err := autonaming.ApplyAutoNaming(spec.AutoNamingSpec, urn, req.RandomSeed, olds, newInputs); err != nil { + if err := autonaming.ApplyAutoNaming(spec.AutoNamingSpec, urn, req.RandomSeed, olds, newInputs, p.autoNamingConfig); err != nil { return nil, fmt.Errorf("failed to apply auto-naming: %w", err) } diff --git a/provider/pkg/provider/provider_test.go b/provider/pkg/provider/provider_test.go index 0f54cd4c05..020f1c3472 100644 --- a/provider/pkg/provider/provider_test.go +++ b/provider/pkg/provider/provider_test.go @@ -5,6 +5,7 @@ import ( "testing" "time" + "github.com/pulumi/pulumi-aws-native/provider/pkg/autonaming" "github.com/pulumi/pulumi-aws-native/provider/pkg/client" "github.com/pulumi/pulumi-aws-native/provider/pkg/metadata" "github.com/pulumi/pulumi-aws-native/provider/pkg/resources" @@ -19,6 +20,88 @@ import ( "google.golang.org/protobuf/types/known/structpb" ) +func TestConfigure(t *testing.T) { + ctrl := gomock.NewController(t) + defer ctrl.Finish() + + mockCCC := client.NewMockCloudControlClient(ctrl) + mockCustomResource := resources.NewMockCustomResource(ctrl) + + ctx, cancel := context.WithCancel(context.Background()) + provider := &cfnProvider{ + name: "test-provider", + resourceMap: &metadata.CloudAPIMetadata{Resources: map[string]metadata.CloudAPIResource{}}, + customResources: map[string]resources.CustomResource{"custom:resource": mockCustomResource}, + ccc: mockCCC, + canceler: &cancellationContext{ + context: ctx, + cancel: cancel, + }, + } + + t.Run("No AutoNaming Config", func(t *testing.T) { + req := &pulumirpc.ConfigureRequest{ + Variables: map[string]string{ + "aws-native:config:skipCredentialsValidation": "true", + "aws-native:config:region": "us-west-2", + }, + } + + _, err := provider.Configure(ctx, req) + assert.NoError(t, err) + + assert.Nil(t, provider.autoNamingConfig) + }) + + t.Run("AutoNaming config", func(t *testing.T) { + req := &pulumirpc.ConfigureRequest{ + Variables: map[string]string{ + "aws-native:config:skipCredentialsValidation": "true", + "aws-native:config:autoNaming": "{\"autoTrim\": true, \"randomSuffixMinLength\": 5}", + "aws-native:config:region": "us-west-2", + }, + } + + _, err := provider.Configure(ctx, req) + assert.NoError(t, err) + + assert.NotNil(t, provider.autoNamingConfig) + assert.Equal(t, autonaming.AutoNamingConfig{ + AutoTrim: true, + RandomSuffixMinLength: 5, + }, *provider.autoNamingConfig) + }) + + t.Run("AutoNaming empty", func(t *testing.T) { + req := &pulumirpc.ConfigureRequest{ + Variables: map[string]string{ + "aws-native:config:skipCredentialsValidation": "true", + "aws-native:config:autoNaming": "{}", + "aws-native:config:region": "us-west-2", + }, + } + + _, err := provider.Configure(ctx, req) + assert.NoError(t, err) + + assert.NotNil(t, provider.autoNamingConfig) + assert.Equal(t, autonaming.AutoNamingConfig{}, *provider.autoNamingConfig) + }) + + t.Run("AutoNaming config invalid", func(t *testing.T) { + req := &pulumirpc.ConfigureRequest{ + Variables: map[string]string{ + "aws-native:config:skipCredentialsValidation": "true", + "aws-native:config:autoNaming": "autoTrim: true", + "aws-native:config:region": "us-west-2", + }, + } + + _, err := provider.Configure(ctx, req) + assert.ErrorContains(t, err, "failed to unmarshal 'autoNaming' config") + }) +} + func TestCreate(t *testing.T) { ctrl := gomock.NewController(t) defer ctrl.Finish() diff --git a/provider/pkg/resources/extension_resource.go b/provider/pkg/resources/extension_resource.go index bcaf7d5dd0..c3ce163cce 100644 --- a/provider/pkg/resources/extension_resource.go +++ b/provider/pkg/resources/extension_resource.go @@ -64,7 +64,7 @@ func (r *extensionResource) Check(ctx context.Context, urn resource.URN, randomS SdkName: typedInputs.AutoNaming.PropertyName, MinLength: typedInputs.AutoNaming.MinLength, MaxLength: typedInputs.AutoNaming.MaxLength, - }, urn, randomSeed, state, inputs); err != nil { + }, urn, randomSeed, state, inputs, nil); err != nil { return nil, nil, fmt.Errorf("failed to apply auto-naming: %w", err) } } diff --git a/provider/pkg/schema/config.go b/provider/pkg/schema/config.go index 6c9ce37910..fab8799576 100644 --- a/provider/pkg/schema/config.go +++ b/provider/pkg/schema/config.go @@ -139,6 +139,24 @@ var ignoreTags = pschema.ComplexTypeSpec{ }, } +var autoName = pschema.ComplexTypeSpec{ + ObjectTypeSpec: pschema.ObjectTypeSpec{ + Description: "The configuration for automatically naming resources.", + Properties: map[string]pschema.PropertySpec{ + "autoTrim": { + Description: "Automatically trim the auto-generated name to meet the maximum length constraint.", + TypeSpec: pschema.TypeSpec{Type: "boolean"}, + }, + "randomSuffixMinLength": { + Description: "The minimum length of the random suffix to append to the auto-generated name.", + Default: 1, + TypeSpec: pschema.TypeSpec{Type: "integer"}, + }, + }, + Type: "object", + }, +} + func generateRegionEnum(regions []RegionInfo) pschema.ComplexTypeSpec { enums := make([]pschema.EnumValueSpec, len(regions)) for i, region := range regions { @@ -178,4 +196,6 @@ var typeOverlays = map[string]pschema.ComplexTypeSpec{ "aws-native:index:ProviderEndpoint": configToProvider(endpoints), "aws-native:config:IgnoreTags": ignoreTags, "aws-native:index:ProviderIgnoreTags": configToProvider(ignoreTags), + "aws-native:config:AutoNaming": autoName, + "aws-native:index:ProviderAutoNaming": configToProvider(autoName), } diff --git a/provider/pkg/schema/gen.go b/provider/pkg/schema/gen.go index 6fddcd3b4c..d19a2792f8 100644 --- a/provider/pkg/schema/gen.go +++ b/provider/pkg/schema/gen.go @@ -177,6 +177,10 @@ func GatherPackage(supportedResourceTypes []string, jsonSchemas []*jsschema.Sche TypeSpec: pschema.TypeSpec{Type: "string"}, Secret: true, }, + "autoNaming": { + Description: "The configuration for automatically naming resources.", + TypeSpec: pschema.TypeSpec{Ref: "#/types/aws-native:config:AutoNaming"}, + }, }, Required: []string{ "region", @@ -261,6 +265,10 @@ func GatherPackage(supportedResourceTypes []string, jsonSchemas []*jsschema.Sche Description: "Skip requesting the account ID. Used for AWS API implementations that do not have IAM/STS API and/or metadata API.", TypeSpec: pschema.TypeSpec{Type: "boolean"}, }, + "autoNaming": { + Description: "The configuration for automatically naming resources.", + TypeSpec: pschema.TypeSpec{Ref: "#/types/aws-native:index:ProviderAutoNaming"}, + }, }, }, InputProperties: map[string]pschema.PropertySpec{ @@ -374,6 +382,10 @@ func GatherPackage(supportedResourceTypes []string, jsonSchemas []*jsschema.Sche Secret: true, TypeSpec: pschema.TypeSpec{Type: "string"}, }, + "autoNaming": { + Description: "The configuration for automatically naming resources.", + TypeSpec: pschema.TypeSpec{Ref: "#/types/aws-native:index:ProviderAutoNaming"}, + }, }, RequiredInputs: []string{ "region", diff --git a/sdk/dotnet/Config/Config.cs b/sdk/dotnet/Config/Config.cs index 0f75df1a00..64a57c81ef 100644 --- a/sdk/dotnet/Config/Config.cs +++ b/sdk/dotnet/Config/Config.cs @@ -62,6 +62,16 @@ public static Pulumi.AwsNative.Config.Types.AssumeRole? AssumeRole set => _assumeRole.Set(value); } + private static readonly __Value _autoNaming = new __Value(() => __config.GetObject("autoNaming")); + /// + /// The configuration for automatically naming resources. + /// + public static Pulumi.AwsNative.Config.Types.AutoNaming? AutoNaming + { + get => _autoNaming.Get(); + set => _autoNaming.Set(value); + } + private static readonly __Value _defaultTags = new __Value(() => __config.GetObject("defaultTags")); /// /// Configuration block with resource tag settings to apply across all resources handled by this provider. This is designed to replace redundant per-resource `tags` configurations. Provider tags can be overridden with new values, but not excluded from specific resources. To override provider tag values, use the `tags` argument within a resource to configure new tag values for matching keys. @@ -281,6 +291,18 @@ public class AssumeRole public ImmutableArray TransitiveTagKeys { get; set; } } + public class AutoNaming + { + /// + /// Automatically trim the auto-generated name to meet the maximum length constraint. + /// + public bool? AutoTrim { get; set; } + /// + /// The minimum length of the random suffix to append to the auto-generated name. + /// + public int? RandomSuffixMinLength { get; set; } + } + public class DefaultTags { /// diff --git a/sdk/dotnet/Inputs/ProviderAutoNamingArgs.cs b/sdk/dotnet/Inputs/ProviderAutoNamingArgs.cs new file mode 100644 index 0000000000..7557c565a2 --- /dev/null +++ b/sdk/dotnet/Inputs/ProviderAutoNamingArgs.cs @@ -0,0 +1,36 @@ +// *** WARNING: this file was generated by pulumi. *** +// *** Do not edit by hand unless you're certain you know what you are doing! *** + +using System; +using System.Collections.Generic; +using System.Collections.Immutable; +using System.Threading.Tasks; +using Pulumi.Serialization; + +namespace Pulumi.AwsNative.Inputs +{ + + /// + /// The configuration for automatically naming resources. + /// + public sealed class ProviderAutoNamingArgs : global::Pulumi.ResourceArgs + { + /// + /// Automatically trim the auto-generated name to meet the maximum length constraint. + /// + [Input("autoTrim")] + public Input? AutoTrim { get; set; } + + /// + /// The minimum length of the random suffix to append to the auto-generated name. + /// + [Input("randomSuffixMinLength")] + public Input? RandomSuffixMinLength { get; set; } + + public ProviderAutoNamingArgs() + { + RandomSuffixMinLength = 1; + } + public static new ProviderAutoNamingArgs Empty => new ProviderAutoNamingArgs(); + } +} diff --git a/sdk/dotnet/Provider.cs b/sdk/dotnet/Provider.cs index 5654d061b1..6002074003 100644 --- a/sdk/dotnet/Provider.cs +++ b/sdk/dotnet/Provider.cs @@ -101,6 +101,12 @@ public InputList AllowedAccountIds [Input("assumeRole", json: true)] public Input? AssumeRole { get; set; } + /// + /// The configuration for automatically naming resources. + /// + [Input("autoNaming", json: true)] + public Input? AutoNaming { get; set; } + /// /// Configuration block with resource tag settings to apply across all resources handled by this provider. This is designed to replace redundant per-resource `tags` configurations. Provider tags can be overridden with new values, but not excluded from specific resources. To override provider tag values, use the `tags` argument within a resource to configure new tag values for matching keys. /// diff --git a/sdk/go/aws/config/config.go b/sdk/go/aws/config/config.go index 5d2a63acc4..0c79249ca5 100644 --- a/sdk/go/aws/config/config.go +++ b/sdk/go/aws/config/config.go @@ -26,6 +26,11 @@ func GetAssumeRole(ctx *pulumi.Context) string { return config.Get(ctx, "aws-native:assumeRole") } +// The configuration for automatically naming resources. +func GetAutoNaming(ctx *pulumi.Context) string { + return config.Get(ctx, "aws-native:autoNaming") +} + // Configuration block with resource tag settings to apply across all resources handled by this provider. This is designed to replace redundant per-resource `tags` configurations. Provider tags can be overridden with new values, but not excluded from specific resources. To override provider tag values, use the `tags` argument within a resource to configure new tag values for matching keys. func GetDefaultTags(ctx *pulumi.Context) string { return config.Get(ctx, "aws-native:defaultTags") diff --git a/sdk/go/aws/config/pulumiTypes.go b/sdk/go/aws/config/pulumiTypes.go index 149fdae0da..c652905dfb 100644 --- a/sdk/go/aws/config/pulumiTypes.go +++ b/sdk/go/aws/config/pulumiTypes.go @@ -29,6 +29,27 @@ type AssumeRole struct { TransitiveTagKeys []string `pulumi:"transitiveTagKeys"` } +// The configuration for automatically naming resources. +type AutoNaming struct { + // Automatically trim the auto-generated name to meet the maximum length constraint. + AutoTrim *bool `pulumi:"autoTrim"` + // The minimum length of the random suffix to append to the auto-generated name. + RandomSuffixMinLength *int `pulumi:"randomSuffixMinLength"` +} + +// Defaults sets the appropriate defaults for AutoNaming +func (val *AutoNaming) Defaults() *AutoNaming { + if val == nil { + return nil + } + tmp := *val + if tmp.RandomSuffixMinLength == nil { + randomSuffixMinLength_ := 1 + tmp.RandomSuffixMinLength = &randomSuffixMinLength_ + } + return &tmp +} + // The configuration with resource tag settings to apply across all resources handled by this provider. This is designed to replace redundant per-resource `tags` configurations. Provider tags can be overridden with new values, but not excluded from specific resources. To override provider tag values, use the `tags` argument within a resource to configure new tag values for matching keys. type DefaultTags struct { // A group of tags to set across all resources. diff --git a/sdk/go/aws/provider.go b/sdk/go/aws/provider.go index 819e8cb978..3fa93e822c 100644 --- a/sdk/go/aws/provider.go +++ b/sdk/go/aws/provider.go @@ -33,6 +33,9 @@ func NewProvider(ctx *pulumi.Context, return nil, errors.New("missing one or more required arguments") } + if args.AutoNaming != nil { + args.AutoNaming = args.AutoNaming.ToProviderAutoNamingPtrOutput().ApplyT(func(v *ProviderAutoNaming) *ProviderAutoNaming { return v.Defaults() }).(ProviderAutoNamingPtrOutput) + } if args.Profile == nil { if d := internal.GetEnvOrDefault(nil, nil, "AWS_PROFILE"); d != nil { args.Profile = pulumi.StringPtr(d.(string)) @@ -85,6 +88,8 @@ type providerArgs struct { AllowedAccountIds []string `pulumi:"allowedAccountIds"` // Configuration for retrieving temporary credentials from the STS service. AssumeRole *ProviderAssumeRole `pulumi:"assumeRole"` + // The configuration for automatically naming resources. + AutoNaming *ProviderAutoNaming `pulumi:"autoNaming"` // Configuration block with resource tag settings to apply across all resources handled by this provider. This is designed to replace redundant per-resource `tags` configurations. Provider tags can be overridden with new values, but not excluded from specific resources. To override provider tag values, use the `tags` argument within a resource to configure new tag values for matching keys. DefaultTags *ProviderDefaultTags `pulumi:"defaultTags"` // Configuration block for customizing service endpoints. @@ -131,6 +136,8 @@ type ProviderArgs struct { AllowedAccountIds pulumi.StringArrayInput // Configuration for retrieving temporary credentials from the STS service. AssumeRole ProviderAssumeRolePtrInput + // The configuration for automatically naming resources. + AutoNaming ProviderAutoNamingPtrInput // Configuration block with resource tag settings to apply across all resources handled by this provider. This is designed to replace redundant per-resource `tags` configurations. Provider tags can be overridden with new values, but not excluded from specific resources. To override provider tag values, use the `tags` argument within a resource to configure new tag values for matching keys. DefaultTags ProviderDefaultTagsPtrInput // Configuration block for customizing service endpoints. diff --git a/sdk/go/aws/pulumiTypes.go b/sdk/go/aws/pulumiTypes.go index a46705b9be..46e5fee1bb 100644 --- a/sdk/go/aws/pulumiTypes.go +++ b/sdk/go/aws/pulumiTypes.go @@ -573,6 +573,189 @@ func (o ProviderAssumeRolePtrOutput) TransitiveTagKeys() pulumi.StringArrayOutpu }).(pulumi.StringArrayOutput) } +// The configuration for automatically naming resources. +type ProviderAutoNaming struct { + // Automatically trim the auto-generated name to meet the maximum length constraint. + AutoTrim *bool `pulumi:"autoTrim"` + // The minimum length of the random suffix to append to the auto-generated name. + RandomSuffixMinLength *int `pulumi:"randomSuffixMinLength"` +} + +// Defaults sets the appropriate defaults for ProviderAutoNaming +func (val *ProviderAutoNaming) Defaults() *ProviderAutoNaming { + if val == nil { + return nil + } + tmp := *val + if tmp.RandomSuffixMinLength == nil { + randomSuffixMinLength_ := 1 + tmp.RandomSuffixMinLength = &randomSuffixMinLength_ + } + return &tmp +} + +// ProviderAutoNamingInput is an input type that accepts ProviderAutoNamingArgs and ProviderAutoNamingOutput values. +// You can construct a concrete instance of `ProviderAutoNamingInput` via: +// +// ProviderAutoNamingArgs{...} +type ProviderAutoNamingInput interface { + pulumi.Input + + ToProviderAutoNamingOutput() ProviderAutoNamingOutput + ToProviderAutoNamingOutputWithContext(context.Context) ProviderAutoNamingOutput +} + +// The configuration for automatically naming resources. +type ProviderAutoNamingArgs struct { + // Automatically trim the auto-generated name to meet the maximum length constraint. + AutoTrim pulumi.BoolPtrInput `pulumi:"autoTrim"` + // The minimum length of the random suffix to append to the auto-generated name. + RandomSuffixMinLength pulumi.IntPtrInput `pulumi:"randomSuffixMinLength"` +} + +// Defaults sets the appropriate defaults for ProviderAutoNamingArgs +func (val *ProviderAutoNamingArgs) Defaults() *ProviderAutoNamingArgs { + if val == nil { + return nil + } + tmp := *val + if tmp.RandomSuffixMinLength == nil { + tmp.RandomSuffixMinLength = pulumi.IntPtr(1) + } + return &tmp +} +func (ProviderAutoNamingArgs) ElementType() reflect.Type { + return reflect.TypeOf((*ProviderAutoNaming)(nil)).Elem() +} + +func (i ProviderAutoNamingArgs) ToProviderAutoNamingOutput() ProviderAutoNamingOutput { + return i.ToProviderAutoNamingOutputWithContext(context.Background()) +} + +func (i ProviderAutoNamingArgs) ToProviderAutoNamingOutputWithContext(ctx context.Context) ProviderAutoNamingOutput { + return pulumi.ToOutputWithContext(ctx, i).(ProviderAutoNamingOutput) +} + +func (i ProviderAutoNamingArgs) ToProviderAutoNamingPtrOutput() ProviderAutoNamingPtrOutput { + return i.ToProviderAutoNamingPtrOutputWithContext(context.Background()) +} + +func (i ProviderAutoNamingArgs) ToProviderAutoNamingPtrOutputWithContext(ctx context.Context) ProviderAutoNamingPtrOutput { + return pulumi.ToOutputWithContext(ctx, i).(ProviderAutoNamingOutput).ToProviderAutoNamingPtrOutputWithContext(ctx) +} + +// ProviderAutoNamingPtrInput is an input type that accepts ProviderAutoNamingArgs, ProviderAutoNamingPtr and ProviderAutoNamingPtrOutput values. +// You can construct a concrete instance of `ProviderAutoNamingPtrInput` via: +// +// ProviderAutoNamingArgs{...} +// +// or: +// +// nil +type ProviderAutoNamingPtrInput interface { + pulumi.Input + + ToProviderAutoNamingPtrOutput() ProviderAutoNamingPtrOutput + ToProviderAutoNamingPtrOutputWithContext(context.Context) ProviderAutoNamingPtrOutput +} + +type providerAutoNamingPtrType ProviderAutoNamingArgs + +func ProviderAutoNamingPtr(v *ProviderAutoNamingArgs) ProviderAutoNamingPtrInput { + return (*providerAutoNamingPtrType)(v) +} + +func (*providerAutoNamingPtrType) ElementType() reflect.Type { + return reflect.TypeOf((**ProviderAutoNaming)(nil)).Elem() +} + +func (i *providerAutoNamingPtrType) ToProviderAutoNamingPtrOutput() ProviderAutoNamingPtrOutput { + return i.ToProviderAutoNamingPtrOutputWithContext(context.Background()) +} + +func (i *providerAutoNamingPtrType) ToProviderAutoNamingPtrOutputWithContext(ctx context.Context) ProviderAutoNamingPtrOutput { + return pulumi.ToOutputWithContext(ctx, i).(ProviderAutoNamingPtrOutput) +} + +// The configuration for automatically naming resources. +type ProviderAutoNamingOutput struct{ *pulumi.OutputState } + +func (ProviderAutoNamingOutput) ElementType() reflect.Type { + return reflect.TypeOf((*ProviderAutoNaming)(nil)).Elem() +} + +func (o ProviderAutoNamingOutput) ToProviderAutoNamingOutput() ProviderAutoNamingOutput { + return o +} + +func (o ProviderAutoNamingOutput) ToProviderAutoNamingOutputWithContext(ctx context.Context) ProviderAutoNamingOutput { + return o +} + +func (o ProviderAutoNamingOutput) ToProviderAutoNamingPtrOutput() ProviderAutoNamingPtrOutput { + return o.ToProviderAutoNamingPtrOutputWithContext(context.Background()) +} + +func (o ProviderAutoNamingOutput) ToProviderAutoNamingPtrOutputWithContext(ctx context.Context) ProviderAutoNamingPtrOutput { + return o.ApplyTWithContext(ctx, func(_ context.Context, v ProviderAutoNaming) *ProviderAutoNaming { + return &v + }).(ProviderAutoNamingPtrOutput) +} + +// Automatically trim the auto-generated name to meet the maximum length constraint. +func (o ProviderAutoNamingOutput) AutoTrim() pulumi.BoolPtrOutput { + return o.ApplyT(func(v ProviderAutoNaming) *bool { return v.AutoTrim }).(pulumi.BoolPtrOutput) +} + +// The minimum length of the random suffix to append to the auto-generated name. +func (o ProviderAutoNamingOutput) RandomSuffixMinLength() pulumi.IntPtrOutput { + return o.ApplyT(func(v ProviderAutoNaming) *int { return v.RandomSuffixMinLength }).(pulumi.IntPtrOutput) +} + +type ProviderAutoNamingPtrOutput struct{ *pulumi.OutputState } + +func (ProviderAutoNamingPtrOutput) ElementType() reflect.Type { + return reflect.TypeOf((**ProviderAutoNaming)(nil)).Elem() +} + +func (o ProviderAutoNamingPtrOutput) ToProviderAutoNamingPtrOutput() ProviderAutoNamingPtrOutput { + return o +} + +func (o ProviderAutoNamingPtrOutput) ToProviderAutoNamingPtrOutputWithContext(ctx context.Context) ProviderAutoNamingPtrOutput { + return o +} + +func (o ProviderAutoNamingPtrOutput) Elem() ProviderAutoNamingOutput { + return o.ApplyT(func(v *ProviderAutoNaming) ProviderAutoNaming { + if v != nil { + return *v + } + var ret ProviderAutoNaming + return ret + }).(ProviderAutoNamingOutput) +} + +// Automatically trim the auto-generated name to meet the maximum length constraint. +func (o ProviderAutoNamingPtrOutput) AutoTrim() pulumi.BoolPtrOutput { + return o.ApplyT(func(v *ProviderAutoNaming) *bool { + if v == nil { + return nil + } + return v.AutoTrim + }).(pulumi.BoolPtrOutput) +} + +// The minimum length of the random suffix to append to the auto-generated name. +func (o ProviderAutoNamingPtrOutput) RandomSuffixMinLength() pulumi.IntPtrOutput { + return o.ApplyT(func(v *ProviderAutoNaming) *int { + if v == nil { + return nil + } + return v.RandomSuffixMinLength + }).(pulumi.IntPtrOutput) +} + // The configuration with resource tag settings to apply across all resources handled by this provider. This is designed to replace redundant per-resource `tags` configurations. Provider tags can be overridden with new values, but not excluded from specific resources. To override provider tag values, use the `tags` argument within a resource to configure new tag values for matching keys. type ProviderDefaultTags struct { // A group of tags to set across all resources. @@ -1124,6 +1307,8 @@ func init() { pulumi.RegisterInputType(reflect.TypeOf((*CreateOnlyTagArrayInput)(nil)).Elem(), CreateOnlyTagArray{}) pulumi.RegisterInputType(reflect.TypeOf((*ProviderAssumeRoleInput)(nil)).Elem(), ProviderAssumeRoleArgs{}) pulumi.RegisterInputType(reflect.TypeOf((*ProviderAssumeRolePtrInput)(nil)).Elem(), ProviderAssumeRoleArgs{}) + pulumi.RegisterInputType(reflect.TypeOf((*ProviderAutoNamingInput)(nil)).Elem(), ProviderAutoNamingArgs{}) + pulumi.RegisterInputType(reflect.TypeOf((*ProviderAutoNamingPtrInput)(nil)).Elem(), ProviderAutoNamingArgs{}) pulumi.RegisterInputType(reflect.TypeOf((*ProviderDefaultTagsInput)(nil)).Elem(), ProviderDefaultTagsArgs{}) pulumi.RegisterInputType(reflect.TypeOf((*ProviderDefaultTagsPtrInput)(nil)).Elem(), ProviderDefaultTagsArgs{}) pulumi.RegisterInputType(reflect.TypeOf((*ProviderEndpointInput)(nil)).Elem(), ProviderEndpointArgs{}) @@ -1138,6 +1323,8 @@ func init() { pulumi.RegisterOutputType(CreateOnlyTagArrayOutput{}) pulumi.RegisterOutputType(ProviderAssumeRoleOutput{}) pulumi.RegisterOutputType(ProviderAssumeRolePtrOutput{}) + pulumi.RegisterOutputType(ProviderAutoNamingOutput{}) + pulumi.RegisterOutputType(ProviderAutoNamingPtrOutput{}) pulumi.RegisterOutputType(ProviderDefaultTagsOutput{}) pulumi.RegisterOutputType(ProviderDefaultTagsPtrOutput{}) pulumi.RegisterOutputType(ProviderEndpointOutput{}) diff --git a/sdk/nodejs/config/vars.ts b/sdk/nodejs/config/vars.ts index 18068e2085..985cb47787 100644 --- a/sdk/nodejs/config/vars.ts +++ b/sdk/nodejs/config/vars.ts @@ -45,6 +45,17 @@ Object.defineProperty(exports, "assumeRole", { enumerable: true, }); +/** + * The configuration for automatically naming resources. + */ +export declare const autoNaming: outputs.config.AutoNaming | undefined; +Object.defineProperty(exports, "autoNaming", { + get() { + return __config.getObject("autoNaming"); + }, + enumerable: true, +}); + /** * Configuration block with resource tag settings to apply across all resources handled by this provider. This is designed to replace redundant per-resource `tags` configurations. Provider tags can be overridden with new values, but not excluded from specific resources. To override provider tag values, use the `tags` argument within a resource to configure new tag values for matching keys. */ diff --git a/sdk/nodejs/provider.ts b/sdk/nodejs/provider.ts index d8b6446850..fd9a605dec 100644 --- a/sdk/nodejs/provider.ts +++ b/sdk/nodejs/provider.ts @@ -61,6 +61,7 @@ export class Provider extends pulumi.ProviderResource { resourceInputs["accessKey"] = args?.accessKey ? pulumi.secret(args.accessKey) : undefined; resourceInputs["allowedAccountIds"] = pulumi.output(args ? args.allowedAccountIds : undefined).apply(JSON.stringify); resourceInputs["assumeRole"] = pulumi.output(args ? args.assumeRole : undefined).apply(JSON.stringify); + resourceInputs["autoNaming"] = pulumi.output(args ? (args.autoNaming ? pulumi.output(args.autoNaming).apply(inputs.providerAutoNamingArgsProvideDefaults) : undefined) : undefined).apply(JSON.stringify); resourceInputs["defaultTags"] = pulumi.output(args ? args.defaultTags : undefined).apply(JSON.stringify); resourceInputs["endpoints"] = pulumi.output(args ? args.endpoints : undefined).apply(JSON.stringify); resourceInputs["forbiddenAccountIds"] = pulumi.output(args ? args.forbiddenAccountIds : undefined).apply(JSON.stringify); @@ -101,6 +102,10 @@ export interface ProviderArgs { * Configuration for retrieving temporary credentials from the STS service. */ assumeRole?: pulumi.Input; + /** + * The configuration for automatically naming resources. + */ + autoNaming?: pulumi.Input; /** * Configuration block with resource tag settings to apply across all resources handled by this provider. This is designed to replace redundant per-resource `tags` configurations. Provider tags can be overridden with new values, but not excluded from specific resources. To override provider tag values, use the `tags` argument within a resource to configure new tag values for matching keys. */ diff --git a/sdk/nodejs/types/input.ts b/sdk/nodejs/types/input.ts index 65bb6bbc8a..9f30088923 100644 --- a/sdk/nodejs/types/input.ts +++ b/sdk/nodejs/types/input.ts @@ -6,6 +6,8 @@ import * as inputs from "../types/input"; import * as outputs from "../types/output"; import * as enums from "../types/enums"; +import * as utilities from "../utilities"; + /** * Auto-naming specification for the resource. */ @@ -76,6 +78,29 @@ export interface ProviderAssumeRoleArgs { transitiveTagKeys?: pulumi.Input[]>; } +/** + * The configuration for automatically naming resources. + */ +export interface ProviderAutoNamingArgs { + /** + * Automatically trim the auto-generated name to meet the maximum length constraint. + */ + autoTrim?: pulumi.Input; + /** + * The minimum length of the random suffix to append to the auto-generated name. + */ + randomSuffixMinLength?: pulumi.Input; +} +/** + * providerAutoNamingArgsProvideDefaults sets the appropriate defaults for ProviderAutoNamingArgs + */ +export function providerAutoNamingArgsProvideDefaults(val: ProviderAutoNamingArgs): ProviderAutoNamingArgs { + return { + ...val, + randomSuffixMinLength: (val.randomSuffixMinLength) ?? 1, + }; +} + /** * The configuration with resource tag settings to apply across all resources handled by this provider. This is designed to replace redundant per-resource `tags` configurations. Provider tags can be overridden with new values, but not excluded from specific resources. To override provider tag values, use the `tags` argument within a resource to configure new tag values for matching keys. */ diff --git a/sdk/nodejs/types/output.ts b/sdk/nodejs/types/output.ts index 4ebcf4a384..9f03815118 100644 --- a/sdk/nodejs/types/output.ts +++ b/sdk/nodejs/types/output.ts @@ -6,6 +6,8 @@ import * as inputs from "../types/input"; import * as outputs from "../types/output"; import * as enums from "../types/enums"; +import * as utilities from "../utilities"; + /** * A set of tags to apply to the resource. */ @@ -16715,6 +16717,29 @@ export namespace config { transitiveTagKeys?: string[]; } + /** + * The configuration for automatically naming resources. + */ + export interface AutoNaming { + /** + * Automatically trim the auto-generated name to meet the maximum length constraint. + */ + autoTrim?: boolean; + /** + * The minimum length of the random suffix to append to the auto-generated name. + */ + randomSuffixMinLength?: number; + } + /** + * autoNamingProvideDefaults sets the appropriate defaults for AutoNaming + */ + export function autoNamingProvideDefaults(val: AutoNaming): AutoNaming { + return { + ...val, + randomSuffixMinLength: (val.randomSuffixMinLength) ?? 1, + }; + } + /** * The configuration with resource tag settings to apply across all resources handled by this provider. This is designed to replace redundant per-resource `tags` configurations. Provider tags can be overridden with new values, but not excluded from specific resources. To override provider tag values, use the `tags` argument within a resource to configure new tag values for matching keys. */ diff --git a/sdk/python/pulumi_aws_native/_inputs.py b/sdk/python/pulumi_aws_native/_inputs.py index e523cf06cd..a4175ddfb8 100644 --- a/sdk/python/pulumi_aws_native/_inputs.py +++ b/sdk/python/pulumi_aws_native/_inputs.py @@ -22,6 +22,8 @@ 'CreateOnlyTagArgsDict', 'ProviderAssumeRoleArgs', 'ProviderAssumeRoleArgsDict', + 'ProviderAutoNamingArgs', + 'ProviderAutoNamingArgsDict', 'ProviderDefaultTagsArgs', 'ProviderDefaultTagsArgsDict', 'ProviderEndpointArgs', @@ -340,6 +342,64 @@ def transitive_tag_keys(self, value: Optional[pulumi.Input[Sequence[pulumi.Input pulumi.set(self, "transitive_tag_keys", value) +if not MYPY: + class ProviderAutoNamingArgsDict(TypedDict): + """ + The configuration for automatically naming resources. + """ + auto_trim: NotRequired[pulumi.Input[bool]] + """ + Automatically trim the auto-generated name to meet the maximum length constraint. + """ + random_suffix_min_length: NotRequired[pulumi.Input[int]] + """ + The minimum length of the random suffix to append to the auto-generated name. + """ +elif False: + ProviderAutoNamingArgsDict: TypeAlias = Mapping[str, Any] + +@pulumi.input_type +class ProviderAutoNamingArgs: + def __init__(__self__, *, + auto_trim: Optional[pulumi.Input[bool]] = None, + random_suffix_min_length: Optional[pulumi.Input[int]] = None): + """ + The configuration for automatically naming resources. + :param pulumi.Input[bool] auto_trim: Automatically trim the auto-generated name to meet the maximum length constraint. + :param pulumi.Input[int] random_suffix_min_length: The minimum length of the random suffix to append to the auto-generated name. + """ + if auto_trim is not None: + pulumi.set(__self__, "auto_trim", auto_trim) + if random_suffix_min_length is None: + random_suffix_min_length = 1 + if random_suffix_min_length is not None: + pulumi.set(__self__, "random_suffix_min_length", random_suffix_min_length) + + @property + @pulumi.getter(name="autoTrim") + def auto_trim(self) -> Optional[pulumi.Input[bool]]: + """ + Automatically trim the auto-generated name to meet the maximum length constraint. + """ + return pulumi.get(self, "auto_trim") + + @auto_trim.setter + def auto_trim(self, value: Optional[pulumi.Input[bool]]): + pulumi.set(self, "auto_trim", value) + + @property + @pulumi.getter(name="randomSuffixMinLength") + def random_suffix_min_length(self) -> Optional[pulumi.Input[int]]: + """ + The minimum length of the random suffix to append to the auto-generated name. + """ + return pulumi.get(self, "random_suffix_min_length") + + @random_suffix_min_length.setter + def random_suffix_min_length(self, value: Optional[pulumi.Input[int]]): + pulumi.set(self, "random_suffix_min_length", value) + + if not MYPY: class ProviderDefaultTagsArgsDict(TypedDict): """ diff --git a/sdk/python/pulumi_aws_native/config/__init__.pyi b/sdk/python/pulumi_aws_native/config/__init__.pyi index 0ed67fd4b9..e49d6217b8 100644 --- a/sdk/python/pulumi_aws_native/config/__init__.pyi +++ b/sdk/python/pulumi_aws_native/config/__init__.pyi @@ -30,6 +30,11 @@ assumeRole: Optional[str] Configuration for retrieving temporary credentials from the STS service. """ +autoNaming: Optional[str] +""" +The configuration for automatically naming resources. +""" + defaultTags: Optional[str] """ Configuration block with resource tag settings to apply across all resources handled by this provider. This is designed to replace redundant per-resource `tags` configurations. Provider tags can be overridden with new values, but not excluded from specific resources. To override provider tag values, use the `tags` argument within a resource to configure new tag values for matching keys. diff --git a/sdk/python/pulumi_aws_native/config/outputs.py b/sdk/python/pulumi_aws_native/config/outputs.py index b5afd4ffe7..7a4e58d20f 100644 --- a/sdk/python/pulumi_aws_native/config/outputs.py +++ b/sdk/python/pulumi_aws_native/config/outputs.py @@ -16,6 +16,7 @@ __all__ = [ 'AssumeRole', + 'AutoNaming', 'DefaultTags', 'Endpoints', 'IgnoreTags', @@ -128,6 +129,43 @@ def transitive_tag_keys(self) -> Optional[Sequence[str]]: return pulumi.get(self, "transitive_tag_keys") +@pulumi.output_type +class AutoNaming(dict): + """ + The configuration for automatically naming resources. + """ + def __init__(__self__, *, + auto_trim: Optional[bool] = None, + random_suffix_min_length: Optional[int] = None): + """ + The configuration for automatically naming resources. + :param bool auto_trim: Automatically trim the auto-generated name to meet the maximum length constraint. + :param int random_suffix_min_length: The minimum length of the random suffix to append to the auto-generated name. + """ + if auto_trim is not None: + pulumi.set(__self__, "auto_trim", auto_trim) + if random_suffix_min_length is None: + random_suffix_min_length = 1 + if random_suffix_min_length is not None: + pulumi.set(__self__, "random_suffix_min_length", random_suffix_min_length) + + @property + @pulumi.getter(name="autoTrim") + def auto_trim(self) -> Optional[bool]: + """ + Automatically trim the auto-generated name to meet the maximum length constraint. + """ + return pulumi.get(self, "auto_trim") + + @property + @pulumi.getter(name="randomSuffixMinLength") + def random_suffix_min_length(self) -> Optional[int]: + """ + The minimum length of the random suffix to append to the auto-generated name. + """ + return pulumi.get(self, "random_suffix_min_length") + + @pulumi.output_type class DefaultTags(dict): """ diff --git a/sdk/python/pulumi_aws_native/config/vars.py b/sdk/python/pulumi_aws_native/config/vars.py index adf8aa5c57..bc513795f6 100644 --- a/sdk/python/pulumi_aws_native/config/vars.py +++ b/sdk/python/pulumi_aws_native/config/vars.py @@ -42,6 +42,13 @@ def assume_role(self) -> Optional[str]: """ return __config__.get('assumeRole') + @property + def auto_naming(self) -> Optional[str]: + """ + The configuration for automatically naming resources. + """ + return __config__.get('autoNaming') + @property def default_tags(self) -> Optional[str]: """ diff --git a/sdk/python/pulumi_aws_native/provider.py b/sdk/python/pulumi_aws_native/provider.py index 0a1e318a4a..94d327772e 100644 --- a/sdk/python/pulumi_aws_native/provider.py +++ b/sdk/python/pulumi_aws_native/provider.py @@ -24,6 +24,7 @@ def __init__(__self__, *, access_key: Optional[pulumi.Input[str]] = None, allowed_account_ids: Optional[pulumi.Input[Sequence[pulumi.Input[str]]]] = None, assume_role: Optional[pulumi.Input['ProviderAssumeRoleArgs']] = None, + auto_naming: Optional[pulumi.Input['ProviderAutoNamingArgs']] = None, default_tags: Optional[pulumi.Input['ProviderDefaultTagsArgs']] = None, endpoints: Optional[pulumi.Input[Sequence[pulumi.Input['ProviderEndpointArgs']]]] = None, forbidden_account_ids: Optional[pulumi.Input[Sequence[pulumi.Input[str]]]] = None, @@ -47,6 +48,7 @@ def __init__(__self__, *, :param pulumi.Input[str] access_key: The access key for API operations. You can retrieve this from the ‘Security & Credentials’ section of the AWS console. :param pulumi.Input[Sequence[pulumi.Input[str]]] allowed_account_ids: List of allowed AWS account IDs to prevent you from mistakenly using an incorrect one. Conflicts with `forbiddenAccountIds`. :param pulumi.Input['ProviderAssumeRoleArgs'] assume_role: Configuration for retrieving temporary credentials from the STS service. + :param pulumi.Input['ProviderAutoNamingArgs'] auto_naming: The configuration for automatically naming resources. :param pulumi.Input['ProviderDefaultTagsArgs'] default_tags: Configuration block with resource tag settings to apply across all resources handled by this provider. This is designed to replace redundant per-resource `tags` configurations. Provider tags can be overridden with new values, but not excluded from specific resources. To override provider tag values, use the `tags` argument within a resource to configure new tag values for matching keys. :param pulumi.Input[Sequence[pulumi.Input['ProviderEndpointArgs']]] endpoints: Configuration block for customizing service endpoints. :param pulumi.Input[Sequence[pulumi.Input[str]]] forbidden_account_ids: List of forbidden AWS account IDs to prevent you from mistakenly using the wrong one (and potentially end up destroying a live environment). Conflicts with `allowedAccountIds`. @@ -74,6 +76,8 @@ def __init__(__self__, *, pulumi.set(__self__, "allowed_account_ids", allowed_account_ids) if assume_role is not None: pulumi.set(__self__, "assume_role", assume_role) + if auto_naming is not None: + pulumi.set(__self__, "auto_naming", auto_naming) if default_tags is not None: pulumi.set(__self__, "default_tags", default_tags) if endpoints is not None: @@ -169,6 +173,18 @@ def assume_role(self) -> Optional[pulumi.Input['ProviderAssumeRoleArgs']]: def assume_role(self, value: Optional[pulumi.Input['ProviderAssumeRoleArgs']]): pulumi.set(self, "assume_role", value) + @property + @pulumi.getter(name="autoNaming") + def auto_naming(self) -> Optional[pulumi.Input['ProviderAutoNamingArgs']]: + """ + The configuration for automatically naming resources. + """ + return pulumi.get(self, "auto_naming") + + @auto_naming.setter + def auto_naming(self, value: Optional[pulumi.Input['ProviderAutoNamingArgs']]): + pulumi.set(self, "auto_naming", value) + @property @pulumi.getter(name="defaultTags") def default_tags(self) -> Optional[pulumi.Input['ProviderDefaultTagsArgs']]: @@ -382,6 +398,7 @@ def __init__(__self__, access_key: Optional[pulumi.Input[str]] = None, allowed_account_ids: Optional[pulumi.Input[Sequence[pulumi.Input[str]]]] = None, assume_role: Optional[pulumi.Input[Union['ProviderAssumeRoleArgs', 'ProviderAssumeRoleArgsDict']]] = None, + auto_naming: Optional[pulumi.Input[Union['ProviderAutoNamingArgs', 'ProviderAutoNamingArgsDict']]] = None, default_tags: Optional[pulumi.Input[Union['ProviderDefaultTagsArgs', 'ProviderDefaultTagsArgsDict']]] = None, endpoints: Optional[pulumi.Input[Sequence[pulumi.Input[Union['ProviderEndpointArgs', 'ProviderEndpointArgsDict']]]]] = None, forbidden_account_ids: Optional[pulumi.Input[Sequence[pulumi.Input[str]]]] = None, @@ -409,6 +426,7 @@ def __init__(__self__, :param pulumi.Input[str] access_key: The access key for API operations. You can retrieve this from the ‘Security & Credentials’ section of the AWS console. :param pulumi.Input[Sequence[pulumi.Input[str]]] allowed_account_ids: List of allowed AWS account IDs to prevent you from mistakenly using an incorrect one. Conflicts with `forbiddenAccountIds`. :param pulumi.Input[Union['ProviderAssumeRoleArgs', 'ProviderAssumeRoleArgsDict']] assume_role: Configuration for retrieving temporary credentials from the STS service. + :param pulumi.Input[Union['ProviderAutoNamingArgs', 'ProviderAutoNamingArgsDict']] auto_naming: The configuration for automatically naming resources. :param pulumi.Input[Union['ProviderDefaultTagsArgs', 'ProviderDefaultTagsArgsDict']] default_tags: Configuration block with resource tag settings to apply across all resources handled by this provider. This is designed to replace redundant per-resource `tags` configurations. Provider tags can be overridden with new values, but not excluded from specific resources. To override provider tag values, use the `tags` argument within a resource to configure new tag values for matching keys. :param pulumi.Input[Sequence[pulumi.Input[Union['ProviderEndpointArgs', 'ProviderEndpointArgsDict']]]] endpoints: Configuration block for customizing service endpoints. :param pulumi.Input[Sequence[pulumi.Input[str]]] forbidden_account_ids: List of forbidden AWS account IDs to prevent you from mistakenly using the wrong one (and potentially end up destroying a live environment). Conflicts with `allowedAccountIds`. @@ -455,6 +473,7 @@ def _internal_init(__self__, access_key: Optional[pulumi.Input[str]] = None, allowed_account_ids: Optional[pulumi.Input[Sequence[pulumi.Input[str]]]] = None, assume_role: Optional[pulumi.Input[Union['ProviderAssumeRoleArgs', 'ProviderAssumeRoleArgsDict']]] = None, + auto_naming: Optional[pulumi.Input[Union['ProviderAutoNamingArgs', 'ProviderAutoNamingArgsDict']]] = None, default_tags: Optional[pulumi.Input[Union['ProviderDefaultTagsArgs', 'ProviderDefaultTagsArgsDict']]] = None, endpoints: Optional[pulumi.Input[Sequence[pulumi.Input[Union['ProviderEndpointArgs', 'ProviderEndpointArgsDict']]]]] = None, forbidden_account_ids: Optional[pulumi.Input[Sequence[pulumi.Input[str]]]] = None, @@ -485,6 +504,7 @@ def _internal_init(__self__, __props__.__dict__["access_key"] = None if access_key is None else pulumi.Output.secret(access_key) __props__.__dict__["allowed_account_ids"] = pulumi.Output.from_input(allowed_account_ids).apply(pulumi.runtime.to_json) if allowed_account_ids is not None else None __props__.__dict__["assume_role"] = pulumi.Output.from_input(assume_role).apply(pulumi.runtime.to_json) if assume_role is not None else None + __props__.__dict__["auto_naming"] = pulumi.Output.from_input(auto_naming).apply(pulumi.runtime.to_json) if auto_naming is not None else None __props__.__dict__["default_tags"] = pulumi.Output.from_input(default_tags).apply(pulumi.runtime.to_json) if default_tags is not None else None __props__.__dict__["endpoints"] = pulumi.Output.from_input(endpoints).apply(pulumi.runtime.to_json) if endpoints is not None else None __props__.__dict__["forbidden_account_ids"] = pulumi.Output.from_input(forbidden_account_ids).apply(pulumi.runtime.to_json) if forbidden_account_ids is not None else None