diff --git a/internal/provider/factory_test.go b/internal/provider/factory_test.go index 20b6b70d7207..9936541c639b 100644 --- a/internal/provider/factory_test.go +++ b/internal/provider/factory_test.go @@ -10,7 +10,7 @@ import ( "github.com/hashicorp/terraform-provider-aws/internal/provider" ) -// go test -bench=BenchmarkProtoV5ProviderServerFactory -benchtime 1x -benchmem -run=B -v ./internal/provider +// go test -bench=BenchmarkProtoV5ProviderServerFactory -benchtime 1x -benchmem -run=Bench -v ./internal/provider func BenchmarkProtoV5ProviderServerFactory(b *testing.B) { _, p, err := provider.ProtoV5ProviderServerFactory(context.Background()) diff --git a/internal/provider/provider_test.go b/internal/provider/provider_test.go index 3cd7575ffd72..afe2bb9e7ccf 100644 --- a/internal/provider/provider_test.go +++ b/internal/provider/provider_test.go @@ -18,6 +18,16 @@ import ( "github.com/hashicorp/terraform-provider-aws/names" ) +// go test -bench=BenchmarkSDKProviderInitialization -benchmem -run=Bench -v ./internal/provider +func BenchmarkSDKProviderInitialization(b *testing.B) { + for n := 0; n < b.N; n++ { + _, err := New(context.Background()) + if err != nil { + b.Fatal(err) + } + } +} + func TestProvider(t *testing.T) { t.Parallel() diff --git a/internal/service/ec2/tags.go b/internal/service/ec2/tags.go index 093d6d1b1332..e6284fe759dd 100644 --- a/internal/service/ec2/tags.go +++ b/internal/service/ec2/tags.go @@ -100,8 +100,8 @@ func tagsFromTagDescriptions(tds []awstypes.TagDescription) []awstypes.Tag { } func tagsSchemaConflictsWith(conflictsWith []string) *schema.Schema { - v := tftags.TagsSchema() + v := *tftags.TagsSchema() // nosemgrep:ci.semgrep.aws.prefer-pointer-conversion-assignment v.ConflictsWith = conflictsWith - return v + return &v } diff --git a/internal/service/wafv2/schemas.go b/internal/service/wafv2/schemas.go index ccff60eff789..8ac8b8d5342c 100644 --- a/internal/service/wafv2/schemas.go +++ b/internal/service/wafv2/schemas.go @@ -5,6 +5,7 @@ package wafv2 import ( "math" + "sync" "github.com/YakDriver/regexache" awstypes "github.com/aws/aws-sdk-go-v2/service/wafv2/types" @@ -15,20 +16,18 @@ import ( "github.com/hashicorp/terraform-provider-aws/names" ) -var listOfEmptyObjectSchema *schema.Schema = &schema.Schema{ - Type: schema.TypeList, - Optional: true, - MaxItems: 1, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{}, - }, -} - -func emptySchema() *schema.Schema { - return listOfEmptyObjectSchema -} +var emptySchema = sync.OnceValue(func() *schema.Schema { + return &schema.Schema{ + Type: schema.TypeList, + Optional: true, + MaxItems: 1, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{}, + }, + } +}) -func ruleLabelsSchema() *schema.Schema { +var ruleLabelsSchema = sync.OnceValue(func() *schema.Schema { return &schema.Schema{ Type: schema.TypeSet, Optional: true, @@ -39,13 +38,16 @@ func ruleLabelsSchema() *schema.Schema { Required: true, ValidateFunc: validation.All( validation.StringLenBetween(1, 1024), - validation.StringMatch(regexache.MustCompile(`^[0-9A-Za-z_\-:]+$`), "must contain only alphanumeric, underscore, hyphen, and colon characters"), + validation.StringMatch( + regexache.MustCompile(`^[0-9A-Za-z_\-:]+$`), + "must contain only alphanumeric, underscore, hyphen, and colon characters", + ), ), }, }, }, } -} +}) func ruleGroupRootStatementSchema(level int) *schema.Schema { return &schema.Schema{ @@ -72,9 +74,22 @@ func ruleGroupRootStatementSchema(level int) *schema.Schema { } } -func statementSchema(level int) *schema.Schema { - if level > 1 { - return &schema.Schema{ +const ( + statementSchemaCacheSize = max( + ruleGroupRootStatementSchemaLevel, + webACLRootStatementSchemaLevel, + ) +) + +type schemaCache struct { + values [statementSchemaCacheSize]schema.Schema + once sync.Once +} + +func (c *schemaCache) get(level int) *schema.Schema { + c.once.Do(func() { + // Initialize the first element + c.values[0] = schema.Schema{ Type: schema.TypeList, Optional: true, MaxItems: 1, @@ -85,13 +100,10 @@ func statementSchema(level int) *schema.Schema { Required: true, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "and_statement": statementSchema(level - 1), "byte_match_statement": byteMatchStatementSchema(), "geo_match_statement": geoMatchStatementSchema(), "ip_set_reference_statement": ipSetReferenceStatementSchema(), "label_match_statement": labelMatchStatementSchema(), - "not_statement": statementSchema(level - 1), - "or_statement": statementSchema(level - 1), "regex_match_statement": regexMatchStatementSchema(), "regex_pattern_set_reference_statement": regexPatternSetReferenceStatementSchema(), "size_constraint_statement": sizeConstraintSchema(), @@ -103,37 +115,53 @@ func statementSchema(level int) *schema.Schema { }, }, } - } - return &schema.Schema{ - Type: schema.TypeList, - Optional: true, - MaxItems: 1, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "statement": { - Type: schema.TypeList, - Required: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "byte_match_statement": byteMatchStatementSchema(), - "geo_match_statement": geoMatchStatementSchema(), - "ip_set_reference_statement": ipSetReferenceStatementSchema(), - "label_match_statement": labelMatchStatementSchema(), - "regex_match_statement": regexMatchStatementSchema(), - "regex_pattern_set_reference_statement": regexPatternSetReferenceStatementSchema(), - "size_constraint_statement": sizeConstraintSchema(), - "sqli_match_statement": sqliMatchStatementSchema(), - "xss_match_statement": xssMatchStatementSchema(), + // Initialize the rest of the elements + previous := &c.values[0] + for i := 1; i < statementSchemaCacheSize; i++ { + c.values[i] = schema.Schema{ + Type: schema.TypeList, + Optional: true, + MaxItems: 1, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "statement": { + Type: schema.TypeList, + Required: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "and_statement": previous, + "byte_match_statement": byteMatchStatementSchema(), + "geo_match_statement": geoMatchStatementSchema(), + "ip_set_reference_statement": ipSetReferenceStatementSchema(), + "label_match_statement": labelMatchStatementSchema(), + "not_statement": previous, + "or_statement": previous, + "regex_match_statement": regexMatchStatementSchema(), + "regex_pattern_set_reference_statement": regexPatternSetReferenceStatementSchema(), + "size_constraint_statement": sizeConstraintSchema(), + "sqli_match_statement": sqliMatchStatementSchema(), + "xss_match_statement": xssMatchStatementSchema(), + }, + }, }, }, }, - }, - }, - } + } + previous = &c.values[i] + } + }) + + return &c.values[level-1] +} + +var statementSchemaCache schemaCache + +func statementSchema(level int) *schema.Schema { + return statementSchemaCache.get(level) } -func byteMatchStatementSchema() *schema.Schema { +var byteMatchStatementSchema = sync.OnceValue(func() *schema.Schema { return &schema.Schema{ Type: schema.TypeList, Optional: true, @@ -155,9 +183,9 @@ func byteMatchStatementSchema() *schema.Schema { }, }, } -} +}) -func geoMatchStatementSchema() *schema.Schema { +var geoMatchStatementSchema = sync.OnceValue(func() *schema.Schema { return &schema.Schema{ Type: schema.TypeList, Optional: true, @@ -174,9 +202,9 @@ func geoMatchStatementSchema() *schema.Schema { }, }, } -} +}) -func ipSetReferenceStatementSchema() *schema.Schema { +var ipSetReferenceStatementSchema = sync.OnceValue(func() *schema.Schema { return &schema.Schema{ Type: schema.TypeList, Optional: true, @@ -218,9 +246,9 @@ func ipSetReferenceStatementSchema() *schema.Schema { }, }, } -} +}) -func labelMatchStatementSchema() *schema.Schema { +var labelMatchStatementSchema = sync.OnceValue(func() *schema.Schema { return &schema.Schema{ Type: schema.TypeList, Optional: true, @@ -243,9 +271,9 @@ func labelMatchStatementSchema() *schema.Schema { }, }, } -} +}) -func regexMatchStatementSchema() *schema.Schema { +var regexMatchStatementSchema = sync.OnceValue(func() *schema.Schema { return &schema.Schema{ Type: schema.TypeList, Optional: true, @@ -265,9 +293,9 @@ func regexMatchStatementSchema() *schema.Schema { }, }, } -} +}) -func regexPatternSetReferenceStatementSchema() *schema.Schema { +var regexPatternSetReferenceStatementSchema = sync.OnceValue(func() *schema.Schema { return &schema.Schema{ Type: schema.TypeList, Optional: true, @@ -284,9 +312,9 @@ func regexPatternSetReferenceStatementSchema() *schema.Schema { }, }, } -} +}) -func sizeConstraintSchema() *schema.Schema { +var sizeConstraintSchema = sync.OnceValue(func() *schema.Schema { return &schema.Schema{ Type: schema.TypeList, Optional: true, @@ -308,9 +336,9 @@ func sizeConstraintSchema() *schema.Schema { }, }, } -} +}) -func sqliMatchStatementSchema() *schema.Schema { +var sqliMatchStatementSchema = sync.OnceValue(func() *schema.Schema { return &schema.Schema{ Type: schema.TypeList, Optional: true, @@ -327,9 +355,9 @@ func sqliMatchStatementSchema() *schema.Schema { }, }, } -} +}) -func xssMatchStatementSchema() *schema.Schema { +var xssMatchStatementSchema = sync.OnceValue(func() *schema.Schema { return &schema.Schema{ Type: schema.TypeList, Optional: true, @@ -341,9 +369,9 @@ func xssMatchStatementSchema() *schema.Schema { }, }, } -} +}) -func fieldToMatchBaseSchema() *schema.Resource { +var fieldToMatchBaseSchema = sync.OnceValue(func() *schema.Resource { return &schema.Resource{ Schema: map[string]*schema.Schema{ "all_query_arguments": emptySchema(), @@ -396,18 +424,18 @@ func fieldToMatchBaseSchema() *schema.Resource { "uri_path": emptySchema(), }, } -} +}) -func fieldToMatchSchema() *schema.Schema { +var fieldToMatchSchema = sync.OnceValue(func() *schema.Schema { return &schema.Schema{ Type: schema.TypeList, Optional: true, MaxItems: 1, Elem: fieldToMatchBaseSchema(), } -} +}) -func jsonBodySchema() *schema.Schema { +var jsonBodySchema = sync.OnceValue(func() *schema.Schema { return &schema.Schema{ Type: schema.TypeList, Optional: true, @@ -425,13 +453,13 @@ func jsonBodySchema() *schema.Schema { Required: true, ValidateDiagFunc: enum.Validate[awstypes.JsonMatchScope](), }, - "oversize_handling": oversizeHandlingOptionalSchema(string(awstypes.OversizeHandlingContinue)), + "oversize_handling": oversizeHandlingOptionalDefaultContinueSchema(), }, }, } -} +}) -func jsonBodyMatchPatternSchema() *schema.Schema { +var jsonBodyMatchPatternSchema = sync.OnceValue(func() *schema.Schema { return &schema.Schema{ Type: schema.TypeList, Required: true, @@ -453,9 +481,9 @@ func jsonBodyMatchPatternSchema() *schema.Schema { }, }, } -} +}) -func forwardedIPConfigSchema() *schema.Schema { +var forwardedIPConfigSchema = sync.OnceValue(func() *schema.Schema { return &schema.Schema{ Type: schema.TypeList, Optional: true, @@ -474,9 +502,9 @@ func forwardedIPConfigSchema() *schema.Schema { }, }, } -} +}) -func textTransformationSchema() *schema.Schema { +var textTransformationSchema = sync.OnceValue(func() *schema.Schema { return &schema.Schema{ Type: schema.TypeSet, Required: true, @@ -495,9 +523,9 @@ func textTransformationSchema() *schema.Schema { }, }, } -} +}) -func visibilityConfigSchema() *schema.Schema { +var visibilityConfigSchema = sync.OnceValue(func() *schema.Schema { return &schema.Schema{ Type: schema.TypeList, Required: true, @@ -523,9 +551,9 @@ func visibilityConfigSchema() *schema.Schema { }, }, } -} +}) -func associationConfigSchema() *schema.Schema { +var associationConfigSchema = sync.OnceValue(func() *schema.Schema { return &schema.Schema{ Type: schema.TypeList, Optional: true, @@ -536,85 +564,42 @@ func associationConfigSchema() *schema.Schema { }, }, } -} +}) -func requestBodySchema() *schema.Schema { +var requestBodySchema = sync.OnceValue(func() *schema.Schema { return &schema.Schema{ Type: schema.TypeList, Optional: true, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "api_gateway": { - Type: schema.TypeList, - Optional: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "default_size_inspection_limit": { - Type: schema.TypeString, - Required: true, - ValidateDiagFunc: enum.Validate[awstypes.SizeInspectionLimit](), - }, - }, - }, - }, - "app_runner_service": { - Type: schema.TypeList, - Optional: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "default_size_inspection_limit": { - Type: schema.TypeString, - Required: true, - ValidateDiagFunc: enum.Validate[awstypes.SizeInspectionLimit](), - }, - }, - }, - }, - "cloudfront": { - Type: schema.TypeList, - Optional: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "default_size_inspection_limit": { - Type: schema.TypeString, - Required: true, - ValidateDiagFunc: enum.Validate[awstypes.SizeInspectionLimit](), - }, - }, - }, - }, - "cognito_user_pool": { - Type: schema.TypeList, - Optional: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "default_size_inspection_limit": { - Type: schema.TypeString, - Required: true, - ValidateDiagFunc: enum.Validate[awstypes.SizeInspectionLimit](), - }, - }, - }, - }, - "verified_access_instance": { - Type: schema.TypeList, - Optional: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "default_size_inspection_limit": { - Type: schema.TypeString, - Required: true, - ValidateDiagFunc: enum.Validate[awstypes.SizeInspectionLimit](), - }, - }, - }, + "api_gateway": requestBodyAssociatedResourceTypeSchema(), + "app_runner_service": requestBodyAssociatedResourceTypeSchema(), + "cloudfront": requestBodyAssociatedResourceTypeSchema(), + "cognito_user_pool": requestBodyAssociatedResourceTypeSchema(), + "verified_access_instance": requestBodyAssociatedResourceTypeSchema(), + }, + }, + } +}) + +var requestBodyAssociatedResourceTypeSchema = sync.OnceValue(func() *schema.Schema { + return &schema.Schema{ + Type: schema.TypeList, + Optional: true, + MaxItems: 1, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "default_size_inspection_limit": { + Type: schema.TypeString, + Required: true, + ValidateDiagFunc: enum.Validate[awstypes.SizeInspectionLimit](), }, }, }, } -} +}) -func allowConfigSchema() *schema.Schema { +var allowConfigSchema = sync.OnceValue(func() *schema.Schema { return &schema.Schema{ Type: schema.TypeList, Optional: true, @@ -625,9 +610,9 @@ func allowConfigSchema() *schema.Schema { }, }, } -} +}) -func captchaConfigSchema() *schema.Schema { +var captchaConfigSchema = sync.OnceValue(func() *schema.Schema { return &schema.Schema{ Type: schema.TypeList, Optional: true, @@ -638,9 +623,9 @@ func captchaConfigSchema() *schema.Schema { }, }, } -} +}) -func outerCaptchaConfigSchema() *schema.Schema { +var outerCaptchaConfigSchema = sync.OnceValue(func() *schema.Schema { return &schema.Schema{ Type: schema.TypeList, Optional: true, @@ -663,9 +648,9 @@ func outerCaptchaConfigSchema() *schema.Schema { }, }, } -} +}) -func challengeConfigSchema() *schema.Schema { +var challengeConfigSchema = sync.OnceValue(func() *schema.Schema { return &schema.Schema{ Type: schema.TypeList, Optional: true, @@ -676,9 +661,9 @@ func challengeConfigSchema() *schema.Schema { }, }, } -} +}) -func outerChallengeConfigSchema() *schema.Schema { +var outerChallengeConfigSchema = sync.OnceValue(func() *schema.Schema { return &schema.Schema{ Type: schema.TypeList, Optional: true, @@ -701,9 +686,9 @@ func outerChallengeConfigSchema() *schema.Schema { }, }, } -} +}) -func countConfigSchema() *schema.Schema { +var countConfigSchema = sync.OnceValue(func() *schema.Schema { return &schema.Schema{ Type: schema.TypeList, Optional: true, @@ -714,9 +699,9 @@ func countConfigSchema() *schema.Schema { }, }, } -} +}) -func blockConfigSchema() *schema.Schema { +var blockConfigSchema = sync.OnceValue(func() *schema.Schema { return &schema.Schema{ Type: schema.TypeList, Optional: true, @@ -727,9 +712,9 @@ func blockConfigSchema() *schema.Schema { }, }, } -} +}) -func customRequestHandlingSchema() *schema.Schema { +var customRequestHandlingSchema = sync.OnceValue(func() *schema.Schema { return &schema.Schema{ Type: schema.TypeList, Optional: true, @@ -761,9 +746,9 @@ func customRequestHandlingSchema() *schema.Schema { }, }, } -} +}) -func customResponseSchema() *schema.Schema { +var customResponseSchema = sync.OnceValue(func() *schema.Schema { return &schema.Schema{ Type: schema.TypeList, Optional: true, @@ -807,9 +792,9 @@ func customResponseSchema() *schema.Schema { }, }, } -} +}) -func customResponseBodySchema() *schema.Schema { +var customResponseBodySchema = sync.OnceValue(func() *schema.Schema { return &schema.Schema{ Type: schema.TypeSet, Optional: true, @@ -836,7 +821,7 @@ func customResponseBodySchema() *schema.Schema { }, }, } -} +}) func cookiesSchema() *schema.Schema { return &schema.Schema{ @@ -899,36 +884,36 @@ func bodySchema() *schema.Schema { MaxItems: 1, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "oversize_handling": oversizeHandlingOptionalSchema(string(awstypes.OversizeHandlingContinue)), + "oversize_handling": oversizeHandlingOptionalDefaultContinueSchema(), }, }, } } -func oversizeHandlingOptionalSchema(defaultValue string) *schema.Schema { +var oversizeHandlingOptionalDefaultContinueSchema = sync.OnceValue(func() *schema.Schema { return &schema.Schema{ Type: schema.TypeString, Optional: true, - Default: defaultValue, + Default: string(awstypes.OversizeHandlingContinue), ValidateDiagFunc: enum.Validate[awstypes.OversizeHandling](), } -} +}) -func oversizeHandlingRequiredSchema() *schema.Schema { +var oversizeHandlingRequiredSchema = sync.OnceValue(func() *schema.Schema { return &schema.Schema{ Type: schema.TypeString, Required: true, ValidateDiagFunc: enum.Validate[awstypes.OversizeHandling](), } -} +}) -func matchScopeSchema() *schema.Schema { +var matchScopeSchema = sync.OnceValue(func() *schema.Schema { return &schema.Schema{ Type: schema.TypeString, Required: true, ValidateDiagFunc: enum.Validate[awstypes.MapMatchScope](), } -} +}) func headerOrderSchema() *schema.Schema { return &schema.Schema{ @@ -968,7 +953,7 @@ func headersSchema() *schema.Schema { } } -func headersMatchPatternBaseSchema() *schema.Schema { +var headersMatchPatternBaseSchema = sync.OnceValue(func() *schema.Schema { return &schema.Schema{ Type: schema.TypeList, Optional: true, @@ -978,11 +963,11 @@ func headersMatchPatternBaseSchema() *schema.Schema { Type: schema.TypeString, ValidateFunc: validation.All( validation.StringLenBetween(1, 64), - validation.StringMatch(regexache.MustCompile(`.*\S.*`), ""), + validation.StringIsNotWhiteSpace, ), }, } -} +}) func webACLRootStatementSchema(level int) *schema.Schema { return &schema.Schema{ @@ -1191,7 +1176,7 @@ func scopeDownStatementSchema(level int) *schema.Schema { } } -func ruleActionOverrideSchema() *schema.Schema { +var ruleActionOverrideSchema = sync.OnceValue(func() *schema.Schema { return &schema.Schema{ Type: schema.TypeList, Optional: true, @@ -1207,7 +1192,7 @@ func ruleActionOverrideSchema() *schema.Schema { }, }, } -} +}) func managedRuleGroupConfigSchema() *schema.Schema { return &schema.Schema{ @@ -1231,7 +1216,7 @@ func managedRuleGroupConfigSchema() *schema.Schema { Required: true, ValidateFunc: validation.All( validation.StringLenBetween(1, 256), - validation.StringMatch(regexache.MustCompile(`.*\S.*`), `must conform to pattern .*\S.* `), + validation.StringIsNotWhiteSpace, ), }, "registration_page_path": { @@ -1239,7 +1224,7 @@ func managedRuleGroupConfigSchema() *schema.Schema { Required: true, ValidateFunc: validation.All( validation.StringLenBetween(1, 256), - validation.StringMatch(regexache.MustCompile(`.*\S.*`), `must conform to pattern .*\S.* `), + validation.StringIsNotWhiteSpace, ), }, "request_inspection": managedRuleGroupConfigACFPRequestInspectionSchema(), @@ -1263,7 +1248,7 @@ func managedRuleGroupConfigSchema() *schema.Schema { Required: true, ValidateFunc: validation.All( validation.StringLenBetween(1, 256), - validation.StringMatch(regexache.MustCompile(`.*\S.*`), `must conform to pattern .*\S.* `), + validation.StringIsNotWhiteSpace, ), }, "request_inspection": managedRuleGroupConfigATPRequestInspectionSchema(), @@ -1295,7 +1280,7 @@ func managedRuleGroupConfigSchema() *schema.Schema { Optional: true, ValidateFunc: validation.All( validation.StringLenBetween(1, 256), - validation.StringMatch(regexache.MustCompile(`.*\S.*`), `must conform to pattern .*\S.* `), + validation.StringIsNotWhiteSpace, ), }, "password_field": { @@ -1309,7 +1294,7 @@ func managedRuleGroupConfigSchema() *schema.Schema { Required: true, ValidateFunc: validation.All( validation.StringLenBetween(1, 512), - validation.StringMatch(regexache.MustCompile(`.*\S.*`), `must conform to pattern .*\S.* `), + validation.StringIsNotWhiteSpace, ), }, }, @@ -1331,7 +1316,7 @@ func managedRuleGroupConfigSchema() *schema.Schema { Required: true, ValidateFunc: validation.All( validation.StringLenBetween(1, 512), - validation.StringMatch(regexache.MustCompile(`.*\S.*`), `must conform to pattern .*\S.* `), + validation.StringIsNotWhiteSpace, ), }, }, @@ -1410,7 +1395,7 @@ func managedRuleGroupConfigACFPRequestInspectionSchema() *schema.Schema { Required: true, ValidateFunc: validation.All( validation.StringLenBetween(1, 512), - validation.StringMatch(regexache.MustCompile(`.*\S.*`), `must conform to pattern .*\S.* `), + validation.StringIsNotWhiteSpace, ), }, }, @@ -1427,7 +1412,7 @@ func managedRuleGroupConfigACFPRequestInspectionSchema() *schema.Schema { Required: true, ValidateFunc: validation.All( validation.StringLenBetween(1, 512), - validation.StringMatch(regexache.MustCompile(`.*\S.*`), `must conform to pattern .*\S.* `), + validation.StringIsNotWhiteSpace, ), }, }, @@ -1464,7 +1449,7 @@ func managedRuleGroupConfigACFPRequestInspectionSchema() *schema.Schema { Required: true, ValidateFunc: validation.All( validation.StringLenBetween(1, 512), - validation.StringMatch(regexache.MustCompile(`.*\S.*`), `must conform to pattern .*\S.* `), + validation.StringIsNotWhiteSpace, ), }, }, @@ -1493,7 +1478,7 @@ func managedRuleGroupConfigATPRequestInspectionSchema() *schema.Schema { Required: true, ValidateFunc: validation.All( validation.StringLenBetween(1, 512), - validation.StringMatch(regexache.MustCompile(`.*\S.*`), `must conform to pattern .*\S.* `), + validation.StringIsNotWhiteSpace, ), }, }, @@ -1515,7 +1500,7 @@ func managedRuleGroupConfigATPRequestInspectionSchema() *schema.Schema { Required: true, ValidateFunc: validation.All( validation.StringLenBetween(1, 512), - validation.StringMatch(regexache.MustCompile(`.*\S.*`), `must conform to pattern .*\S.* `), + validation.StringIsNotWhiteSpace, ), }, }, @@ -1526,7 +1511,7 @@ func managedRuleGroupConfigATPRequestInspectionSchema() *schema.Schema { } } -func managedRuleGroupConfigATPResponseInspectionSchema() *schema.Schema { +var managedRuleGroupConfigATPResponseInspectionSchema = sync.OnceValue(func() *schema.Schema { return &schema.Schema{ Type: schema.TypeList, Optional: true, @@ -1628,4 +1613,4 @@ func managedRuleGroupConfigATPResponseInspectionSchema() *schema.Schema { }, }, } -} +}) diff --git a/internal/tags/tags.go b/internal/tags/tags.go index 12d3b9013ebd..40c06bb057f3 100644 --- a/internal/tags/tags.go +++ b/internal/tags/tags.go @@ -4,32 +4,36 @@ package tags import ( + "sync" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) -// TagsSchema returns the schema to use for tags. -func TagsSchema() *schema.Schema { +// TagsSchema returns the schema to use for configurable resource tags. +var TagsSchema = sync.OnceValue(func() *schema.Schema { return &schema.Schema{ Type: schema.TypeMap, Optional: true, Elem: &schema.Schema{Type: schema.TypeString}, } -} +}) -func TagsSchemaComputed() *schema.Schema { +// TagsSchema returns the schema to use for computed tags, either resource `tags_all` or for data sources. +var TagsSchemaComputed = sync.OnceValue(func() *schema.Schema { return &schema.Schema{ Type: schema.TypeMap, Optional: true, Computed: true, Elem: &schema.Schema{Type: schema.TypeString}, } -} +}) -func TagsSchemaForceNew() *schema.Schema { +// TagsSchema returns the schema to use for configurable resource tags where changes recreate the resource. +var TagsSchemaForceNew = sync.OnceValue(func() *schema.Schema { return &schema.Schema{ Type: schema.TypeMap, Optional: true, ForceNew: true, Elem: &schema.Schema{Type: schema.TypeString}, } -} +})