diff --git a/.actrc b/.actrc index 844f384aea3d..b1b9330fe20b 100644 --- a/.actrc +++ b/.actrc @@ -3,4 +3,5 @@ -P ubuntu-latest=ghcr.io/catthehacker/ubuntu:act-22.04 -P linux=ghcr.io/catthehacker/ubuntu:act-22.04 -P custom-linux-medium=ghcr.io/catthehacker/ubuntu:act-22.04 +-P custom-linux-large=ghcr.io/catthehacker/ubuntu:act-22.04 -P custom-linux-xl=ghcr.io/catthehacker/ubuntu:act-22.04 diff --git a/.ci/.golangci2.yml b/.ci/.golangci2.yml index b392f719ee19..e1a55fb206fc 100644 --- a/.ci/.golangci2.yml +++ b/.ci/.golangci2.yml @@ -78,6 +78,10 @@ linters-settings: - retry.RetryContext - schema.DefaultTimeout - validation.* + # QuickSight schema + - floatBetweenSchema + - intBetweenSchema + - stringLenBetweenSchema # Terraform Plugin Framework - int32validator.* - int64validator.* diff --git a/.ci/semgrep/pluginsdk/quicksight/schema.yml b/.ci/semgrep/pluginsdk/quicksight/schema.yml new file mode 100644 index 000000000000..4cb1c97a78c2 --- /dev/null +++ b/.ci/semgrep/pluginsdk/quicksight/schema.yml @@ -0,0 +1,166 @@ +rules: + - id: quicksight-schema-string-len-between-required + languages: [go] + message: String attributes with length validation should use stringLenBetweenSchema + paths: + include: + - internal/service/quicksight/schema + patterns: + - pattern-inside: "Schema: map[string]*schema.Schema{ ... }" + - pattern: | + { + Type: schema.TypeString, + Required: true, + ValidateFunc: validation.StringLenBetween($MIN, $MAX), + } + fix: stringLenBetweenSchema(attrRequired, $MIN, $MAX) + severity: WARNING + + - id: quicksight-schema-string-len-between-optional + languages: [go] + message: String attributes with length validation should use stringLenBetweenSchema + paths: + include: + - internal/service/quicksight/schema + patterns: + - pattern-inside: "Schema: map[string]*schema.Schema{ ... }" + - pattern: | + { + Type: schema.TypeString, + Optional: true, + ValidateFunc: validation.StringLenBetween($MIN, $MAX), + } + fix: stringLenBetweenSchema(attrOptional, $MIN, $MAX) + severity: WARNING + + - id: quicksight-schema-string-len-between-optionalcomputed + languages: [go] + message: String attributes with length validation should use stringLenBetweenSchema + paths: + include: + - internal/service/quicksight/schema + patterns: + - pattern-inside: "Schema: map[string]*schema.Schema{ ... }" + - pattern-either: + - pattern: | + { + Type: schema.TypeString, + Optional: true, + Computed: true, + ValidateFunc: validation.StringLenBetween($MIN, $MAX), + } + - pattern: | + { + Type: schema.TypeString, + Computed: true, + Optional: true, + ValidateFunc: validation.StringLenBetween($MIN, $MAX), + } + fix: stringLenBetweenSchema(attrOptionalComputed, $MIN, $MAX) + severity: WARNING + + - id: quicksight-schema-string-enum + languages: [go] + message: String attributes with enum validation should use stringEnumSchema[]() + paths: + include: + - internal/service/quicksight/schema + patterns: + - pattern-inside: "Schema: map[string]*schema.Schema{ ... }" + - pattern-either: + - pattern: | + { + Type: schema.TypeString, + $REQOPT: true, + ValidateDiagFunc: $FUNC(), + } + - pattern: | + { + Type: schema.TypeString, + Computed: true, + $REQOPT: true, + ValidateDiagFunc: $FUNC(), + } + - pattern: | + { + Type: schema.TypeString, + $REQOPT: true, + Computed: true, + ValidateDiagFunc: $FUNC(), + } + - metavariable-regex: + metavariable: $REQOPT + regex: 'Required|Optional' + - metavariable-regex: + metavariable: $FUNC + regex: enum\.Validate # Semgrep doesn't seem to recognize the type specification + # Cannot be auto-fixed + severity: WARNING + + - id: quicksight-schema-int-between-required + languages: [go] + message: Int attributes with between validation should use intBetweenSchema + paths: + include: + - internal/service/quicksight/schema + patterns: + - pattern-inside: "Schema: map[string]*schema.Schema{ ... }" + - pattern: | + { + Type: schema.TypeInt, + Required: true, + ValidateFunc: validation.IntBetween($MIN, $MAX), + } + fix: intBetweenSchema(attrRequired, $MIN, $MAX) + severity: WARNING + + - id: quicksight-schema-int-between-optional + languages: [go] + message: Int attributes with between validation should use intBetweenSchema + paths: + include: + - internal/service/quicksight/schema + patterns: + - pattern-inside: "Schema: map[string]*schema.Schema{ ... }" + - pattern: | + { + Type: schema.TypeInt, + Optional: true, + ValidateFunc: validation.IntBetween($MIN, $MAX), + } + fix: intBetweenSchema(attrOptional, $MIN, $MAX) + severity: WARNING + + - id: quicksight-schema-float-between-required + languages: [go] + message: Float attributes with between validation should use floatBetweenSchema + paths: + include: + - internal/service/quicksight/schema + patterns: + - pattern-inside: "Schema: map[string]*schema.Schema{ ... }" + - pattern: | + { + Type: schema.TypeFloat, + Required: true, + ValidateFunc: validation.FloatBetween($MIN, $MAX), + } + fix: floatBetweenSchema(attrRequired, $MIN, $MAX) + severity: WARNING + + - id: quicksight-schema-float-between-optional + languages: [go] + message: Float attributes with between validation should use floatBetweenSchema + paths: + include: + - internal/service/quicksight/schema + patterns: + - pattern-inside: "Schema: map[string]*schema.Schema{ ... }" + - pattern: | + { + Type: schema.TypeFloat, + Optional: true, + ValidateFunc: validation.FloatBetween($MIN, $MAX), + } + fix: floatBetweenSchema(attrOptional, $MIN, $MAX) + severity: WARNING diff --git a/internal/service/quicksight/ingestion_test.go b/internal/service/quicksight/ingestion_test.go index e5765f0c0cbe..09fb5a16d8f9 100644 --- a/internal/service/quicksight/ingestion_test.go +++ b/internal/service/quicksight/ingestion_test.go @@ -49,6 +49,7 @@ func TestAccQuickSightIngestion_basic(t *testing.T) { ImportState: true, ImportStateVerify: true, ImportStateVerifyIgnore: []string{ + "ingestion_status", "ingestion_type", }, }, diff --git a/internal/service/quicksight/schema/analysis.go b/internal/service/quicksight/schema/analysis.go index 23c9ed79993b..c7fb98452756 100644 --- a/internal/service/quicksight/schema/analysis.go +++ b/internal/service/quicksight/schema/analysis.go @@ -7,10 +7,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awstypes "github.com/aws/aws-sdk-go-v2/service/quicksight/types" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" - "github.com/hashicorp/terraform-provider-aws/internal/enum" "github.com/hashicorp/terraform-provider-aws/internal/sdkv2" - "github.com/hashicorp/terraform-provider-aws/internal/verify" "github.com/hashicorp/terraform-provider-aws/names" ) @@ -38,7 +35,7 @@ func AnalysisDefinitionSchema() *schema.Schema { Schema: map[string]*schema.Schema{ "column": columnSchema(true), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_ColumnIdentifier.html "format_configuration": formatConfigurationSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_FormatConfiguration.html - names.AttrRole: stringSchema(false, enum.Validate[awstypes.ColumnRole]()), + names.AttrRole: stringEnumSchema[awstypes.ColumnRole](attrOptional), }, }, }, @@ -49,11 +46,11 @@ func AnalysisDefinitionSchema() *schema.Schema { Optional: true, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "cross_dataset": stringSchema(true, enum.Validate[awstypes.CrossDatasetTypes]()), + "cross_dataset": stringEnumSchema[awstypes.CrossDatasetTypes](attrRequired), "filter_group_id": idSchema(), "filters": filtersSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_Filter.html "scope_configuration": filterScopeConfigurationSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_FilterScopeConfiguration.html - names.AttrStatus: stringSchema(false, enum.Validate[awstypes.Status]()), + names.AttrStatus: stringEnumSchema[awstypes.Status](attrOptional), }, }, }, @@ -78,17 +75,12 @@ func AnalysisDefinitionSchema() *schema.Schema { Optional: true, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "sheet_id": idSchema(), - names.AttrContentType: { - Type: schema.TypeString, - Optional: true, - Computed: true, - ValidateDiagFunc: enum.Validate[awstypes.SheetContentType](), - }, - names.AttrDescription: stringSchema(false, validation.StringLenBetween(1, 1024)), + "sheet_id": idSchema(), + names.AttrContentType: stringEnumSchema[awstypes.SheetContentType](attrOptionalComputed), + names.AttrDescription: stringLenBetweenSchema(attrOptional, 1, 1024), "filter_controls": filterControlsSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_FilterControl.html "layouts": layoutSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_Layout.html - names.AttrName: stringSchema(false, validation.StringLenBetween(1, 2048)), + names.AttrName: stringLenBetweenSchema(attrOptional, 1, 2048), "parameter_controls": parameterControlsSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_ParameterControl.html "sheet_control_layouts": sheetControlLayoutsSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_SheetControlLayout.html "text_boxes": { // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_SheetTextBox.html @@ -99,11 +91,11 @@ func AnalysisDefinitionSchema() *schema.Schema { Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ "sheet_text_box_id": idSchema(), - names.AttrContent: stringSchema(false, validation.StringLenBetween(1, 150000)), + names.AttrContent: stringLenBetweenSchema(attrOptional, 1, 150000), }, }, }, - "title": stringSchema(false, validation.StringLenBetween(1, 1024)), + "title": stringLenBetweenSchema(attrOptional, 1, 1024), "visuals": visualsSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_Visual.html }, }, @@ -134,11 +126,7 @@ func AnalysisSourceEntitySchema() *schema.Schema { Optional: true, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - names.AttrARN: { - Type: schema.TypeString, - Required: true, - ValidateFunc: verify.ValidARN, - }, + names.AttrARN: arnStringSchema(attrRequired), "data_set_references": dataSetReferencesSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_DataSetReference.html }, }, diff --git a/internal/service/quicksight/schema/dashboard.go b/internal/service/quicksight/schema/dashboard.go index 4ee2515a9fb1..17fe14789323 100644 --- a/internal/service/quicksight/schema/dashboard.go +++ b/internal/service/quicksight/schema/dashboard.go @@ -7,9 +7,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awstypes "github.com/aws/aws-sdk-go-v2/service/quicksight/types" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" "github.com/hashicorp/terraform-provider-aws/internal/enum" - "github.com/hashicorp/terraform-provider-aws/internal/verify" "github.com/hashicorp/terraform-provider-aws/names" ) @@ -37,7 +35,7 @@ func DashboardDefinitionSchema() *schema.Schema { Schema: map[string]*schema.Schema{ "column": columnSchema(true), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_ColumnIdentifier.html "format_configuration": formatConfigurationSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_FormatConfiguration.html - names.AttrRole: stringSchema(false, enum.Validate[awstypes.ColumnRole]()), + names.AttrRole: stringEnumSchema[awstypes.ColumnRole](attrOptional), }, }, }, @@ -48,11 +46,11 @@ func DashboardDefinitionSchema() *schema.Schema { Optional: true, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "cross_dataset": stringSchema(true, enum.Validate[awstypes.CrossDatasetTypes]()), + "cross_dataset": stringEnumSchema[awstypes.CrossDatasetTypes](attrRequired), "filter_group_id": idSchema(), "filters": filtersSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_Filter.html "scope_configuration": filterScopeConfigurationSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_FilterScopeConfiguration.html - names.AttrStatus: stringSchema(false, enum.Validate[awstypes.Status]()), + names.AttrStatus: stringEnumSchema[awstypes.Status](attrOptional), }, }, }, @@ -77,17 +75,12 @@ func DashboardDefinitionSchema() *schema.Schema { Optional: true, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "sheet_id": idSchema(), - names.AttrContentType: { - Type: schema.TypeString, - Optional: true, - Computed: true, - ValidateDiagFunc: enum.Validate[awstypes.SheetContentType](), - }, - names.AttrDescription: stringSchema(false, validation.StringLenBetween(1, 1024)), + "sheet_id": idSchema(), + names.AttrContentType: stringEnumSchema[awstypes.SheetContentType](attrOptionalComputed), + names.AttrDescription: stringLenBetweenSchema(attrOptional, 1, 1024), "filter_controls": filterControlsSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_FilterControl.html "layouts": layoutSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_Layout.html - names.AttrName: stringSchema(false, validation.StringLenBetween(1, 2048)), + names.AttrName: stringLenBetweenSchema(attrOptional, 1, 2048), "parameter_controls": parameterControlsSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_ParameterControl.html "sheet_control_layouts": sheetControlLayoutsSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_SheetControlLayout.html "text_boxes": { // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_SheetTextBox.html @@ -98,11 +91,11 @@ func DashboardDefinitionSchema() *schema.Schema { Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ "sheet_text_box_id": idSchema(), - names.AttrContent: stringSchema(false, validation.StringLenBetween(1, 150000)), + names.AttrContent: stringLenBetweenSchema(attrOptional, 1, 150000), }, }, }, - "title": stringSchema(false, validation.StringLenBetween(1, 1024)), + "title": stringLenBetweenSchema(attrOptional, 1, 1024), "visuals": visualsSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_Visual.html }, }, @@ -284,11 +277,7 @@ func DashboardSourceEntitySchema() *schema.Schema { Optional: true, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - names.AttrARN: { - Type: schema.TypeString, - Required: true, - ValidateFunc: verify.ValidARN, - }, + names.AttrARN: arnStringSchema(attrRequired), "data_set_references": dataSetReferencesSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_DataSetReference.html }, }, diff --git a/internal/service/quicksight/schema/data_set.go b/internal/service/quicksight/schema/data_set.go index ea2bfa2817ac..b89922ba0db6 100644 --- a/internal/service/quicksight/schema/data_set.go +++ b/internal/service/quicksight/schema/data_set.go @@ -8,10 +8,8 @@ import ( awstypes "github.com/aws/aws-sdk-go-v2/service/quicksight/types" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" - "github.com/hashicorp/terraform-provider-aws/internal/enum" "github.com/hashicorp/terraform-provider-aws/internal/flex" "github.com/hashicorp/terraform-provider-aws/internal/sdkv2" - "github.com/hashicorp/terraform-provider-aws/internal/verify" "github.com/hashicorp/terraform-provider-aws/names" ) @@ -39,16 +37,8 @@ func DataSetColumnGroupsSchema() *schema.Schema { ValidateFunc: validation.StringLenBetween(1, 128), }, }, - "country_code": { - Type: schema.TypeString, - Required: true, - ValidateDiagFunc: enum.Validate[awstypes.GeoSpatialCountryCode](), - }, - names.AttrName: { - Type: schema.TypeString, - Required: true, - ValidateFunc: validation.StringLenBetween(1, 64), - }, + "country_code": stringEnumSchema[awstypes.GeoSpatialCountryCode](attrRequired), + names.AttrName: stringLenBetweenSchema(attrRequired, 1, 64), }, }, }, @@ -134,11 +124,7 @@ func DataSetFieldFoldersSchema() *schema.Schema { MaxItems: 5000, Elem: &schema.Schema{Type: schema.TypeString}, }, - names.AttrDescription: { - Type: schema.TypeString, - Optional: true, - ValidateFunc: validation.StringLenBetween(0, 500), - }, + names.AttrDescription: stringLenBetweenSchema(attrOptional, 0, 500), }, }, } @@ -152,11 +138,7 @@ func DataSetLogicalTableMapSchema() *schema.Schema { logicalTableMapSchema := func() *schema.Resource { return &schema.Resource{ Schema: map[string]*schema.Schema{ - names.AttrAlias: { - Type: schema.TypeString, - Required: true, - ValidateFunc: validation.StringLenBetween(1, 64), - }, + names.AttrAlias: stringLenBetweenSchema(attrRequired, 1, 64), "data_transforms": { Type: schema.TypeList, Computed: true, @@ -172,22 +154,9 @@ func DataSetLogicalTableMapSchema() *schema.Schema { MaxItems: 1, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "column_name": { - Type: schema.TypeString, - Required: true, - ValidateFunc: validation.StringLenBetween(1, 128), - }, - names.AttrFormat: { - Type: schema.TypeString, - Computed: true, - Optional: true, - ValidateFunc: validation.StringLenBetween(0, 32), - }, - "new_column_type": { - Type: schema.TypeString, - Required: true, - ValidateDiagFunc: enum.Validate[awstypes.ColumnDataType](), - }, + "column_name": stringLenBetweenSchema(attrRequired, 1, 128), + names.AttrFormat: stringLenBetweenSchema(attrOptionalComputed, 0, 32), + "new_column_type": stringEnumSchema[awstypes.ColumnDataType](attrRequired), }, }, }, @@ -205,21 +174,9 @@ func DataSetLogicalTableMapSchema() *schema.Schema { MaxItems: 128, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "column_id": { - Type: schema.TypeString, - Required: true, - ValidateFunc: validation.StringLenBetween(1, 64), - }, - "column_name": { - Type: schema.TypeString, - Required: true, - ValidateFunc: validation.StringLenBetween(1, 128), - }, - names.AttrExpression: { - Type: schema.TypeString, - Required: true, - ValidateFunc: validation.StringLenBetween(1, 4096), - }, + "column_id": stringLenBetweenSchema(attrRequired, 1, 64), + "column_name": stringLenBetweenSchema(attrRequired, 1, 128), + names.AttrExpression: stringLenBetweenSchema(attrRequired, 1, 4096), }, }, }, @@ -233,11 +190,7 @@ func DataSetLogicalTableMapSchema() *schema.Schema { MaxItems: 1, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "condition_expression": { - Type: schema.TypeString, - Required: true, - ValidateFunc: validation.StringLenBetween(1, 4096), - }, + "condition_expression": stringLenBetweenSchema(attrRequired, 1, 4096), }, }, }, @@ -265,16 +218,8 @@ func DataSetLogicalTableMapSchema() *schema.Schema { MaxItems: 1, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "column_name": { - Type: schema.TypeString, - Required: true, - ValidateFunc: validation.StringLenBetween(1, 128), - }, - "new_column_name": { - Type: schema.TypeString, - Required: true, - ValidateFunc: validation.StringLenBetween(1, 128), - }, + "column_name": stringLenBetweenSchema(attrRequired, 1, 128), + "new_column_name": stringLenBetweenSchema(attrRequired, 1, 128), }, }, }, @@ -285,11 +230,7 @@ func DataSetLogicalTableMapSchema() *schema.Schema { MaxItems: 1, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "column_name": { - Type: schema.TypeString, - Required: true, - ValidateFunc: validation.StringLenBetween(1, 128), - }, + "column_name": stringLenBetweenSchema(attrRequired, 1, 128), names.AttrTags: { Type: schema.TypeList, Required: true, @@ -304,21 +245,11 @@ func DataSetLogicalTableMapSchema() *schema.Schema { MaxItems: 1, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "text": { - Type: schema.TypeString, - Computed: true, - Optional: true, - ValidateFunc: validation.StringLenBetween(0, 500), - }, + "text": stringLenBetweenSchema(attrOptionalComputed, 0, 500), }, }, }, - "column_geographic_role": { - Type: schema.TypeString, - Computed: true, - Optional: true, - ValidateDiagFunc: enum.Validate[awstypes.GeoSpatialDataRole](), - }, + "column_geographic_role": stringEnumSchema[awstypes.GeoSpatialDataRole](attrOptionalComputed), }, }, }, @@ -332,18 +263,11 @@ func DataSetLogicalTableMapSchema() *schema.Schema { MaxItems: 1, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "column_name": { - Type: schema.TypeString, - Required: true, - ValidateFunc: validation.StringLenBetween(1, 128), - }, + "column_name": stringLenBetweenSchema(attrRequired, 1, 128), "tag_names": { Type: schema.TypeList, Required: true, - Elem: &schema.Schema{ - Type: schema.TypeString, - ValidateDiagFunc: enum.Validate[awstypes.ColumnTagName](), - }, + Elem: stringEnumSchema[awstypes.ColumnTagName](attrElem), }, }, }, @@ -388,16 +312,8 @@ func DataSetLogicalTableMapSchema() *schema.Schema { }, }, }, - "left_operand": { - Type: schema.TypeString, - Required: true, - ValidateFunc: validation.StringLenBetween(1, 64), - }, - "on_clause": { - Type: schema.TypeString, - Required: true, - ValidateFunc: validation.StringLenBetween(1, 512), - }, + "left_operand": stringLenBetweenSchema(attrRequired, 1, 64), + "on_clause": stringLenBetweenSchema(attrRequired, 1, 512), "right_join_key_properties": { Type: schema.TypeList, Computed: true, @@ -413,25 +329,12 @@ func DataSetLogicalTableMapSchema() *schema.Schema { }, }, }, - "right_operand": { - Type: schema.TypeString, - Required: true, - ValidateFunc: validation.StringLenBetween(1, 64), - }, - names.AttrType: { - Type: schema.TypeString, - Required: true, - ValidateDiagFunc: enum.Validate[awstypes.JoinType](), - }, + "right_operand": stringLenBetweenSchema(attrRequired, 1, 64), + names.AttrType: stringEnumSchema[awstypes.JoinType](attrRequired), }, }, }, - "physical_table_id": { - Type: schema.TypeString, - Computed: true, - Optional: true, - ValidateFunc: validation.StringLenBetween(1, 64), - }, + "physical_table_id": stringLenBetweenSchema(attrOptionalComputed, 1, 64), }, }, }, @@ -492,34 +395,14 @@ func DataSetPhysicalTableMapSchema() *schema.Schema { MaxItems: 2048, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - names.AttrName: { - Type: schema.TypeString, - Required: true, - ValidateFunc: validation.StringLenBetween(1, 128), - }, - names.AttrType: { - Type: schema.TypeString, - Required: true, - ValidateDiagFunc: enum.Validate[awstypes.InputColumnDataType](), - }, + names.AttrName: stringLenBetweenSchema(attrRequired, 1, 128), + names.AttrType: stringEnumSchema[awstypes.InputColumnDataType](attrRequired), }, }, }, - "data_source_arn": { - Type: schema.TypeString, - Required: true, - ValidateFunc: verify.ValidARN, - }, - names.AttrName: { - Type: schema.TypeString, - Required: true, - ValidateFunc: validation.StringLenBetween(1, 64), - }, - "sql_query": { - Type: schema.TypeString, - Required: true, - ValidateFunc: validation.StringLenBetween(1, 65536), - }, + "data_source_arn": arnStringSchema(attrRequired), + names.AttrName: stringLenBetweenSchema(attrRequired, 1, 64), + "sql_query": stringLenBetweenSchema(attrRequired, 1, 65536), }, }, }, @@ -533,16 +416,8 @@ func DataSetPhysicalTableMapSchema() *schema.Schema { MaxItems: 1, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "catalog": { - Type: schema.TypeString, - Optional: true, - ValidateFunc: validation.StringLenBetween(0, 256), - }, - "data_source_arn": { - Type: schema.TypeString, - Required: true, - ValidateFunc: verify.ValidARN, - }, + "catalog": stringLenBetweenSchema(attrOptional, 0, 256), + "data_source_arn": arnStringSchema(attrRequired), "input_columns": { Type: schema.TypeList, Required: true, @@ -550,24 +425,12 @@ func DataSetPhysicalTableMapSchema() *schema.Schema { MaxItems: 2048, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - names.AttrName: { - Type: schema.TypeString, - Required: true, - ValidateFunc: validation.StringLenBetween(1, 128), - }, - names.AttrType: { - Type: schema.TypeString, - Required: true, - ValidateDiagFunc: enum.Validate[awstypes.InputColumnDataType](), - }, + names.AttrName: stringLenBetweenSchema(attrRequired, 1, 128), + names.AttrType: stringEnumSchema[awstypes.InputColumnDataType](attrRequired), }, }, }, - names.AttrName: { - Type: schema.TypeString, - Required: true, - ValidateFunc: validation.StringLenBetween(1, 64), - }, + names.AttrName: stringLenBetweenSchema(attrRequired, 1, 64), names.AttrSchema: { Type: schema.TypeString, Optional: true, @@ -582,11 +445,7 @@ func DataSetPhysicalTableMapSchema() *schema.Schema { MaxItems: 1, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "data_source_arn": { - Type: schema.TypeString, - Required: true, - ValidateFunc: verify.ValidARN, - }, + "data_source_arn": arnStringSchema(attrRequired), "input_columns": { Type: schema.TypeList, Required: true, @@ -594,16 +453,8 @@ func DataSetPhysicalTableMapSchema() *schema.Schema { MaxItems: 2048, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - names.AttrName: { - Type: schema.TypeString, - Required: true, - ValidateFunc: validation.StringLenBetween(1, 128), - }, - names.AttrType: { - Type: schema.TypeString, - Required: true, - ValidateDiagFunc: enum.Validate[awstypes.InputColumnDataType](), - }, + names.AttrName: stringLenBetweenSchema(attrRequired, 1, 128), + names.AttrType: stringEnumSchema[awstypes.InputColumnDataType](attrRequired), }, }, }, @@ -618,30 +469,15 @@ func DataSetPhysicalTableMapSchema() *schema.Schema { Computed: true, Optional: true, }, - "delimiter": { - Type: schema.TypeString, - Computed: true, - Optional: true, - ValidateFunc: validation.StringLenBetween(1, 1), - }, - names.AttrFormat: { - Type: schema.TypeString, - Computed: true, - Optional: true, - ValidateDiagFunc: enum.Validate[awstypes.FileFormat](), - }, + "delimiter": stringLenBetweenSchema(attrOptionalComputed, 1, 1), + names.AttrFormat: stringEnumSchema[awstypes.FileFormat](attrOptionalComputed), "start_from_row": { Type: schema.TypeInt, Computed: true, Optional: true, ValidateFunc: validation.IntAtLeast(1), }, - "text_qualifier": { - Type: schema.TypeString, - Computed: true, - Optional: true, - ValidateDiagFunc: enum.Validate[awstypes.TextQualifier](), - }, + "text_qualifier": stringEnumSchema[awstypes.TextQualifier](attrOptionalComputed), }, }, }, @@ -671,31 +507,11 @@ func DataSetRowLevelPermissionDataSetSchema() *schema.Schema { MaxItems: 1, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - names.AttrARN: { - Type: schema.TypeString, - Required: true, - ValidateFunc: verify.ValidARN, - }, - "format_version": { - Type: schema.TypeString, - Optional: true, - ValidateDiagFunc: enum.Validate[awstypes.RowLevelPermissionFormatVersion](), - }, - names.AttrNamespace: { - Type: schema.TypeString, - Optional: true, - ValidateFunc: validation.StringLenBetween(0, 64), - }, - "permission_policy": { - Type: schema.TypeString, - Required: true, - ValidateDiagFunc: enum.Validate[awstypes.RowLevelPermissionPolicy](), - }, - names.AttrStatus: { - Type: schema.TypeString, - Optional: true, - ValidateDiagFunc: enum.Validate[awstypes.Status](), - }, + names.AttrARN: arnStringSchema(attrRequired), + "format_version": stringEnumSchema[awstypes.RowLevelPermissionFormatVersion](attrOptional), + names.AttrNamespace: stringLenBetweenSchema(attrOptional, 0, 64), + "permission_policy": stringEnumSchema[awstypes.RowLevelPermissionPolicy](attrRequired), + names.AttrStatus: stringEnumSchema[awstypes.Status](attrOptional), }, }, } @@ -712,11 +528,7 @@ func DataSetRowLevelPermissionTagConfigurationSchema() *schema.Schema { MaxItems: 1, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - names.AttrStatus: { - Type: schema.TypeString, - Optional: true, - ValidateDiagFunc: enum.Validate[awstypes.Status](), - }, + names.AttrStatus: stringEnumSchema[awstypes.Status](attrOptional), "tag_rules": { Type: schema.TypeList, Required: true, @@ -729,21 +541,9 @@ func DataSetRowLevelPermissionTagConfigurationSchema() *schema.Schema { Required: true, ValidateFunc: validation.NoZeroValues, }, - "match_all_value": { - Type: schema.TypeString, - Optional: true, - ValidateFunc: validation.StringLenBetween(1, 256), - }, - "tag_key": { - Type: schema.TypeString, - Required: true, - ValidateFunc: validation.StringLenBetween(1, 128), - }, - "tag_multi_value_delimiter": { - Type: schema.TypeString, - Optional: true, - ValidateFunc: validation.StringLenBetween(1, 10), - }, + "match_all_value": stringLenBetweenSchema(attrOptional, 1, 256), + "tag_key": stringLenBetweenSchema(attrRequired, 1, 128), + "tag_multi_value_delimiter": stringLenBetweenSchema(attrOptional, 1, 10), }, }, }, @@ -789,11 +589,7 @@ func DataSetRefreshPropertiesSchema() *schema.Schema { Type: schema.TypeInt, Required: true, }, - "size_unit": { - Type: schema.TypeString, - Required: true, - ValidateDiagFunc: enum.Validate[awstypes.LookbackWindowSizeUnit](), - }, + "size_unit": stringEnumSchema[awstypes.LookbackWindowSizeUnit](attrRequired), }, }, }, diff --git a/internal/service/quicksight/schema/data_source.go b/internal/service/quicksight/schema/data_source.go index 7548ea32cff5..e49bdf398495 100644 --- a/internal/service/quicksight/schema/data_source.go +++ b/internal/service/quicksight/schema/data_source.go @@ -591,11 +591,7 @@ func VPCConnectionPropertiesSchema() *schema.Schema { MaxItems: 1, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "vpc_connection_arn": { - Type: schema.TypeString, - Required: true, - ValidateFunc: verify.ValidARN, - }, + "vpc_connection_arn": arnStringSchema(attrRequired), }, }, } diff --git a/internal/service/quicksight/schema/dataset.go b/internal/service/quicksight/schema/dataset.go index dfa31758a948..adb1b0ad78c9 100644 --- a/internal/service/quicksight/schema/dataset.go +++ b/internal/service/quicksight/schema/dataset.go @@ -4,15 +4,15 @@ package schema import ( + "sync" + "github.com/aws/aws-sdk-go-v2/aws" awstypes "github.com/aws/aws-sdk-go-v2/service/quicksight/types" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" - "github.com/hashicorp/terraform-provider-aws/internal/verify" "github.com/hashicorp/terraform-provider-aws/names" ) -func dataSetIdentifierDeclarationsSchema() *schema.Schema { +var dataSetIdentifierDeclarationsSchema = sync.OnceValue(func() *schema.Schema { return &schema.Schema{ // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_DataSetIdentifierDeclaration.html Type: schema.TypeList, MinItems: 1, @@ -20,25 +20,21 @@ func dataSetIdentifierDeclarationsSchema() *schema.Schema { Required: true, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "data_set_arn": stringSchema(false, verify.ValidARN), - names.AttrIdentifier: stringSchema(false, validation.StringLenBetween(1, 2048)), + "data_set_arn": arnStringSchema(attrOptional), + names.AttrIdentifier: stringLenBetweenSchema(attrOptional, 1, 2048), }, }, } -} +}) -func dataSetReferencesSchema() *schema.Schema { +var dataSetReferencesSchema = sync.OnceValue(func() *schema.Schema { return &schema.Schema{ // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_DataSetReference.html Type: schema.TypeList, Required: true, MinItems: 1, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "data_set_arn": { - Type: schema.TypeString, - Required: true, - ValidateFunc: verify.ValidARN, - }, + "data_set_arn": arnStringSchema(attrRequired), "data_set_placeholder": { Type: schema.TypeString, Required: true, @@ -46,7 +42,7 @@ func dataSetReferencesSchema() *schema.Schema { }, }, } -} +}) func expandDataSetIdentifierDeclarations(tfList []interface{}) []awstypes.DataSetIdentifierDeclaration { if len(tfList) == 0 { diff --git a/internal/service/quicksight/schema/parameters.go b/internal/service/quicksight/schema/parameters.go index 29659bcfadec..ba3061242fc5 100644 --- a/internal/service/quicksight/schema/parameters.go +++ b/internal/service/quicksight/schema/parameters.go @@ -4,9 +4,9 @@ package schema import ( + "sync" "time" - "github.com/YakDriver/regexache" "github.com/aws/aws-sdk-go-v2/aws" awstypes "github.com/aws/aws-sdk-go-v2/service/quicksight/types" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" @@ -31,7 +31,7 @@ func ParametersSchema() *schema.Schema { Optional: true, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - names.AttrName: stringSchema(true, validation.StringMatch(regexache.MustCompile(`.*\S.*`), "")), + names.AttrName: stringNonEmptyRequiredSchema(), names.AttrValues: { Type: schema.TypeList, MinItems: 1, @@ -51,7 +51,7 @@ func ParametersSchema() *schema.Schema { Optional: true, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - names.AttrName: stringSchema(true, validation.StringMatch(regexache.MustCompile(`.*\S.*`), "")), + names.AttrName: stringNonEmptyRequiredSchema(), names.AttrValues: { Type: schema.TypeList, MinItems: 1, @@ -70,7 +70,7 @@ func ParametersSchema() *schema.Schema { Optional: true, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - names.AttrName: stringSchema(true, validation.StringMatch(regexache.MustCompile(`.*\S.*`), "")), + names.AttrName: stringNonEmptyRequiredSchema(), names.AttrValues: { Type: schema.TypeList, MinItems: 1, @@ -89,7 +89,7 @@ func ParametersSchema() *schema.Schema { Optional: true, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - names.AttrName: stringSchema(true, validation.StringMatch(regexache.MustCompile(`.*\S.*`), "")), + names.AttrName: stringNonEmptyRequiredSchema(), names.AttrValues: { Type: schema.TypeList, MinItems: 1, @@ -106,6 +106,14 @@ func ParametersSchema() *schema.Schema { } } +var stringNonEmptyRequiredSchema = sync.OnceValue(func() *schema.Schema { + return &schema.Schema{ + Type: schema.TypeString, + Required: true, + ValidateFunc: validation.StringIsNotWhiteSpace, + } +}) + func ExpandParameters(tfList []interface{}) *awstypes.Parameters { if len(tfList) == 0 || tfList[0] == nil { return nil diff --git a/internal/service/quicksight/schema/permissions.go b/internal/service/quicksight/schema/permissions.go index 39f1ecfcf1d8..feea4ddc1167 100644 --- a/internal/service/quicksight/schema/permissions.go +++ b/internal/service/quicksight/schema/permissions.go @@ -7,7 +7,6 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awstypes "github.com/aws/aws-sdk-go-v2/service/quicksight/types" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" "github.com/hashicorp/terraform-provider-aws/internal/flex" "github.com/hashicorp/terraform-provider-aws/names" ) @@ -27,11 +26,7 @@ func PermissionsSchema() *schema.Schema { MaxItems: 20, Elem: &schema.Schema{Type: schema.TypeString}, }, - names.AttrPrincipal: { - Type: schema.TypeString, - Required: true, - ValidateFunc: validation.StringLenBetween(1, 256), - }, + names.AttrPrincipal: stringLenBetweenSchema(attrRequired, 1, 256), }, }, } diff --git a/internal/service/quicksight/schema/template.go b/internal/service/quicksight/schema/template.go index 156718a5cb33..582154f177ba 100644 --- a/internal/service/quicksight/schema/template.go +++ b/internal/service/quicksight/schema/template.go @@ -4,7 +4,8 @@ package schema import ( - "fmt" + "reflect" + "sync" "github.com/YakDriver/regexache" "github.com/aws/aws-sdk-go-v2/aws" @@ -40,7 +41,7 @@ func TemplateDefinitionSchema() *schema.Schema { Schema: map[string]*schema.Schema{ "column": columnSchema(true), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_ColumnIdentifier.html "format_configuration": formatConfigurationSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_FormatConfiguration.html - names.AttrRole: stringSchema(false, enum.Validate[awstypes.ColumnRole]()), + names.AttrRole: stringEnumSchema[awstypes.ColumnRole](attrOptional), }, }, }, @@ -51,11 +52,11 @@ func TemplateDefinitionSchema() *schema.Schema { Optional: true, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "cross_dataset": stringSchema(true, enum.Validate[awstypes.CrossDatasetTypes]()), + "cross_dataset": stringEnumSchema[awstypes.CrossDatasetTypes](attrRequired), "filter_group_id": idSchema(), "filters": filtersSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_Filter.html "scope_configuration": filterScopeConfigurationSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_FilterScopeConfiguration.html - names.AttrStatus: stringSchema(false, enum.Validate[awstypes.Status]()), + names.AttrStatus: stringEnumSchema[awstypes.Status](attrOptional), }, }, }, @@ -80,17 +81,12 @@ func TemplateDefinitionSchema() *schema.Schema { Optional: true, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "sheet_id": idSchema(), - names.AttrContentType: { - Type: schema.TypeString, - Optional: true, - Computed: true, - ValidateDiagFunc: enum.Validate[awstypes.SheetContentType](), - }, - names.AttrDescription: stringSchema(false, validation.StringLenBetween(1, 1024)), + "sheet_id": idSchema(), + names.AttrContentType: stringEnumSchema[awstypes.SheetContentType](attrOptionalComputed), + names.AttrDescription: stringLenBetweenSchema(attrOptional, 1, 1024), "filter_controls": filterControlsSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_FilterControl.html "layouts": layoutSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_Layout.html - names.AttrName: stringSchema(false, validation.StringLenBetween(1, 2048)), + names.AttrName: stringLenBetweenSchema(attrOptional, 1, 2048), "parameter_controls": parameterControlsSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_ParameterControl.html "sheet_control_layouts": sheetControlLayoutsSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_SheetControlLayout.html "text_boxes": { // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_SheetTextBox.html @@ -101,11 +97,11 @@ func TemplateDefinitionSchema() *schema.Schema { Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ "sheet_text_box_id": idSchema(), - names.AttrContent: stringSchema(false, validation.StringLenBetween(1, 150000)), + names.AttrContent: stringLenBetweenSchema(attrOptional, 1, 150000), }, }, }, - "title": stringSchema(false, validation.StringLenBetween(1, 1024)), + "title": stringLenBetweenSchema(attrOptional, 1, 1024), "visuals": visualsSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_Visual.html }, }, @@ -115,94 +111,320 @@ func TemplateDefinitionSchema() *schema.Schema { } } -func stringOptionalComputedSchema(validateFunc any) *schema.Schema { - switch v := validateFunc.(type) { - case schema.SchemaValidateDiagFunc: - return &schema.Schema{ - Type: schema.TypeString, - Optional: true, - Computed: true, - ValidateDiagFunc: v, - } - case schema.SchemaValidateFunc: - return stringOptionalComputedSchema(validation.ToDiagFunc(v)) - default: - panic(fmt.Sprintf("unsupported validateFunc type: %T", v)) //lintignore:R009 +type attrHandling int + +const ( + attrElem attrHandling = 0 + attrRequired attrHandling = 1 << iota + attrOptional + attrComputed + attrOptionalComputed = attrOptional | attrComputed +) + +func (x attrHandling) isRequired() bool { + return x&attrRequired != 0 +} + +func (x attrHandling) isOptional() bool { + return x&attrOptional != 0 +} + +func (x attrHandling) isComputed() bool { + return x&attrComputed != 0 +} + +var arnStringSchemaCache syncMap[attrHandling, *schema.Schema] + +func arnStringSchema(handling attrHandling) *schema.Schema { + s, ok := arnStringSchemaCache.Load(handling) + if ok { + return s + } + + // Use a separate `LoadOrStore` to avoid allocation if item is already in the cache + // Use `LoadOrStore` instead of `Store` in case there is a race + s, _ = arnStringSchemaCache.LoadOrStore( + handling, + &schema.Schema{ + Type: schema.TypeString, + Required: handling.isRequired(), + Optional: handling.isOptional(), + Computed: handling.isComputed(), + ValidateFunc: verify.ValidARN, + }, + ) + return s +} + +var utcTimestampStringSchemaCache syncMap[attrHandling, *schema.Schema] + +func utcTimestampStringSchema(handling attrHandling) *schema.Schema { + s, ok := utcTimestampStringSchemaCache.Load(handling) + if ok { + return s + } + + // Use a separate `LoadOrStore` to avoid allocation if item is already in the cache + // Use `LoadOrStore` instead of `Store` in case there is a race + s, _ = utcTimestampStringSchemaCache.LoadOrStore( + handling, + &schema.Schema{ + Type: schema.TypeString, + Required: handling.isRequired(), + Optional: handling.isOptional(), + Computed: handling.isComputed(), + ValidateFunc: verify.ValidUTCTimestamp, + }, + ) + return s +} + +type stringLenBetweenIdentity struct { + handling attrHandling + min, max int +} + +var stringLenBetweenSchemaCache syncMap[stringLenBetweenIdentity, *schema.Schema] + +func stringLenBetweenSchema(handling attrHandling, min, max int) *schema.Schema { + id := stringLenBetweenIdentity{ + handling: handling, + min: min, + max: max, + } + + s, ok := stringLenBetweenSchemaCache.Load(id) + if ok { + return s + } + + // Use a separate `LoadOrStore` to avoid allocation if item is already in the cache + // Use `LoadOrStore` instead of `Store` in case there is a race + s, _ = stringLenBetweenSchemaCache.LoadOrStore( + id, + &schema.Schema{ + Type: schema.TypeString, + Required: handling.isRequired(), + Optional: handling.isOptional(), + Computed: handling.isComputed(), + ValidateFunc: validation.StringLenBetween(min, max), + }, + ) + return s +} + +type stringMatchIdentity struct { + handling attrHandling + re, message string +} + +var stringMatchSchemaCache syncMap[stringMatchIdentity, *schema.Schema] + +func stringMatchSchema(handling attrHandling, re, message string) *schema.Schema { + id := stringMatchIdentity{ + handling: handling, + re: re, + message: message, } + + s, ok := stringMatchSchemaCache.Load(id) + if ok { + return s + } + + // Use a separate `LoadOrStore` to avoid allocation if item is already in the cache + // Use `LoadOrStore` instead of `Store` in case there is a race + s, _ = stringMatchSchemaCache.LoadOrStore( + id, + &schema.Schema{ + Type: schema.TypeString, + Required: handling.isRequired(), + Optional: handling.isOptional(), + Computed: handling.isComputed(), + ValidateFunc: validation.StringMatch(regexache.MustCompile(re), message), + }, + ) + return s } -func stringSchema(required bool, validateFunc any) *schema.Schema { - switch v := validateFunc.(type) { - case schema.SchemaValidateDiagFunc: - return &schema.Schema{ +type stringEnumIdentity struct { + handling attrHandling + typ reflect.Type +} + +var stringEnumSchemaCache syncMap[stringEnumIdentity, *schema.Schema] + +func stringEnumSchema[T enum.Valueser[T]](handling attrHandling) *schema.Schema { + id := stringEnumIdentity{ + handling: handling, + typ: reflect.TypeFor[T](), + } + + s, ok := stringEnumSchemaCache.Load(id) + if ok { + return s + } + + // Use a separate `LoadOrStore` to avoid allocation if item is already in the cache + // Use `LoadOrStore` instead of `Store` in case there is a race + s, _ = stringEnumSchemaCache.LoadOrStore( + id, + &schema.Schema{ Type: schema.TypeString, - Required: required, - Optional: !required, - ValidateDiagFunc: v, - } - case schema.SchemaValidateFunc: - return stringSchema(required, validation.ToDiagFunc(v)) - case func(interface{}, string) ([]string, []error): - return stringSchema(required, schema.SchemaValidateFunc(v)) - default: - panic(fmt.Sprintf("unsupported validateFunc type: %T", v)) //lintignore:R009 - } -} - -func intSchema(required bool, validateFunc any) *schema.Schema { - switch v := validateFunc.(type) { - case schema.SchemaValidateDiagFunc: - return &schema.Schema{ - Type: schema.TypeInt, - Required: required, - Optional: !required, - ValidateDiagFunc: v, - } - case schema.SchemaValidateFunc: - return intSchema(required, validation.ToDiagFunc(v)) - case func(interface{}, string) ([]string, []error): - return intSchema(required, schema.SchemaValidateFunc(v)) - default: - panic(fmt.Sprintf("unsupported validateFunc type: %T", v)) //lintignore:R009 - } -} - -func floatSchema(required bool, validateFunc any) *schema.Schema { - switch v := validateFunc.(type) { - case schema.SchemaValidateDiagFunc: - return &schema.Schema{ - Type: schema.TypeFloat, - Required: required, - Optional: !required, - ValidateDiagFunc: v, - } - case schema.SchemaValidateFunc: - return floatSchema(required, validation.ToDiagFunc(v)) - case func(interface{}, string) ([]string, []error): - return floatSchema(required, schema.SchemaValidateFunc(v)) - default: - panic(fmt.Sprintf("unsupported validateFunc type: %T", v)) //lintignore:R009 + Required: handling.isRequired(), + Optional: handling.isOptional(), + Computed: handling.isComputed(), + ValidateDiagFunc: enum.Validate[T](), + }, + ) + return s +} + +// syncMap is a type-safe wrapper around `sync.Map` +type syncMap[K comparable, V any] struct { + m sync.Map +} + +func (m *syncMap[K, V]) Load(k K) (V, bool) { + if a, b := m.m.Load(k); b { + return a.(V), true + } else { + var zero V + return zero, false } } +func (m *syncMap[K, V]) LoadOrStore(k K, v V) (V, bool) { + a, b := m.m.LoadOrStore(k, v) + return a.(V), b +} + +type intBetweenIdentity struct { + handling attrHandling + min, max int +} + +var intBetweenSchemaCache syncMap[intBetweenIdentity, *schema.Schema] + +func intBetweenSchema(handling attrHandling, min, max int) *schema.Schema { + id := intBetweenIdentity{ + handling: handling, + min: min, + max: max, + } + + s, ok := intBetweenSchemaCache.Load(id) + if ok { + return s + } + + // Use a separate `LoadOrStore` to avoid allocation if item is already in the cache + // Use `LoadOrStore` instead of `Store` in case there is a race + s, _ = intBetweenSchemaCache.LoadOrStore( + id, + &schema.Schema{ + Type: schema.TypeInt, + Required: handling.isRequired(), + Optional: handling.isOptional(), + Computed: handling.isComputed(), + ValidateFunc: validation.IntBetween(min, max), + }, + ) + return s +} + +func intAtLeastSchema(handling attrHandling, min int) *schema.Schema { + id := intBetweenIdentity{ + handling: handling, + min: min, + max: -1, + } + + s, ok := intBetweenSchemaCache.Load(id) + if ok { + return s + } + + // Use a separate `LoadOrStore` to avoid allocation if item is already in the cache + // Use `LoadOrStore` instead of `Store` in case there is a race + s, _ = intBetweenSchemaCache.LoadOrStore( + id, + &schema.Schema{ + Type: schema.TypeInt, + Required: handling.isRequired(), + Optional: handling.isOptional(), + Computed: handling.isComputed(), + ValidateFunc: validation.IntAtLeast(min), + }, + ) + return s +} + +type floatBetweenIdentity struct { + handling attrHandling + min, max float64 +} + +var floatBetweenSchemaCache syncMap[floatBetweenIdentity, *schema.Schema] + +func floatBetweenSchema(handling attrHandling, min, max float64) *schema.Schema { + id := floatBetweenIdentity{ + handling: handling, + min: min, + max: max, + } + + s, ok := floatBetweenSchemaCache.Load(id) + if ok { + return s + } + + // Use a separate `LoadOrStore` to avoid allocation if item is already in the cache + // Use `LoadOrStore` instead of `Store` in case there is a race + s, _ = floatBetweenSchemaCache.LoadOrStore( + id, + &schema.Schema{ + Type: schema.TypeFloat, + Required: handling.isRequired(), + Optional: handling.isOptional(), + Computed: handling.isComputed(), + ValidateFunc: validation.FloatBetween(min, max), + }, + ) + return s +} + +var aggregationFunctionSchemaCache syncMap[bool, *schema.Schema] + func aggregationFunctionSchema(required bool) *schema.Schema { - return &schema.Schema{ // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_AggregationFunction.html - Type: schema.TypeList, - Required: required, - Optional: !required, - MinItems: 1, - MaxItems: 1, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "categorical_aggregation_function": stringSchema(false, enum.Validate[awstypes.CategoricalAggregationFunction]()), - "date_aggregation_function": stringSchema(false, enum.Validate[awstypes.DateAggregationFunction]()), - "numerical_aggregation_function": numericalAggregationFunctionSchema(false), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_NumericalAggregationFunction.html + s, ok := aggregationFunctionSchemaCache.Load(required) + if ok { + return s + } + + // Use a separate `LoadOrStore` to avoid allocation if item is already in the cache + // Use `LoadOrStore` instead of `Store` in case there is a race + s, _ = aggregationFunctionSchemaCache.LoadOrStore( + required, + &schema.Schema{ // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_AggregationFunction.html + Type: schema.TypeList, + Required: required, + Optional: !required, + MinItems: 1, + MaxItems: 1, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "categorical_aggregation_function": stringEnumSchema[awstypes.CategoricalAggregationFunction](attrOptional), + "date_aggregation_function": stringEnumSchema[awstypes.DateAggregationFunction](attrOptional), + "numerical_aggregation_function": numericalAggregationFunctionSchema(false), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_NumericalAggregationFunction.html + }, }, }, - } + ) + return s } -func calculatedFieldsSchema() *schema.Schema { +var calculatedFieldsSchema = sync.OnceValue(func() *schema.Schema { return &schema.Schema{ // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_CalculatedField.html Type: schema.TypeSet, MinItems: 1, @@ -210,45 +432,54 @@ func calculatedFieldsSchema() *schema.Schema { Optional: true, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "data_set_identifier": stringSchema(true, validation.StringLenBetween(1, 2048)), - names.AttrExpression: stringSchema(true, validation.StringLenBetween(1, 32000)), - names.AttrName: stringSchema(true, validation.StringLenBetween(1, 128)), + "data_set_identifier": stringLenBetweenSchema(attrRequired, 1, 2048), + names.AttrExpression: stringLenBetweenSchema(attrRequired, 1, 32000), + names.AttrName: stringLenBetweenSchema(attrRequired, 1, 128), }, }, } -} +}) + +var numericalAggregationFunctionSchemaCache syncMap[bool, *schema.Schema] func numericalAggregationFunctionSchema(required bool) *schema.Schema { - return &schema.Schema{ // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_NumericalAggregationFunction.html - Type: schema.TypeList, - Required: required, - Optional: !required, - MinItems: 1, - MaxItems: 1, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "percentile_aggregation": { // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_PercentileAggregation.html - Type: schema.TypeList, - Optional: true, - MinItems: 1, - MaxItems: 1, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "percentile_value": { - Type: schema.TypeFloat, - Optional: true, - ValidateFunc: validation.IntBetween(0, 100), + s, ok := numericalAggregationFunctionSchemaCache.Load(required) + if ok { + return s + } + + // Use a separate `LoadOrStore` to avoid allocation if item is already in the cache + // Use `LoadOrStore` instead of `Store` in case there is a race + s, _ = numericalAggregationFunctionSchemaCache.LoadOrStore( + required, + &schema.Schema{ // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_NumericalAggregationFunction.html + Type: schema.TypeList, + Required: required, + Optional: !required, + MinItems: 1, + MaxItems: 1, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "percentile_aggregation": { // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_PercentileAggregation.html + Type: schema.TypeList, + Optional: true, + MinItems: 1, + MaxItems: 1, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "percentile_value": floatBetweenSchema(attrOptional, 0, 100), }, }, }, + "simple_numerical_aggregation": stringEnumSchema[awstypes.SimpleNumericalAggregationFunction](attrOptional), }, - "simple_numerical_aggregation": stringSchema(false, enum.Validate[awstypes.SimpleNumericalAggregationFunction]()), }, }, - } + ) + return s } -func idSchema() *schema.Schema { +var idSchema = sync.OnceValue(func() *schema.Schema { return &schema.Schema{ Type: schema.TypeString, Required: true, @@ -257,22 +488,35 @@ func idSchema() *schema.Schema { validation.StringMatch(regexache.MustCompile(`[\w\-]+`), "must contain only alphanumeric, hyphen, and underscore characters"), ), } -} +}) + +var columnSchemaCache syncMap[bool, *schema.Schema] func columnSchema(required bool) *schema.Schema { - return &schema.Schema{ // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_ColumnIdentifier.html - Type: schema.TypeList, - MinItems: 1, - MaxItems: 1, - Required: required, - Optional: !required, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "column_name": stringSchema(true, validation.StringLenBetween(1, 128)), - "data_set_identifier": stringSchema(true, validation.StringLenBetween(1, 2048)), + s, ok := columnSchemaCache.Load(required) + if ok { + return s + } + + // Use a separate `LoadOrStore` to avoid allocation if item is already in the cache + // Use `LoadOrStore` instead of `Store` in case there is a race + s, _ = columnSchemaCache.LoadOrStore( + required, + &schema.Schema{ // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_ColumnIdentifier.html + Type: schema.TypeList, + MinItems: 1, + MaxItems: 1, + Required: required, + Optional: !required, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "column_name": stringLenBetweenSchema(attrRequired, 1, 128), + "data_set_identifier": stringLenBetweenSchema(attrRequired, 1, 2048), + }, }, }, - } + ) + return s } func dataSetConfigurationSchema() *schema.Schema { @@ -351,7 +595,7 @@ func dataSetConfigurationSchema() *schema.Schema { } } -func rollingDateConfigurationSchema() *schema.Schema { +var rollingDateConfigurationSchema = sync.OnceValue(func() *schema.Schema { return &schema.Schema{ // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_RollingDateConfiguration.html Type: schema.TypeList, MinItems: 1, @@ -359,12 +603,12 @@ func rollingDateConfigurationSchema() *schema.Schema { Optional: true, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "data_set_identifier": stringSchema(false, validation.StringLenBetween(1, 2048)), - names.AttrExpression: stringSchema(true, validation.StringLenBetween(1, 4096)), + "data_set_identifier": stringLenBetweenSchema(attrOptional, 1, 2048), + names.AttrExpression: stringLenBetweenSchema(attrRequired, 1, 4096), }, }, } -} +}) func TemplateSourceEntitySchema() *schema.Schema { return &schema.Schema{ @@ -384,11 +628,7 @@ func TemplateSourceEntitySchema() *schema.Schema { ExactlyOneOf: []string{"source_entity.0.source_analysis", "source_entity.0.source_template"}, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - names.AttrARN: { - Type: schema.TypeString, - Required: true, - ValidateFunc: verify.ValidARN, - }, + names.AttrARN: arnStringSchema(attrRequired), "data_set_references": dataSetReferencesSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_DataSetReference.html }, }, @@ -400,11 +640,7 @@ func TemplateSourceEntitySchema() *schema.Schema { ExactlyOneOf: []string{"source_entity.0.source_analysis", "source_entity.0.source_template"}, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - names.AttrARN: { - Type: schema.TypeString, - Required: true, - ValidateFunc: verify.ValidARN, - }, + names.AttrARN: arnStringSchema(attrRequired), }, }, }, diff --git a/internal/service/quicksight/schema/template_control.go b/internal/service/quicksight/schema/template_control.go index 611fe24be52a..e9eacc77b473 100644 --- a/internal/service/quicksight/schema/template_control.go +++ b/internal/service/quicksight/schema/template_control.go @@ -4,16 +4,16 @@ package schema import ( + "sync" + "github.com/aws/aws-sdk-go-v2/aws" awstypes "github.com/aws/aws-sdk-go-v2/service/quicksight/types" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" - "github.com/hashicorp/terraform-provider-aws/internal/enum" "github.com/hashicorp/terraform-provider-aws/internal/flex" "github.com/hashicorp/terraform-provider-aws/names" ) -func filterControlsSchema() *schema.Schema { +var filterControlsSchema = sync.OnceValue(func() *schema.Schema { return &schema.Schema{ // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_FilterControl.html Type: schema.TypeList, Optional: true, @@ -30,9 +30,9 @@ func filterControlsSchema() *schema.Schema { Schema: map[string]*schema.Schema{ "filter_control_id": idSchema(), "source_filter_id": idSchema(), - "title": stringSchema(true, validation.StringLenBetween(1, 2048)), + "title": stringLenBetweenSchema(attrRequired, 1, 2048), "display_options": dateTimePickerControlDisplayOptionsSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_DateTimePickerControlDisplayOptions.html - names.AttrType: stringSchema(false, enum.Validate[awstypes.SheetControlDateTimePickerType]()), + names.AttrType: stringEnumSchema[awstypes.SheetControlDateTimePickerType](attrOptional), }, }, }, @@ -45,11 +45,11 @@ func filterControlsSchema() *schema.Schema { Schema: map[string]*schema.Schema{ "filter_control_id": idSchema(), "source_filter_id": idSchema(), - "title": stringSchema(true, validation.StringLenBetween(1, 2048)), + "title": stringLenBetweenSchema(attrRequired, 1, 2048), "cascading_control_configuration": cascadingControlConfigurationSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_CascadingControlConfiguration.html "display_options": dropDownControlDisplayOptionsSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_DropDownControlDisplayOptions.html "selectable_values": filterSelectableValuesSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_FilterSelectableValues.html - names.AttrType: stringSchema(false, enum.Validate[awstypes.SheetControlListType]()), + names.AttrType: stringEnumSchema[awstypes.SheetControlListType](attrOptional), }, }, }, @@ -62,11 +62,11 @@ func filterControlsSchema() *schema.Schema { Schema: map[string]*schema.Schema{ "filter_control_id": idSchema(), "source_filter_id": idSchema(), - "title": stringSchema(true, validation.StringLenBetween(1, 2048)), + "title": stringLenBetweenSchema(attrRequired, 1, 2048), "cascading_control_configuration": cascadingControlConfigurationSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_CascadingControlConfiguration.html "display_options": listControlDisplayOptionsSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_ListControlDisplayOptions.html "selectable_values": filterSelectableValuesSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_FilterSelectableValues.html - names.AttrType: stringSchema(false, enum.Validate[awstypes.SheetControlListType]()), + names.AttrType: stringEnumSchema[awstypes.SheetControlListType](attrOptional), }, }, }, @@ -79,7 +79,7 @@ func filterControlsSchema() *schema.Schema { Schema: map[string]*schema.Schema{ "filter_control_id": idSchema(), "source_filter_id": idSchema(), - "title": stringSchema(true, validation.StringLenBetween(1, 2048)), + "title": stringLenBetweenSchema(attrRequired, 1, 2048), "display_options": { // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_RelativeDateTimeControlDisplayOptions.html Type: schema.TypeList, Optional: true, @@ -87,7 +87,7 @@ func filterControlsSchema() *schema.Schema { MaxItems: 1, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "date_time_format": stringSchema(false, validation.StringLenBetween(1, 128)), + "date_time_format": stringLenBetweenSchema(attrOptional, 1, 128), "title_options": labelOptionsSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_LabelOptions.html }, }, @@ -104,7 +104,7 @@ func filterControlsSchema() *schema.Schema { Schema: map[string]*schema.Schema{ "filter_control_id": idSchema(), "source_filter_id": idSchema(), - "title": stringSchema(true, validation.StringLenBetween(1, 2048)), + "title": stringLenBetweenSchema(attrRequired, 1, 2048), "maximum_value": { Type: schema.TypeFloat, Required: true, @@ -118,7 +118,7 @@ func filterControlsSchema() *schema.Schema { Required: true, }, "display_options": sliderControlDisplayOptionsSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_SliderControlDisplayOptions.html - names.AttrType: stringSchema(false, enum.Validate[awstypes.SheetControlSliderType]()), + names.AttrType: stringEnumSchema[awstypes.SheetControlSliderType](attrOptional), }, }, }, @@ -131,8 +131,8 @@ func filterControlsSchema() *schema.Schema { Schema: map[string]*schema.Schema{ "filter_control_id": idSchema(), "source_filter_id": idSchema(), - "title": stringSchema(true, validation.StringLenBetween(1, 2048)), - "delimiter": stringSchema(false, validation.StringLenBetween(1, 2048)), + "title": stringLenBetweenSchema(attrRequired, 1, 2048), + "delimiter": stringLenBetweenSchema(attrOptional, 1, 2048), "display_options": textAreaControlDisplayOptionsSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_TextAreaControlDisplayOptions.html }, }, @@ -146,7 +146,7 @@ func filterControlsSchema() *schema.Schema { Schema: map[string]*schema.Schema{ "filter_control_id": idSchema(), "source_filter_id": idSchema(), - "title": stringSchema(true, validation.StringLenBetween(1, 2048)), + "title": stringLenBetweenSchema(attrRequired, 1, 2048), "display_options": textFieldControlDisplayOptionsSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_TextFieldControlDisplayOptions.html }, }, @@ -154,9 +154,9 @@ func filterControlsSchema() *schema.Schema { }, }, } -} +}) -func textFieldControlDisplayOptionsSchema() *schema.Schema { +var textFieldControlDisplayOptionsSchema = sync.OnceValue(func() *schema.Schema { return &schema.Schema{ // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_TextFieldControlDisplayOptions.html Type: schema.TypeList, Optional: true, @@ -169,9 +169,9 @@ func textFieldControlDisplayOptionsSchema() *schema.Schema { }, }, } -} +}) -func textAreaControlDisplayOptionsSchema() *schema.Schema { +var textAreaControlDisplayOptionsSchema = sync.OnceValue(func() *schema.Schema { return &schema.Schema{ // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_TextAreaControlDisplayOptions.html Type: schema.TypeList, Optional: true, @@ -184,9 +184,9 @@ func textAreaControlDisplayOptionsSchema() *schema.Schema { }, }, } -} +}) -func sliderControlDisplayOptionsSchema() *schema.Schema { +var sliderControlDisplayOptionsSchema = sync.OnceValue(func() *schema.Schema { return &schema.Schema{ // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_SliderControlDisplayOptions.html Type: schema.TypeList, Optional: true, @@ -198,9 +198,9 @@ func sliderControlDisplayOptionsSchema() *schema.Schema { }, }, } -} +}) -func dateTimePickerControlDisplayOptionsSchema() *schema.Schema { +var dateTimePickerControlDisplayOptionsSchema = sync.OnceValue(func() *schema.Schema { return &schema.Schema{ // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_DateTimePickerControlDisplayOptions.html Type: schema.TypeList, Optional: true, @@ -208,14 +208,14 @@ func dateTimePickerControlDisplayOptionsSchema() *schema.Schema { MaxItems: 1, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "date_time_format": stringSchema(false, validation.StringLenBetween(1, 128)), + "date_time_format": stringLenBetweenSchema(attrOptional, 1, 128), "title_options": labelOptionsSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_LabelOptions.html }, }, } -} +}) -func listControlDisplayOptionsSchema() *schema.Schema { +var listControlDisplayOptionsSchema = sync.OnceValue(func() *schema.Schema { return &schema.Schema{ // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_ListControlDisplayOptions.html Type: schema.TypeList, Optional: true, @@ -230,7 +230,7 @@ func listControlDisplayOptionsSchema() *schema.Schema { MaxItems: 1, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "visibility": stringSchema(false, enum.Validate[awstypes.Visibility]()), + "visibility": stringEnumSchema[awstypes.Visibility](attrOptional), }, }, }, @@ -239,9 +239,9 @@ func listControlDisplayOptionsSchema() *schema.Schema { }, }, } -} +}) -func cascadingControlConfigurationSchema() *schema.Schema { +var cascadingControlConfigurationSchema = sync.OnceValue(func() *schema.Schema { return &schema.Schema{ // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_CascadingControlConfiguration.html Type: schema.TypeList, Optional: true, @@ -267,9 +267,9 @@ func cascadingControlConfigurationSchema() *schema.Schema { }, }, } -} +}) -func selectAllOptionsSchema() *schema.Schema { +var selectAllOptionsSchema = sync.OnceValue(func() *schema.Schema { return &schema.Schema{ // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_ListControlSelectAllOptions.html Type: schema.TypeList, Optional: true, @@ -277,13 +277,13 @@ func selectAllOptionsSchema() *schema.Schema { MaxItems: 1, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "visibility": stringSchema(false, enum.Validate[awstypes.Visibility]()), + "visibility": stringEnumSchema[awstypes.Visibility](attrOptional), }, }, } -} +}) -func dropDownControlDisplayOptionsSchema() *schema.Schema { +var dropDownControlDisplayOptionsSchema = sync.OnceValue(func() *schema.Schema { return &schema.Schema{ // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_DropDownControlDisplayOptions.html Type: schema.TypeList, Optional: true, @@ -296,9 +296,9 @@ func dropDownControlDisplayOptionsSchema() *schema.Schema { }, }, } -} +}) -func placeholderOptionsSchema() *schema.Schema { +var placeholderOptionsSchema = sync.OnceValue(func() *schema.Schema { return &schema.Schema{ // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_TextControlPlaceholderOptions.html Type: schema.TypeList, Optional: true, @@ -306,11 +306,11 @@ func placeholderOptionsSchema() *schema.Schema { MaxItems: 1, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "visibility": stringSchema(false, enum.Validate[awstypes.Visibility]()), + "visibility": stringEnumSchema[awstypes.Visibility](attrOptional), }, }, } -} +}) func expandFilterControl(tfMap map[string]interface{}) *awstypes.FilterControl { if tfMap == nil { diff --git a/internal/service/quicksight/schema/template_filter.go b/internal/service/quicksight/schema/template_filter.go index 24917a78d581..db0e87ffc178 100644 --- a/internal/service/quicksight/schema/template_filter.go +++ b/internal/service/quicksight/schema/template_filter.go @@ -4,6 +4,7 @@ package schema import ( + "sync" "time" "github.com/YakDriver/regexache" @@ -11,13 +12,12 @@ import ( awstypes "github.com/aws/aws-sdk-go-v2/service/quicksight/types" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" - "github.com/hashicorp/terraform-provider-aws/internal/enum" "github.com/hashicorp/terraform-provider-aws/internal/flex" "github.com/hashicorp/terraform-provider-aws/internal/verify" "github.com/hashicorp/terraform-provider-aws/names" ) -func filtersSchema() *schema.Schema { +var filtersSchema = sync.OnceValue(func() *schema.Schema { return &schema.Schema{ Type: schema.TypeList, MinItems: 1, @@ -35,7 +35,7 @@ func filtersSchema() *schema.Schema { }, }, } -} +}) func categoryFilterSchema() *schema.Schema { return &schema.Schema{ // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_CategoryFilter.html @@ -60,13 +60,9 @@ func categoryFilterSchema() *schema.Schema { MaxItems: 1, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "match_operator": stringSchema(true, enum.Validate[awstypes.CategoryFilterMatchOperator]()), - "null_option": stringSchema(true, enum.Validate[awstypes.FilterNullOption]()), - "category_value": { - Type: schema.TypeString, - Optional: true, - ValidateFunc: validation.StringLenBetween(1, 512), - }, + "match_operator": stringEnumSchema[awstypes.CategoryFilterMatchOperator](attrRequired), + "null_option": stringEnumSchema[awstypes.FilterNullOption](attrRequired), + "category_value": stringLenBetweenSchema(attrOptional, 1, 512), "parameter_name": { Type: schema.TypeString, Optional: true, @@ -75,7 +71,7 @@ func categoryFilterSchema() *schema.Schema { validation.StringMatch(regexache.MustCompile(`^[0-9A-Za-z]+`), ""), ), }, - "select_all_options": stringSchema(false, enum.Validate[awstypes.CategoryFilterSelectAllOptions]()), + "select_all_options": stringEnumSchema[awstypes.CategoryFilterSelectAllOptions](attrOptional), }, }, }, @@ -86,8 +82,8 @@ func categoryFilterSchema() *schema.Schema { MaxItems: 1, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "match_operator": stringSchema(true, enum.Validate[awstypes.CategoryFilterMatchOperator]()), - "null_option": stringSchema(true, enum.Validate[awstypes.FilterNullOption]()), + "match_operator": stringEnumSchema[awstypes.CategoryFilterMatchOperator](attrRequired), + "null_option": stringEnumSchema[awstypes.FilterNullOption](attrRequired), "category_values": { Type: schema.TypeList, Optional: true, @@ -98,7 +94,7 @@ func categoryFilterSchema() *schema.Schema { ValidateFunc: validation.StringLenBetween(1, 512), }, }, - "select_all_options": stringSchema(false, enum.Validate[awstypes.CategoryFilterSelectAllOptions]()), + "select_all_options": stringEnumSchema[awstypes.CategoryFilterSelectAllOptions](attrOptional), }, }, }, @@ -109,7 +105,7 @@ func categoryFilterSchema() *schema.Schema { MaxItems: 1, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "match_operator": stringSchema(true, enum.Validate[awstypes.CategoryFilterMatchOperator]()), + "match_operator": stringEnumSchema[awstypes.CategoryFilterMatchOperator](attrRequired), "category_values": { Type: schema.TypeList, Optional: true, @@ -120,7 +116,7 @@ func categoryFilterSchema() *schema.Schema { ValidateFunc: validation.StringLenBetween(1, 512), }, }, - "select_all_options": stringSchema(false, enum.Validate[awstypes.CategoryFilterSelectAllOptions]()), + "select_all_options": stringEnumSchema[awstypes.CategoryFilterSelectAllOptions](attrOptional), }, }, }, @@ -143,11 +139,11 @@ func numericEqualityFilterSchema() *schema.Schema { Schema: map[string]*schema.Schema{ "column": columnSchema(true), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_ColumnIdentifier.html "filter_id": idSchema(), - "match_operator": stringSchema(true, enum.Validate[awstypes.CategoryFilterMatchOperator]()), - "null_option": stringSchema(true, enum.Validate[awstypes.FilterNullOption]()), + "match_operator": stringEnumSchema[awstypes.CategoryFilterMatchOperator](attrRequired), + "null_option": stringEnumSchema[awstypes.FilterNullOption](attrRequired), "aggregation_function": aggregationFunctionSchema(false), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_AggregationFunction.html "parameter_name": parameterNameSchema(false), - "select_all_options": stringSchema(false, enum.Validate[awstypes.NumericFilterSelectAllOptions]()), + "select_all_options": stringEnumSchema[awstypes.NumericFilterSelectAllOptions](attrOptional), names.AttrValue: { Type: schema.TypeFloat, Optional: true, @@ -167,7 +163,7 @@ func numericRangeFilterSchema() *schema.Schema { Schema: map[string]*schema.Schema{ "column": columnSchema(true), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_ColumnIdentifier.html "filter_id": idSchema(), - "null_option": stringSchema(true, enum.Validate[awstypes.FilterNullOption]()), + "null_option": stringEnumSchema[awstypes.FilterNullOption](attrRequired), "aggregation_function": aggregationFunctionSchema(false), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_AggregationFunction.html "include_maximum": { Type: schema.TypeBool, @@ -179,7 +175,7 @@ func numericRangeFilterSchema() *schema.Schema { }, "range_maximum": numericRangeFilterValueSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_NumericRangeFilterValue.html "range_minimum": numericRangeFilterValueSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_NumericRangeFilterValue.html - "select_all_options": stringSchema(false, enum.Validate[awstypes.NumericFilterSelectAllOptions]()), + "select_all_options": stringEnumSchema[awstypes.NumericFilterSelectAllOptions](attrOptional), }, }, } @@ -200,18 +196,18 @@ func relativeDatesFilterSchema() *schema.Schema { MaxItems: 1, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "anchor_option": stringSchema(false, enum.Validate[awstypes.AnchorOption]()), + "anchor_option": stringEnumSchema[awstypes.AnchorOption](attrOptional), "parameter_name": parameterNameSchema(false), }, }, }, "column": columnSchema(true), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_ColumnIdentifier.html "filter_id": idSchema(), - "null_option": stringSchema(true, enum.Validate[awstypes.FilterNullOption]()), - "relative_date_type": stringSchema(true, enum.Validate[awstypes.RelativeDateType]()), - "time_granularity": stringSchema(true, enum.Validate[awstypes.TimeGranularity]()), + "null_option": stringEnumSchema[awstypes.FilterNullOption](attrRequired), + "relative_date_type": stringEnumSchema[awstypes.RelativeDateType](attrRequired), + "time_granularity": stringEnumSchema[awstypes.TimeGranularity](attrRequired), "exclude_period_configuration": excludePeriodConfigurationSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_ExcludePeriodConfiguration.html - "minimum_granularity": stringSchema(true, enum.Validate[awstypes.TimeGranularity]()), + "minimum_granularity": stringEnumSchema[awstypes.TimeGranularity](attrRequired), "parameter_name": parameterNameSchema(false), "relative_date_value": { Type: schema.TypeInt, @@ -232,7 +228,7 @@ func timeEqualityFilterSchema() *schema.Schema { Schema: map[string]*schema.Schema{ "column": columnSchema(true), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_ColumnIdentifier.html "filter_id": idSchema(), - "time_granularity": stringSchema(true, enum.Validate[awstypes.TimeGranularity]()), + "time_granularity": stringEnumSchema[awstypes.TimeGranularity](attrRequired), "parameter_name": parameterNameSchema(false), names.AttrValue: { Type: schema.TypeString, @@ -254,7 +250,7 @@ func timeRangeFilterSchema() *schema.Schema { Schema: map[string]*schema.Schema{ "column": columnSchema(true), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_ColumnIdentifier.html "filter_id": idSchema(), - "null_option": stringSchema(true, enum.Validate[awstypes.FilterNullOption]()), + "null_option": stringEnumSchema[awstypes.FilterNullOption](attrRequired), "exclude_period_configuration": excludePeriodConfigurationSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_ExcludePeriodConfiguration.html "include_maximum": { Type: schema.TypeBool, @@ -266,7 +262,7 @@ func timeRangeFilterSchema() *schema.Schema { }, "range_maximum_value": timeRangeFilterValueSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_TimeRangeFilterValue.html "range_minimum_value": timeRangeFilterValueSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_TimeRangeFilterValue.html - "time_granularity": stringSchema(true, enum.Validate[awstypes.TimeGranularity]()), + "time_granularity": stringEnumSchema[awstypes.TimeGranularity](attrRequired), }, }, } @@ -289,7 +285,7 @@ func topBottomFilterSchema() *schema.Schema { Schema: map[string]*schema.Schema{ "aggregation_function": aggregationFunctionSchema(true), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_AggregationFunction.html "column": columnSchema(true), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_ColumnIdentifier.html - "sort_direction": stringSchema(true, enum.Validate[awstypes.SortDirection]()), + "sort_direction": stringEnumSchema[awstypes.SortDirection](attrRequired), }, }, }, @@ -300,13 +296,13 @@ func topBottomFilterSchema() *schema.Schema { Optional: true, }, "parameter_name": parameterNameSchema(false), - "time_granularity": stringSchema(true, enum.Validate[awstypes.TimeGranularity]()), + "time_granularity": stringEnumSchema[awstypes.TimeGranularity](attrRequired), }, }, } } -func excludePeriodConfigurationSchema() *schema.Schema { +var excludePeriodConfigurationSchema = sync.OnceValue(func() *schema.Schema { return &schema.Schema{ // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_ExcludePeriodConfiguration.html Type: schema.TypeList, Optional: true, @@ -318,14 +314,14 @@ func excludePeriodConfigurationSchema() *schema.Schema { Type: schema.TypeInt, Required: true, }, - "granularity": stringSchema(true, enum.Validate[awstypes.TimeGranularity]()), - names.AttrStatus: stringSchema(false, enum.Validate[awstypes.Status]()), + "granularity": stringEnumSchema[awstypes.TimeGranularity](attrRequired), + names.AttrStatus: stringEnumSchema[awstypes.Status](attrOptional), }, }, } -} +}) -func numericRangeFilterValueSchema() *schema.Schema { +var numericRangeFilterValueSchema = sync.OnceValue(func() *schema.Schema { return &schema.Schema{ // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_NumericRangeFilterValue.html Type: schema.TypeList, Optional: true, @@ -348,9 +344,9 @@ func numericRangeFilterValueSchema() *schema.Schema { }, }, } -} +}) -func timeRangeFilterValueSchema() *schema.Schema { +var timeRangeFilterValueSchema = sync.OnceValue(func() *schema.Schema { return &schema.Schema{ // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_TimeRangeFilterValue.html Type: schema.TypeList, Optional: true, @@ -367,13 +363,13 @@ func timeRangeFilterValueSchema() *schema.Schema { ), }, "rolling_date": rollingDateConfigurationSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_RollingDateConfiguration.html, - "static_value": stringSchema(false, verify.ValidUTCTimestamp), + "static_value": utcTimestampStringSchema(attrOptional), }, }, } -} +}) -func drillDownFilterSchema() *schema.Schema { +var drillDownFilterSchema = sync.OnceValue(func() *schema.Schema { return &schema.Schema{ // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_DrillDownFilter.html Type: schema.TypeList, Optional: true, @@ -425,18 +421,18 @@ func drillDownFilterSchema() *schema.Schema { Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ "column": columnSchema(true), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_ColumnIdentifier.html - "range_maximum": stringSchema(true, verify.ValidUTCTimestamp), - "range_minimum": stringSchema(true, verify.ValidUTCTimestamp), - "time_granularity": stringSchema(true, enum.Validate[awstypes.TimeGranularity]()), + "range_maximum": utcTimestampStringSchema(attrRequired), + "range_minimum": utcTimestampStringSchema(attrRequired), + "time_granularity": stringEnumSchema[awstypes.TimeGranularity](attrRequired), }, }, }, }, }, } -} +}) -func filterSelectableValuesSchema() *schema.Schema { +var filterSelectableValuesSchema = sync.OnceValue(func() *schema.Schema { return &schema.Schema{ // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_FilterSelectableValues.html Type: schema.TypeList, Optional: true, @@ -456,9 +452,9 @@ func filterSelectableValuesSchema() *schema.Schema { }, }, } -} +}) -func filterScopeConfigurationSchema() *schema.Schema { +var filterScopeConfigurationSchema = sync.OnceValue(func() *schema.Schema { return &schema.Schema{ // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_FilterScopeConfiguration.html Type: schema.TypeList, MinItems: 1, @@ -480,7 +476,7 @@ func filterScopeConfigurationSchema() *schema.Schema { Optional: true, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - names.AttrScope: stringSchema(true, enum.Validate[awstypes.FilterVisualScope]()), + names.AttrScope: stringEnumSchema[awstypes.FilterVisualScope](attrRequired), "sheet_id": idSchema(), "visual_ids": { Type: schema.TypeSet, @@ -498,7 +494,7 @@ func filterScopeConfigurationSchema() *schema.Schema { }, }, } -} +}) func expandFilters(tfList []interface{}) []awstypes.Filter { if len(tfList) == 0 { diff --git a/internal/service/quicksight/schema/template_format.go b/internal/service/quicksight/schema/template_format.go index 6bc1c002a57e..010cfb66fd8a 100644 --- a/internal/service/quicksight/schema/template_format.go +++ b/internal/service/quicksight/schema/template_format.go @@ -4,16 +4,15 @@ package schema import ( - "github.com/YakDriver/regexache" + "sync" + "github.com/aws/aws-sdk-go-v2/aws" awstypes "github.com/aws/aws-sdk-go-v2/service/quicksight/types" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" - "github.com/hashicorp/terraform-provider-aws/internal/enum" "github.com/hashicorp/terraform-provider-aws/names" ) -func numericFormatConfigurationSchema() *schema.Schema { +var numericFormatConfigurationSchema = sync.OnceValue(func() *schema.Schema { return &schema.Schema{ Type: schema.TypeList, MinItems: 1, @@ -31,11 +30,11 @@ func numericFormatConfigurationSchema() *schema.Schema { "decimal_places_configuration": decimalPlacesConfigurationSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_DecimalPlacesConfiguration.html "negative_value_configuration": negativeValueConfigurationSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_NegativeValueConfiguration.html "null_value_format_configuration": nullValueConfigurationSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_NullValueFormatConfiguration.html - "number_scale": stringSchema(false, enum.Validate[awstypes.NumberScale]()), - names.AttrPrefix: stringSchema(false, validation.StringLenBetween(1, 128)), + "number_scale": stringEnumSchema[awstypes.NumberScale](attrOptional), + names.AttrPrefix: stringLenBetweenSchema(attrOptional, 1, 128), "separator_configuration": separatorConfigurationSchema(), - "suffix": stringSchema(false, validation.StringLenBetween(1, 128)), - "symbol": stringSchema(false, validation.StringMatch(regexache.MustCompile(`[A-Z]{3}`), "must be a 3 character currency symbol")), + "suffix": stringLenBetweenSchema(attrOptional, 1, 128), + "symbol": stringMatchSchema(attrOptional, `[A-Z]{3}`, "must be a 3 character currency symbol"), }, }, }, @@ -44,9 +43,9 @@ func numericFormatConfigurationSchema() *schema.Schema { }, }, } -} +}) -func dateTimeFormatConfigurationSchema() *schema.Schema { +var dateTimeFormatConfigurationSchema = sync.OnceValue(func() *schema.Schema { return &schema.Schema{ Type: schema.TypeList, MinItems: 1, @@ -54,15 +53,15 @@ func dateTimeFormatConfigurationSchema() *schema.Schema { Optional: true, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "date_time_format": stringSchema(false, validation.StringLenBetween(1, 128)), + "date_time_format": stringLenBetweenSchema(attrOptional, 1, 128), "null_value_format_configuration": nullValueConfigurationSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_NullValueFormatConfiguration.html "numeric_format_configuration": numericFormatConfigurationSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_NumericFormatConfiguration.html }, }, } -} +}) -func numberDisplayFormatConfigurationSchema() *schema.Schema { +var numberDisplayFormatConfigurationSchema = sync.OnceValue(func() *schema.Schema { return &schema.Schema{ // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_NumberDisplayFormatConfiguration.html Type: schema.TypeList, MinItems: 1, @@ -73,16 +72,16 @@ func numberDisplayFormatConfigurationSchema() *schema.Schema { "decimal_places_configuration": decimalPlacesConfigurationSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_DecimalPlacesConfiguration.html "negative_value_configuration": negativeValueConfigurationSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_NegativeValueConfiguration.html "null_value_format_configuration": nullValueConfigurationSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_NullValueFormatConfiguration.html - "number_scale": stringSchema(false, enum.Validate[awstypes.NumberScale]()), - names.AttrPrefix: stringSchema(false, validation.StringLenBetween(1, 128)), + "number_scale": stringEnumSchema[awstypes.NumberScale](attrOptional), + names.AttrPrefix: stringLenBetweenSchema(attrOptional, 1, 128), "separator_configuration": separatorConfigurationSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_NumericSeparatorConfiguration.html - "suffix": stringSchema(false, validation.StringLenBetween(1, 128)), + "suffix": stringLenBetweenSchema(attrOptional, 1, 128), }, }, } -} +}) -func percentageDisplayFormatConfigurationSchema() *schema.Schema { +var percentageDisplayFormatConfigurationSchema = sync.OnceValue(func() *schema.Schema { return &schema.Schema{ // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_PercentageDisplayFormatConfiguration.html Type: schema.TypeList, MinItems: 1, @@ -93,15 +92,15 @@ func percentageDisplayFormatConfigurationSchema() *schema.Schema { "decimal_places_configuration": decimalPlacesConfigurationSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_DecimalPlacesConfiguration.html "negative_value_configuration": negativeValueConfigurationSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_NegativeValueConfiguration.html "null_value_format_configuration": nullValueConfigurationSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_NullValueFormatConfiguration.html - names.AttrPrefix: stringSchema(false, validation.StringLenBetween(1, 128)), + names.AttrPrefix: stringLenBetweenSchema(attrOptional, 1, 128), "separator_configuration": separatorConfigurationSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_NumericSeparatorConfiguration.html - "suffix": stringSchema(false, validation.StringLenBetween(1, 128)), + "suffix": stringLenBetweenSchema(attrOptional, 1, 128), }, }, } -} +}) -func numberFormatConfigurationSchema() *schema.Schema { +var numberFormatConfigurationSchema = sync.OnceValue(func() *schema.Schema { return &schema.Schema{ // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_NumberFormatConfiguration.html Type: schema.TypeList, MinItems: 1, @@ -113,9 +112,9 @@ func numberFormatConfigurationSchema() *schema.Schema { }, }, } -} +}) -func stringFormatConfigurationSchema() *schema.Schema { +var stringFormatConfigurationSchema = sync.OnceValue(func() *schema.Schema { return &schema.Schema{ Type: schema.TypeList, MinItems: 1, @@ -128,9 +127,9 @@ func stringFormatConfigurationSchema() *schema.Schema { }, }, } -} +}) -func decimalPlacesConfigurationSchema() *schema.Schema { +var decimalPlacesConfigurationSchema = sync.OnceValue(func() *schema.Schema { return &schema.Schema{ // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_DecimalPlacesConfiguration.html Type: schema.TypeList, MinItems: 1, @@ -138,17 +137,13 @@ func decimalPlacesConfigurationSchema() *schema.Schema { Optional: true, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "decimal_places": { - Type: schema.TypeInt, - Required: true, - ValidateFunc: validation.IntBetween(0, 20), - }, + "decimal_places": intBetweenSchema(attrRequired, 0, 20), }, }, } -} +}) -func negativeValueConfigurationSchema() *schema.Schema { +var negativeValueConfigurationSchema = sync.OnceValue(func() *schema.Schema { return &schema.Schema{ Type: schema.TypeList, MinItems: 1, @@ -156,13 +151,13 @@ func negativeValueConfigurationSchema() *schema.Schema { Optional: true, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "display_mode": stringSchema(true, enum.Validate[awstypes.NegativeValueDisplayMode]()), + "display_mode": stringEnumSchema[awstypes.NegativeValueDisplayMode](attrRequired), }, }, } -} +}) -func nullValueConfigurationSchema() *schema.Schema { +var nullValueConfigurationSchema = sync.OnceValue(func() *schema.Schema { return &schema.Schema{ Type: schema.TypeList, MinItems: 1, @@ -170,13 +165,13 @@ func nullValueConfigurationSchema() *schema.Schema { Optional: true, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "null_string": stringSchema(true, validation.StringLenBetween(1, 128)), + "null_string": stringLenBetweenSchema(attrRequired, 1, 128), }, }, } -} +}) -func separatorConfigurationSchema() *schema.Schema { +var separatorConfigurationSchema = sync.OnceValue(func() *schema.Schema { return &schema.Schema{ Type: schema.TypeList, MinItems: 1, @@ -184,7 +179,7 @@ func separatorConfigurationSchema() *schema.Schema { Optional: true, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "decimal_separator": stringSchema(false, enum.Validate[awstypes.NumericSeparatorSymbol]()), + "decimal_separator": stringEnumSchema[awstypes.NumericSeparatorSymbol](attrOptional), "thousands_separator": { // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_ThousandSeparatorOptions.html Type: schema.TypeList, MinItems: 1, @@ -192,17 +187,17 @@ func separatorConfigurationSchema() *schema.Schema { Optional: true, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "symbol": stringSchema(false, enum.Validate[awstypes.NumericSeparatorSymbol]()), - "visibility": stringSchema(false, enum.Validate[awstypes.Visibility]()), + "symbol": stringEnumSchema[awstypes.NumericSeparatorSymbol](attrOptional), + "visibility": stringEnumSchema[awstypes.Visibility](attrOptional), }, }, }, }, }, } -} +}) -func labelOptionsSchema() *schema.Schema { +var labelOptionsSchema = sync.OnceValue(func() *schema.Schema { return &schema.Schema{ // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_LabelOptions.html Type: schema.TypeList, MinItems: 1, @@ -215,13 +210,13 @@ func labelOptionsSchema() *schema.Schema { Optional: true, }, "font_configuration": fontConfigurationSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_FontConfiguration.html - "visibility": stringSchema(false, enum.Validate[awstypes.Visibility]()), + "visibility": stringEnumSchema[awstypes.Visibility](attrOptional), }, }, } -} +}) -func fontConfigurationSchema() *schema.Schema { +var fontConfigurationSchema = sync.OnceValue(func() *schema.Schema { return &schema.Schema{ // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_FontConfiguration.html Type: schema.TypeList, MinItems: 1, @@ -229,35 +224,35 @@ func fontConfigurationSchema() *schema.Schema { Optional: true, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "font_color": stringSchema(false, validation.StringMatch(regexache.MustCompile(`^#[0-9A-F]{6}$`), "")), - "font_decoration": stringSchema(false, enum.Validate[awstypes.FontDecoration]()), + "font_color": hexColorSchema(attrOptional), + "font_decoration": stringEnumSchema[awstypes.FontDecoration](attrOptional), "font_size": { // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_FontSize.html Type: schema.TypeList, MaxItems: 1, Optional: true, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "relative": stringSchema(false, enum.Validate[awstypes.RelativeFontSize]()), + "relative": stringEnumSchema[awstypes.RelativeFontSize](attrOptional), }, }, }, - "font_style": stringSchema(false, enum.Validate[awstypes.FontStyle]()), + "font_style": stringEnumSchema[awstypes.FontStyle](attrOptional), "font_weight": { // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_FontWeight.html Type: schema.TypeList, MaxItems: 1, Optional: true, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - names.AttrName: stringSchema(false, enum.Validate[awstypes.FontWeightName]()), + names.AttrName: stringEnumSchema[awstypes.FontWeightName](attrOptional), }, }, }, }, }, } -} +}) -func formatConfigurationSchema() *schema.Schema { +var formatConfigurationSchema = sync.OnceValue(func() *schema.Schema { return &schema.Schema{ // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_FormatConfiguration.html Type: schema.TypeList, MinItems: 1, @@ -271,7 +266,7 @@ func formatConfigurationSchema() *schema.Schema { }, }, } -} +}) func expandFormatConfiguration(tfList []interface{}) *awstypes.FormatConfiguration { if len(tfList) == 0 || tfList[0] == nil { diff --git a/internal/service/quicksight/schema/template_parameter.go b/internal/service/quicksight/schema/template_parameter.go index f6756580f37b..c93152d402ce 100644 --- a/internal/service/quicksight/schema/template_parameter.go +++ b/internal/service/quicksight/schema/template_parameter.go @@ -4,6 +4,7 @@ package schema import ( + "sync" "time" "github.com/YakDriver/regexache" @@ -11,13 +12,12 @@ import ( awstypes "github.com/aws/aws-sdk-go-v2/service/quicksight/types" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" - "github.com/hashicorp/terraform-provider-aws/internal/enum" "github.com/hashicorp/terraform-provider-aws/internal/flex" "github.com/hashicorp/terraform-provider-aws/internal/verify" "github.com/hashicorp/terraform-provider-aws/names" ) -func dateTimeParameterDeclarationSchema() *schema.Schema { +var dateTimeParameterDeclarationSchema = sync.OnceValue(func() *schema.Schema { return &schema.Schema{ // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_DateTimeParameterDeclaration.html Type: schema.TypeList, MinItems: 1, @@ -55,7 +55,7 @@ func dateTimeParameterDeclarationSchema() *schema.Schema { }, }, }, - "time_granularity": stringSchema(false, enum.Validate[awstypes.TimeGranularity]()), + "time_granularity": stringEnumSchema[awstypes.TimeGranularity](attrOptional), "values_when_unset": { // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_DateTimeValueWhenUnsetConfiguration.html Type: schema.TypeList, MinItems: 1, @@ -68,16 +68,16 @@ func dateTimeParameterDeclarationSchema() *schema.Schema { Optional: true, ValidateFunc: verify.ValidUTCTimestamp, }, - "value_when_unset_option": stringSchema(false, enum.Validate[awstypes.ValueWhenUnsetOption]()), + "value_when_unset_option": stringEnumSchema[awstypes.ValueWhenUnsetOption](attrOptional), }, }, }, }, }, } -} +}) -func decimalParameterDeclarationSchema() *schema.Schema { +var decimalParameterDeclarationSchema = sync.OnceValue(func() *schema.Schema { return &schema.Schema{ // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_DecimalParameterDeclaration.html Type: schema.TypeList, MinItems: 1, @@ -93,7 +93,7 @@ func decimalParameterDeclarationSchema() *schema.Schema { validation.StringMatch(regexache.MustCompile(`^[0-9A-Za-z]+$`), ""), ), }, - "parameter_value_type": stringSchema(true, enum.Validate[awstypes.ParameterValueType]()), + "parameter_value_type": stringEnumSchema[awstypes.ParameterValueType](attrRequired), "default_values": { // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_DecimalDefaultValues.html Type: schema.TypeList, MinItems: 1, @@ -125,16 +125,16 @@ func decimalParameterDeclarationSchema() *schema.Schema { Type: schema.TypeFloat, Optional: true, }, - "value_when_unset_option": stringSchema(false, enum.Validate[awstypes.ValueWhenUnsetOption]()), + "value_when_unset_option": stringEnumSchema[awstypes.ValueWhenUnsetOption](attrOptional), }, }, }, }, }, } -} +}) -func integerParameterDeclarationSchema() *schema.Schema { +var integerParameterDeclarationSchema = sync.OnceValue(func() *schema.Schema { return &schema.Schema{ // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_IntegerParameterDeclaration.html Type: schema.TypeList, MinItems: 1, @@ -150,7 +150,7 @@ func integerParameterDeclarationSchema() *schema.Schema { validation.StringMatch(regexache.MustCompile(`^[0-9A-Za-z]+$`), ""), ), }, - "parameter_value_type": stringSchema(true, enum.Validate[awstypes.ParameterValueType]()), + "parameter_value_type": stringEnumSchema[awstypes.ParameterValueType](attrRequired), "default_values": { // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_IntegerDefaultValues.html Type: schema.TypeList, MinItems: 1, @@ -182,16 +182,16 @@ func integerParameterDeclarationSchema() *schema.Schema { Type: schema.TypeInt, Optional: true, }, - "value_when_unset_option": stringSchema(false, enum.Validate[awstypes.ValueWhenUnsetOption]()), + "value_when_unset_option": stringEnumSchema[awstypes.ValueWhenUnsetOption](attrOptional), }, }, }, }, }, } -} +}) -func stringParameterDeclarationSchema() *schema.Schema { +var stringParameterDeclarationSchema = sync.OnceValue(func() *schema.Schema { return &schema.Schema{ // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_StringParameterDeclaration.html Type: schema.TypeList, MinItems: 1, @@ -207,7 +207,7 @@ func stringParameterDeclarationSchema() *schema.Schema { validation.StringMatch(regexache.MustCompile(`^[0-9A-Za-z]+$`), ""), ), }, - "parameter_value_type": stringSchema(true, enum.Validate[awstypes.ParameterValueType]()), + "parameter_value_type": stringEnumSchema[awstypes.ParameterValueType](attrRequired), "default_values": { // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_StringDefaultValues.html Type: schema.TypeList, MinItems: 1, @@ -239,16 +239,16 @@ func stringParameterDeclarationSchema() *schema.Schema { Type: schema.TypeString, Optional: true, }, - "value_when_unset_option": stringSchema(false, enum.Validate[awstypes.ValueWhenUnsetOption]()), + "value_when_unset_option": stringEnumSchema[awstypes.ValueWhenUnsetOption](attrOptional), }, }, }, }, }, } -} +}) -func dynamicValueSchema() *schema.Schema { +var dynamicValueSchema = sync.OnceValue(func() *schema.Schema { return &schema.Schema{ // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_DynamicDefaultValue.html Type: schema.TypeList, MinItems: 1, @@ -262,9 +262,9 @@ func dynamicValueSchema() *schema.Schema { }, }, } -} +}) -func parameterControlsSchema() *schema.Schema { +var parameterControlsSchema = sync.OnceValue(func() *schema.Schema { return &schema.Schema{ // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_ParameterControl.html Type: schema.TypeList, Optional: true, @@ -281,7 +281,7 @@ func parameterControlsSchema() *schema.Schema { Schema: map[string]*schema.Schema{ "parameter_control_id": idSchema(), "source_parameter_name": parameterNameSchema(true), - "title": stringSchema(true, validation.StringLenBetween(1, 2048)), + "title": stringLenBetweenSchema(attrRequired, 1, 2048), "display_options": dateTimePickerControlDisplayOptionsSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_DateTimePickerControlDisplayOptions.html }, }, @@ -295,11 +295,11 @@ func parameterControlsSchema() *schema.Schema { Schema: map[string]*schema.Schema{ "parameter_control_id": idSchema(), "source_parameter_name": parameterNameSchema(true), - "title": stringSchema(true, validation.StringLenBetween(1, 2048)), + "title": stringLenBetweenSchema(attrRequired, 1, 2048), "cascading_control_configuration": cascadingControlConfigurationSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_CascadingControlConfiguration.html "display_options": dropDownControlDisplayOptionsSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_DropDownControlDisplayOptions.html "selectable_values": parameterSelectableValuesSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_ParameterSelectableValues.html - names.AttrType: stringSchema(false, enum.Validate[awstypes.SheetControlListType]()), + names.AttrType: stringEnumSchema[awstypes.SheetControlListType](attrOptional), }, }, }, @@ -312,11 +312,11 @@ func parameterControlsSchema() *schema.Schema { Schema: map[string]*schema.Schema{ "parameter_control_id": idSchema(), "source_parameter_name": parameterNameSchema(true), - "title": stringSchema(true, validation.StringLenBetween(1, 2048)), + "title": stringLenBetweenSchema(attrRequired, 1, 2048), "cascading_control_configuration": cascadingControlConfigurationSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_CascadingControlConfiguration.html "display_options": listControlDisplayOptionsSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_ListControlDisplayOptions.html "selectable_values": parameterSelectableValuesSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_ParameterSelectableValues.html - names.AttrType: stringSchema(false, enum.Validate[awstypes.SheetControlListType]()), + names.AttrType: stringEnumSchema[awstypes.SheetControlListType](attrOptional), }, }, }, @@ -329,7 +329,7 @@ func parameterControlsSchema() *schema.Schema { Schema: map[string]*schema.Schema{ "parameter_control_id": idSchema(), "source_parameter_name": parameterNameSchema(true), - "title": stringSchema(true, validation.StringLenBetween(1, 2048)), + "title": stringLenBetweenSchema(attrRequired, 1, 2048), "display_options": sliderControlDisplayOptionsSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_SliderControlDisplayOptions.html "maximum_value": { Type: schema.TypeFloat, @@ -355,9 +355,9 @@ func parameterControlsSchema() *schema.Schema { Schema: map[string]*schema.Schema{ "parameter_control_id": idSchema(), "source_parameter_name": parameterNameSchema(true), - "title": stringSchema(true, validation.StringLenBetween(1, 2048)), + "title": stringLenBetweenSchema(attrRequired, 1, 2048), "display_options": textAreaControlDisplayOptionsSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_TextAreaControlDisplayOptions.html - "delimiter": stringSchema(false, validation.StringLenBetween(1, 2048)), + "delimiter": stringLenBetweenSchema(attrOptional, 1, 2048), }, }, }, @@ -370,7 +370,7 @@ func parameterControlsSchema() *schema.Schema { Schema: map[string]*schema.Schema{ "parameter_control_id": idSchema(), "source_parameter_name": parameterNameSchema(true), - "title": stringSchema(true, validation.StringLenBetween(1, 2048)), + "title": stringLenBetweenSchema(attrRequired, 1, 2048), "display_options": textFieldControlDisplayOptionsSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_TextFieldControlDisplayOptions.html }, }, @@ -378,9 +378,9 @@ func parameterControlsSchema() *schema.Schema { }, }, } -} +}) -func parameterSelectableValuesSchema() *schema.Schema { +var parameterSelectableValuesSchema = sync.OnceValue(func() *schema.Schema { return &schema.Schema{ // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_ParameterSelectableValues.html Type: schema.TypeList, Optional: true, @@ -401,7 +401,7 @@ func parameterSelectableValuesSchema() *schema.Schema { }, }, } -} +}) func parameterNameSchema(required bool) *schema.Schema { return &schema.Schema{ diff --git a/internal/service/quicksight/schema/template_sheet.go b/internal/service/quicksight/schema/template_sheet.go index 6491c4c3a1df..af44cb52e658 100644 --- a/internal/service/quicksight/schema/template_sheet.go +++ b/internal/service/quicksight/schema/template_sheet.go @@ -4,18 +4,17 @@ package schema import ( - "github.com/YakDriver/regexache" + "sync" + "github.com/aws/aws-sdk-go-v2/aws" awstypes "github.com/aws/aws-sdk-go-v2/service/quicksight/types" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" - "github.com/hashicorp/terraform-provider-aws/internal/enum" "github.com/hashicorp/terraform-provider-aws/internal/flex" "github.com/hashicorp/terraform-provider-aws/internal/sdkv2/types/nullable" "github.com/hashicorp/terraform-provider-aws/names" ) -func analysisDefaultSchema() *schema.Schema { +var analysisDefaultSchema = sync.OnceValue(func() *schema.Schema { return &schema.Schema{ Type: schema.TypeList, MaxItems: 1, @@ -31,14 +30,14 @@ func analysisDefaultSchema() *schema.Schema { Schema: map[string]*schema.Schema{ "interactive_layout_configuration": interactiveLayoutConfigurationSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_DefaultInteractiveLayoutConfiguration.html "paginated_layout_configuration": paginatedLayoutConfigurationSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_DefaultPaginatedLayoutConfiguration.html, - "sheet_content_type": stringSchema(false, enum.Validate[awstypes.SheetContentType]()), + "sheet_content_type": stringEnumSchema[awstypes.SheetContentType](attrOptional), }, }, }, }, }, } -} +}) func interactiveLayoutConfigurationSchema() *schema.Schema { return &schema.Schema{ // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_DefaultInteractiveLayoutConfiguration.html @@ -107,7 +106,7 @@ func interactiveLayoutConfigurationSchema() *schema.Schema { Type: schema.TypeString, Optional: true, }, - "resize_option": stringSchema(true, enum.Validate[awstypes.ResizeOption]()), + "resize_option": stringEnumSchema[awstypes.ResizeOption](attrRequired), }, }, }, @@ -156,7 +155,7 @@ func paginatedLayoutConfigurationSchema() *schema.Schema { } } -func paperCanvasSizeOptionsSchema() *schema.Schema { +var paperCanvasSizeOptionsSchema = sync.OnceValue(func() *schema.Schema { return &schema.Schema{ Type: schema.TypeList, Optional: true, @@ -165,14 +164,14 @@ func paperCanvasSizeOptionsSchema() *schema.Schema { Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ "paper_margin": spacingSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_Spacing.html - "paper_orientation": stringSchema(false, enum.Validate[awstypes.PaperOrientation]()), - "paper_size": stringSchema(false, enum.Validate[awstypes.PaperSize]()), + "paper_orientation": stringEnumSchema[awstypes.PaperOrientation](attrOptional), + "paper_size": stringEnumSchema[awstypes.PaperSize](attrOptional), }, }, } -} +}) -func sheetControlLayoutsSchema() *schema.Schema { +var sheetControlLayoutsSchema = sync.OnceValue(func() *schema.Schema { return &schema.Schema{ // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_SheetControlLayout.html Type: schema.TypeList, MinItems: 0, @@ -194,9 +193,9 @@ func sheetControlLayoutsSchema() *schema.Schema { }, }, } -} +}) -func layoutSchema() *schema.Schema { +var layoutSchema = sync.OnceValue(func() *schema.Schema { return &schema.Schema{ // // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_Layout.html Type: schema.TypeList, Optional: true, @@ -288,7 +287,7 @@ func layoutSchema() *schema.Schema { MaxItems: 1, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - names.AttrStatus: stringSchema(false, enum.Validate[awstypes.Status]()), + names.AttrStatus: stringEnumSchema[awstypes.Status](attrOptional), }, }, }, @@ -322,9 +321,9 @@ func layoutSchema() *schema.Schema { }, }, } -} +}) -func gridLayoutConfigurationSchema() *schema.Schema { +var gridLayoutConfigurationSchema = sync.OnceValue(func() *schema.Schema { return &schema.Schema{ // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_GridLayoutConfiguration.html Type: schema.TypeList, Optional: true, @@ -340,18 +339,10 @@ func gridLayoutConfigurationSchema() *schema.Schema { MaxItems: 430, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "column_span": { - Type: schema.TypeInt, - Required: true, - ValidateFunc: validation.IntBetween(1, 36), - }, + "column_span": intBetweenSchema(attrRequired, 1, 36), "element_id": idSchema(), - "element_type": stringSchema(true, enum.Validate[awstypes.LayoutElementType]()), - "row_span": { - Type: schema.TypeInt, - Required: true, - ValidateFunc: validation.IntBetween(1, 21), - }, + "element_type": stringEnumSchema[awstypes.LayoutElementType](attrRequired), + "row_span": intBetweenSchema(attrRequired, 1, 21), "column_index": { Type: nullable.TypeNullableInt, Optional: true, @@ -383,7 +374,7 @@ func gridLayoutConfigurationSchema() *schema.Schema { Type: schema.TypeString, Optional: true, }, - "resize_option": stringSchema(true, enum.Validate[awstypes.ResizeOption]()), + "resize_option": stringEnumSchema[awstypes.ResizeOption](attrRequired), }, }, }, @@ -393,9 +384,9 @@ func gridLayoutConfigurationSchema() *schema.Schema { }, }, } -} +}) -func headerFooterSectionConfigurationSchema() *schema.Schema { +var headerFooterSectionConfigurationSchema = sync.OnceValue(func() *schema.Schema { return &schema.Schema{ // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_HeaderFooterSectionConfiguration.html Type: schema.TypeList, Required: true, @@ -409,9 +400,9 @@ func headerFooterSectionConfigurationSchema() *schema.Schema { }, }, } -} +}) -func sectionStyleSchema() *schema.Schema { +var sectionStyleSchema = sync.OnceValue(func() *schema.Schema { return &schema.Schema{ // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_SectionStyle.html Type: schema.TypeList, Optional: true, @@ -427,9 +418,9 @@ func sectionStyleSchema() *schema.Schema { }, }, } -} +}) -func freeFormLayoutElementsSchema() *schema.Schema { +var freeFormLayoutElementsSchema = sync.OnceValue(func() *schema.Schema { return &schema.Schema{ // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_FreeFormLayoutElement.html Type: schema.TypeList, Required: true, @@ -438,7 +429,7 @@ func freeFormLayoutElementsSchema() *schema.Schema { Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ "element_id": idSchema(), - "element_type": stringSchema(true, enum.Validate[awstypes.LayoutElementType]()), + "element_type": stringEnumSchema[awstypes.LayoutElementType](attrRequired), "height": { Type: schema.TypeString, Required: true, @@ -462,8 +453,8 @@ func freeFormLayoutElementsSchema() *schema.Schema { MaxItems: 1, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "color": stringSchema(false, validation.StringMatch(regexache.MustCompile(`^#[0-9A-F]{6}(?:[0-9A-F]{2})?$`), "")), - "visibility": stringSchema(false, enum.Validate[awstypes.Visibility]()), + "color": stringMatchSchema(attrOptional, `^#[0-9A-F]{6}(?:[0-9A-F]{2})?$`, ""), + "visibility": stringEnumSchema[awstypes.Visibility](attrOptional), }, }, }, @@ -474,8 +465,8 @@ func freeFormLayoutElementsSchema() *schema.Schema { MaxItems: 1, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "color": stringSchema(false, validation.StringMatch(regexache.MustCompile(`^#[0-9A-F]{6}(?:[0-9A-F]{2})?$`), "")), - "visibility": stringSchema(false, enum.Validate[awstypes.Visibility]()), + "color": stringMatchSchema(attrOptional, `^#[0-9A-F]{6}(?:[0-9A-F]{2})?$`, ""), + "visibility": stringEnumSchema[awstypes.Visibility](attrOptional), }, }, }, @@ -486,7 +477,7 @@ func freeFormLayoutElementsSchema() *schema.Schema { MaxItems: 1, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "visibility": stringSchema(false, enum.Validate[awstypes.Visibility]()), + "visibility": stringEnumSchema[awstypes.Visibility](attrOptional), }, }, }, @@ -504,11 +495,11 @@ func freeFormLayoutElementsSchema() *schema.Schema { MaxItems: 1, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "visibility": stringSchema(false, enum.Validate[awstypes.Visibility]()), + "visibility": stringEnumSchema[awstypes.Visibility](attrOptional), }, }, }, - names.AttrExpression: stringSchema(true, validation.StringLenBetween(1, 4096)), + names.AttrExpression: stringLenBetweenSchema(attrRequired, 1, 4096), }, }, }, @@ -519,18 +510,18 @@ func freeFormLayoutElementsSchema() *schema.Schema { MaxItems: 1, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "color": stringSchema(false, validation.StringMatch(regexache.MustCompile(`^#[0-9A-F]{6}(?:[0-9A-F]{2})?$`), "")), - "visibility": stringSchema(false, enum.Validate[awstypes.Visibility]()), + "color": stringMatchSchema(attrOptional, `^#[0-9A-F]{6}(?:[0-9A-F]{2})?$`, ""), + "visibility": stringEnumSchema[awstypes.Visibility](attrOptional), }, }, }, - "visibility": stringSchema(false, enum.Validate[awstypes.Visibility]()), + "visibility": stringEnumSchema[awstypes.Visibility](attrOptional), }, }, } -} +}) -func sectionLayoutConfigurationSchema() *schema.Schema { +var sectionLayoutConfigurationSchema = sync.OnceValue(func() *schema.Schema { return &schema.Schema{ // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_SectionLayoutConfiguration.html Type: schema.TypeList, Optional: true, @@ -552,9 +543,9 @@ func sectionLayoutConfigurationSchema() *schema.Schema { }, }, } -} +}) -func spacingSchema() *schema.Schema { +var spacingSchema = sync.OnceValue(func() *schema.Schema { return &schema.Schema{ // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_Spacing.html Type: schema.TypeList, Optional: true, @@ -581,7 +572,7 @@ func spacingSchema() *schema.Schema { }, }, } -} +}) func expandAnalysisDefaults(tfList []interface{}) *awstypes.AnalysisDefaults { if len(tfList) == 0 || tfList[0] == nil { diff --git a/internal/service/quicksight/schema/theme.go b/internal/service/quicksight/schema/theme.go index bd2c11d3ae50..3d7a8ebd46f7 100644 --- a/internal/service/quicksight/schema/theme.go +++ b/internal/service/quicksight/schema/theme.go @@ -4,11 +4,9 @@ package schema import ( - "github.com/YakDriver/regexache" "github.com/aws/aws-sdk-go-v2/aws" awstypes "github.com/aws/aws-sdk-go-v2/service/quicksight/types" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" "github.com/hashicorp/terraform-provider-aws/internal/flex" "github.com/hashicorp/terraform-provider-aws/internal/sdkv2" ) @@ -31,25 +29,15 @@ func ThemeConfigurationSchema() *schema.Schema { Optional: true, MinItems: 8, // Colors size needs to be in the range between 8 and 20 MaxItems: 20, - Elem: &schema.Schema{ - Type: schema.TypeString, - ValidateFunc: validation.StringMatch(regexache.MustCompile(`^#[0-9A-F]{6}$`), ""), - }, - }, - "empty_fill_color": { - Type: schema.TypeString, - Optional: true, - ValidateFunc: validation.StringMatch(regexache.MustCompile(`^#[0-9A-F]{6}$`), ""), + Elem: hexColorSchema(attrElem), }, + "empty_fill_color": hexColorSchema(attrOptional), "min_max_gradient": { Type: schema.TypeList, Optional: true, MinItems: 2, // MinMaxGradient size needs to be 2 MaxItems: 2, - Elem: &schema.Schema{ - Type: schema.TypeString, - ValidateFunc: validation.StringMatch(regexache.MustCompile(`^#[0-9A-F]{6}$`), ""), - }, + Elem: hexColorSchema(attrElem), }, }, }, @@ -148,86 +136,22 @@ func ThemeConfigurationSchema() *schema.Schema { Optional: true, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "accent": { - Type: schema.TypeString, - Optional: true, - ValidateFunc: validation.StringMatch(regexache.MustCompile(`^#[0-9A-F]{6}$`), ""), - }, - "accent_foreground": { - Type: schema.TypeString, - Optional: true, - ValidateFunc: validation.StringMatch(regexache.MustCompile(`^#[0-9A-F]{6}$`), ""), - }, - "danger": { - Type: schema.TypeString, - Optional: true, - ValidateFunc: validation.StringMatch(regexache.MustCompile(`^#[0-9A-F]{6}$`), ""), - }, - "danger_foreground": { - Type: schema.TypeString, - Optional: true, - ValidateFunc: validation.StringMatch(regexache.MustCompile(`^#[0-9A-F]{6}$`), ""), - }, - "dimension": { - Type: schema.TypeString, - Optional: true, - ValidateFunc: validation.StringMatch(regexache.MustCompile(`^#[0-9A-F]{6}$`), ""), - }, - "dimension_foreground": { - Type: schema.TypeString, - Optional: true, - ValidateFunc: validation.StringMatch(regexache.MustCompile(`^#[0-9A-F]{6}$`), ""), - }, - "measure": { - Type: schema.TypeString, - Optional: true, - ValidateFunc: validation.StringMatch(regexache.MustCompile(`^#[0-9A-F]{6}$`), ""), - }, - "measure_foreground": { - Type: schema.TypeString, - Optional: true, - ValidateFunc: validation.StringMatch(regexache.MustCompile(`^#[0-9A-F]{6}$`), ""), - }, - "primary_background": { - Type: schema.TypeString, - Optional: true, - ValidateFunc: validation.StringMatch(regexache.MustCompile(`^#[0-9A-F]{6}$`), ""), - }, - "primary_foreground": { - Type: schema.TypeString, - Optional: true, - ValidateFunc: validation.StringMatch(regexache.MustCompile(`^#[0-9A-F]{6}$`), ""), - }, - "secondary_background": { - Type: schema.TypeString, - Optional: true, - ValidateFunc: validation.StringMatch(regexache.MustCompile(`^#[0-9A-F]{6}$`), ""), - }, - "secondary_foreground": { - Type: schema.TypeString, - Optional: true, - ValidateFunc: validation.StringMatch(regexache.MustCompile(`^#[0-9A-F]{6}$`), ""), - }, - "success": { - Type: schema.TypeString, - Optional: true, - ValidateFunc: validation.StringMatch(regexache.MustCompile(`^#[0-9A-F]{6}$`), ""), - }, - "success_foreground": { - Type: schema.TypeString, - Optional: true, - ValidateFunc: validation.StringMatch(regexache.MustCompile(`^#[0-9A-F]{6}$`), ""), - }, - "warning": { - Type: schema.TypeString, - Optional: true, - ValidateFunc: validation.StringMatch(regexache.MustCompile(`^#[0-9A-F]{6}$`), ""), - }, - "warning_foreground": { - Type: schema.TypeString, - Optional: true, - ValidateFunc: validation.StringMatch(regexache.MustCompile(`^#[0-9A-F]{6}$`), ""), - }, + "accent": hexColorSchema(attrOptional), + "accent_foreground": hexColorSchema(attrOptional), + "danger": hexColorSchema(attrOptional), + "danger_foreground": hexColorSchema(attrOptional), + "dimension": hexColorSchema(attrOptional), + "dimension_foreground": hexColorSchema(attrOptional), + "measure": hexColorSchema(attrOptional), + "measure_foreground": hexColorSchema(attrOptional), + "primary_background": hexColorSchema(attrOptional), + "primary_foreground": hexColorSchema(attrOptional), + "secondary_background": hexColorSchema(attrOptional), + "secondary_foreground": hexColorSchema(attrOptional), + "success": hexColorSchema(attrOptional), + "success_foreground": hexColorSchema(attrOptional), + "warning": hexColorSchema(attrOptional), + "warning_foreground": hexColorSchema(attrOptional), }, }, }, diff --git a/internal/service/quicksight/schema/visual.go b/internal/service/quicksight/schema/visual.go index 4b60fbb60123..87fbec0f7803 100644 --- a/internal/service/quicksight/schema/visual.go +++ b/internal/service/quicksight/schema/visual.go @@ -4,14 +4,12 @@ package schema import ( + "sync" "time" - "github.com/YakDriver/regexache" "github.com/aws/aws-sdk-go-v2/aws" awstypes "github.com/aws/aws-sdk-go-v2/service/quicksight/types" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" - "github.com/hashicorp/terraform-provider-aws/internal/enum" "github.com/hashicorp/terraform-provider-aws/names" ) @@ -19,7 +17,7 @@ const customActionsMaxItems = 10 const referenceLinesMaxItems = 20 const dataPathValueMaxItems = 20 -func visualsSchema() *schema.Schema { +var visualsSchema = sync.OnceValue(func() *schema.Schema { return &schema.Schema{ // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_SheetControlLayout.html Type: schema.TypeList, MinItems: 1, @@ -53,9 +51,9 @@ func visualsSchema() *schema.Schema { }, }, } -} +}) -func legendOptionsSchema() *schema.Schema { +var legendOptionsSchema = sync.OnceValue(func() *schema.Schema { return &schema.Schema{ // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_LegendOptions.html Type: schema.TypeList, Optional: true, @@ -67,9 +65,9 @@ func legendOptionsSchema() *schema.Schema { Type: schema.TypeString, Optional: true, }, - "position": stringSchema(false, enum.Validate[awstypes.LegendPosition]()), + "position": stringEnumSchema[awstypes.LegendPosition](attrOptional), "title": labelOptionsSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_LabelOptions.html - "visibility": stringSchema(false, enum.Validate[awstypes.Visibility]()), + "visibility": stringEnumSchema[awstypes.Visibility](attrOptional), "width": { Type: schema.TypeString, Optional: true, @@ -77,9 +75,9 @@ func legendOptionsSchema() *schema.Schema { }, }, } -} +}) -func tooltipOptionsSchema() *schema.Schema { +var tooltipOptionsSchema = sync.OnceValue(func() *schema.Schema { return &schema.Schema{ // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_TooltipOptions.html Type: schema.TypeList, Optional: true, @@ -94,7 +92,7 @@ func tooltipOptionsSchema() *schema.Schema { MaxItems: 1, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "aggregation_visibility": stringSchema(false, enum.Validate[awstypes.Visibility]()), + "aggregation_visibility": stringEnumSchema[awstypes.Visibility](attrOptional), "tooltip_fields": { // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_TooltipItem.html Type: schema.TypeList, Optional: true, @@ -115,7 +113,7 @@ func tooltipOptionsSchema() *schema.Schema { Type: schema.TypeString, Optional: true, }, - "visibility": stringSchema(false, enum.Validate[awstypes.Visibility]()), + "visibility": stringEnumSchema[awstypes.Visibility](attrOptional), }, }, }, @@ -126,30 +124,30 @@ func tooltipOptionsSchema() *schema.Schema { MaxItems: 1, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "field_id": stringSchema(true, validation.StringLenBetween(1, 512)), + "field_id": stringLenBetweenSchema(attrRequired, 1, 512), "label": { Type: schema.TypeString, Optional: true, }, - "visibility": stringSchema(false, enum.Validate[awstypes.Visibility]()), + "visibility": stringEnumSchema[awstypes.Visibility](attrOptional), }, }, }, }, }, }, - "tooltip_title_type": stringSchema(false, enum.Validate[awstypes.TooltipTitleType]()), + "tooltip_title_type": stringEnumSchema[awstypes.TooltipTitleType](attrOptional), }, }, }, - "selected_tooltip_type": stringSchema(false, enum.Validate[awstypes.SelectedTooltipType]()), - "tooltip_visibility": stringSchema(false, enum.Validate[awstypes.Visibility]()), + "selected_tooltip_type": stringEnumSchema[awstypes.SelectedTooltipType](attrOptional), + "tooltip_visibility": stringEnumSchema[awstypes.Visibility](attrOptional), }, }, } -} +}) -func visualPaletteSchema() *schema.Schema { +var visualPaletteSchema = sync.OnceValue(func() *schema.Schema { return &schema.Schema{ // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_VisualPalette.html Type: schema.TypeList, Optional: true, @@ -157,7 +155,7 @@ func visualPaletteSchema() *schema.Schema { MaxItems: 1, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "chart_color": stringSchema(false, validation.StringMatch(regexache.MustCompile(`^#[0-9A-F]{6}$`), "")), + "chart_color": hexColorSchema(attrOptional), "color_map": { // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_DataPathColor.html Type: schema.TypeList, Optional: true, @@ -165,16 +163,16 @@ func visualPaletteSchema() *schema.Schema { MaxItems: 5000, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "color": stringSchema(true, validation.StringMatch(regexache.MustCompile(`^#[0-9A-F]{6}$`), "")), + "color": hexColorSchema(attrRequired), "element": dataPathValueSchema(1), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_DataPathValue.html - "time_granularity": stringSchema(false, enum.Validate[awstypes.TimeGranularity]()), + "time_granularity": stringEnumSchema[awstypes.TimeGranularity](attrOptional), }, }, }, }, }, } -} +}) func dataPathValueSchema(maxItems int) *schema.Schema { return &schema.Schema{ // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_DataPathValue.html @@ -184,14 +182,14 @@ func dataPathValueSchema(maxItems int) *schema.Schema { MaxItems: maxItems, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "field_id": stringSchema(true, validation.StringLenBetween(1, 512)), - "field_value": stringSchema(true, validation.StringLenBetween(1, 2048)), + "field_id": stringLenBetweenSchema(attrRequired, 1, 512), + "field_value": stringLenBetweenSchema(attrRequired, 1, 2048), }, }, } } -func columnHierarchiesSchema() *schema.Schema { +var columnHierarchiesSchema = sync.OnceValue(func() *schema.Schema { return &schema.Schema{ // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_ColumnHierarchy.html Type: schema.TypeList, Optional: true, @@ -206,7 +204,7 @@ func columnHierarchiesSchema() *schema.Schema { MaxItems: 1, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "hierarchy_id": stringSchema(true, validation.StringLenBetween(1, 512)), + "hierarchy_id": stringLenBetweenSchema(attrRequired, 1, 512), "drill_down_filters": drillDownFilterSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_DrillDownFilter.html }, }, @@ -225,12 +223,12 @@ func columnHierarchiesSchema() *schema.Schema { MaxItems: 10, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_ColumnIdentifier.html - "column_name": stringSchema(true, validation.StringLenBetween(1, 128)), - "data_set_identifier": stringSchema(true, validation.StringLenBetween(1, 2048)), + "column_name": stringLenBetweenSchema(attrRequired, 1, 128), + "data_set_identifier": stringLenBetweenSchema(attrRequired, 1, 2048), }, }, }, - "hierarchy_id": stringSchema(true, validation.StringLenBetween(1, 512)), + "hierarchy_id": stringLenBetweenSchema(attrRequired, 1, 512), "drill_down_filters": drillDownFilterSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_DrillDownFilter.html }, }, @@ -249,12 +247,12 @@ func columnHierarchiesSchema() *schema.Schema { MaxItems: 10, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_ColumnIdentifier.html - "column_name": stringSchema(true, validation.StringLenBetween(1, 128)), - "data_set_identifier": stringSchema(true, validation.StringLenBetween(1, 2048)), + "column_name": stringLenBetweenSchema(attrRequired, 1, 128), + "data_set_identifier": stringLenBetweenSchema(attrRequired, 1, 2048), }, }, }, - "hierarchy_id": stringSchema(true, validation.StringLenBetween(1, 512)), + "hierarchy_id": stringLenBetweenSchema(attrRequired, 1, 512), "drill_down_filters": drillDownFilterSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_DrillDownFilter.html }, }, @@ -262,9 +260,9 @@ func columnHierarchiesSchema() *schema.Schema { }, }, } -} +}) -func visualSubtitleLabelOptionsSchema() *schema.Schema { +var visualSubtitleLabelOptionsSchema = sync.OnceValue(func() *schema.Schema { return &schema.Schema{ // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_VisualSubtitleLabelOptions.html Type: schema.TypeList, Optional: true, @@ -274,11 +272,11 @@ func visualSubtitleLabelOptionsSchema() *schema.Schema { Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ "format_text": longFormatTextSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_LongFormatText.html - "visibility": stringOptionalComputedSchema(enum.Validate[awstypes.Visibility]()), + "visibility": stringEnumSchema[awstypes.Visibility](attrOptionalComputed), }, }, } -} +}) func longFormatTextSchema() *schema.Schema { return &schema.Schema{ // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_LongFormatText.html @@ -288,16 +286,8 @@ func longFormatTextSchema() *schema.Schema { MaxItems: 1, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "plain_text": { - Type: schema.TypeString, - Optional: true, - ValidateFunc: validation.StringLenBetween(1, 1024), - }, - "rich_text": { - Type: schema.TypeString, - Optional: true, - ValidateFunc: validation.StringLenBetween(1, 2048), - }, + "plain_text": stringLenBetweenSchema(attrOptional, 1, 1024), + "rich_text": stringLenBetweenSchema(attrOptional, 1, 2048), }, }, } @@ -311,22 +301,14 @@ func shortFormatTextSchema() *schema.Schema { MaxItems: 1, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "plain_text": { - Type: schema.TypeString, - Optional: true, - ValidateFunc: validation.StringLenBetween(1, 512), - }, - "rich_text": { - Type: schema.TypeString, - Optional: true, - ValidateFunc: validation.StringLenBetween(1, 1024), - }, + "plain_text": stringLenBetweenSchema(attrOptional, 1, 512), + "rich_text": stringLenBetweenSchema(attrOptional, 1, 1024), }, }, } } -func visualTitleLabelOptionsSchema() *schema.Schema { +var visualTitleLabelOptionsSchema = sync.OnceValue(func() *schema.Schema { return &schema.Schema{ // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_VisualTitleLabelOptions.html Type: schema.TypeList, Optional: true, @@ -336,13 +318,13 @@ func visualTitleLabelOptionsSchema() *schema.Schema { Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ "format_text": shortFormatTextSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_ShortFormatText.html - "visibility": stringOptionalComputedSchema(enum.Validate[awstypes.Visibility]()), + "visibility": stringEnumSchema[awstypes.Visibility](attrOptionalComputed), }, }, } -} +}) -func comparisonConfigurationSchema() *schema.Schema { +var comparisonConfigurationSchema = sync.OnceValue(func() *schema.Schema { return &schema.Schema{ // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_ComparisonConfiguration.html Type: schema.TypeList, Optional: true, @@ -362,13 +344,13 @@ func comparisonConfigurationSchema() *schema.Schema { }, }, }, - "comparison_method": stringSchema(false, enum.Validate[awstypes.ComparisonMethod]()), + "comparison_method": stringEnumSchema[awstypes.ComparisonMethod](attrOptional), }, }, } -} +}) -func colorScaleSchema() *schema.Schema { +var colorScaleSchema = sync.OnceValue(func() *schema.Schema { return &schema.Schema{ // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_ColorScale.html Type: schema.TypeList, Optional: true, @@ -376,7 +358,7 @@ func colorScaleSchema() *schema.Schema { MaxItems: 1, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "color_fill_type": stringSchema(true, enum.Validate[awstypes.ColorFillType]()), + "color_fill_type": stringEnumSchema[awstypes.ColorFillType](attrRequired), "colors": { // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_DataColor.html Type: schema.TypeList, Required: true, @@ -384,7 +366,7 @@ func colorScaleSchema() *schema.Schema { MaxItems: 3, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "color": stringSchema(false, validation.StringMatch(regexache.MustCompile(`^#[0-9A-F]{6}$`), "")), + "color": hexColorSchema(attrOptional), "data_value": { Type: schema.TypeFloat, Optional: true, @@ -399,7 +381,7 @@ func colorScaleSchema() *schema.Schema { MaxItems: 1, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "color": stringSchema(false, validation.StringMatch(regexache.MustCompile(`^#[0-9A-F]{6}$`), "")), + "color": hexColorSchema(attrOptional), "data_value": { Type: schema.TypeFloat, Optional: true, @@ -410,9 +392,9 @@ func colorScaleSchema() *schema.Schema { }, }, } -} +}) -func dataLabelOptionsSchema() *schema.Schema { +var dataLabelOptionsSchema = sync.OnceValue(func() *schema.Schema { return &schema.Schema{ // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_DataLabelOptions.html Type: schema.TypeList, MinItems: 1, @@ -420,7 +402,7 @@ func dataLabelOptionsSchema() *schema.Schema { Optional: true, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "category_label_visibility": stringSchema(false, enum.Validate[awstypes.Visibility]()), + "category_label_visibility": stringEnumSchema[awstypes.Visibility](attrOptional), "data_label_types": { // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_DataLabelType.html Type: schema.TypeList, MinItems: 1, @@ -435,9 +417,9 @@ func dataLabelOptionsSchema() *schema.Schema { Optional: true, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "field_id": stringSchema(false, validation.StringLenBetween(1, 512)), - "field_value": stringSchema(false, validation.StringLenBetween(1, 2048)), - "visibility": stringSchema(false, enum.Validate[awstypes.Visibility]()), + "field_id": stringLenBetweenSchema(attrOptional, 1, 512), + "field_value": stringLenBetweenSchema(attrOptional, 1, 2048), + "visibility": stringEnumSchema[awstypes.Visibility](attrOptional), }, }, }, @@ -448,8 +430,8 @@ func dataLabelOptionsSchema() *schema.Schema { Optional: true, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "field_id": stringSchema(false, validation.StringLenBetween(1, 512)), - "visibility": stringSchema(false, enum.Validate[awstypes.Visibility]()), + "field_id": stringLenBetweenSchema(attrOptional, 1, 512), + "visibility": stringEnumSchema[awstypes.Visibility](attrOptional), }, }, }, @@ -460,7 +442,7 @@ func dataLabelOptionsSchema() *schema.Schema { Optional: true, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "visibility": stringSchema(false, enum.Validate[awstypes.Visibility]()), + "visibility": stringEnumSchema[awstypes.Visibility](attrOptional), }, }, }, @@ -471,7 +453,7 @@ func dataLabelOptionsSchema() *schema.Schema { Optional: true, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "visibility": stringSchema(false, enum.Validate[awstypes.Visibility]()), + "visibility": stringEnumSchema[awstypes.Visibility](attrOptional), }, }, }, @@ -482,23 +464,27 @@ func dataLabelOptionsSchema() *schema.Schema { Optional: true, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "visibility": stringSchema(false, enum.Validate[awstypes.Visibility]()), + "visibility": stringEnumSchema[awstypes.Visibility](attrOptional), }, }, }, }, }, }, - "label_color": stringSchema(false, validation.StringMatch(regexache.MustCompile(`^#[0-9A-F]{6}$`), "")), - "label_content": stringSchema(false, enum.Validate[awstypes.DataLabelContent]()), + "label_color": hexColorSchema(attrOptional), + "label_content": stringEnumSchema[awstypes.DataLabelContent](attrOptional), "label_font_configuration": fontConfigurationSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_FontConfiguration.html - "measure_label_visibility": stringSchema(false, enum.Validate[awstypes.Visibility]()), - "overlap": stringSchema(false, enum.Validate[awstypes.DataLabelOverlap]()), - "position": stringSchema(false, enum.Validate[awstypes.DataLabelPosition]()), - "visibility": stringSchema(false, enum.Validate[awstypes.Visibility]()), + "measure_label_visibility": stringEnumSchema[awstypes.Visibility](attrOptional), + "overlap": stringEnumSchema[awstypes.DataLabelOverlap](attrOptional), + "position": stringEnumSchema[awstypes.DataLabelPosition](attrOptional), + "visibility": stringEnumSchema[awstypes.Visibility](attrOptional), }, }, } +}) + +func hexColorSchema(handling attrHandling) *schema.Schema { + return stringMatchSchema(handling, `^#[0-9A-F]{6}$`, "") } func expandVisual(tfMap map[string]interface{}) *awstypes.Visual { diff --git a/internal/service/quicksight/schema/visual_actions.go b/internal/service/quicksight/schema/visual_actions.go index d7cb50170302..e10a10dc12c9 100644 --- a/internal/service/quicksight/schema/visual_actions.go +++ b/internal/service/quicksight/schema/visual_actions.go @@ -10,7 +10,6 @@ import ( awstypes "github.com/aws/aws-sdk-go-v2/service/quicksight/types" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" - "github.com/hashicorp/terraform-provider-aws/internal/enum" "github.com/hashicorp/terraform-provider-aws/internal/flex" "github.com/hashicorp/terraform-provider-aws/internal/verify" "github.com/hashicorp/terraform-provider-aws/names" @@ -45,7 +44,7 @@ func visualCustomActionsSchema(maxItems int) *schema.Schema { Required: true, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "selected_field_option": stringSchema(false, enum.Validate[awstypes.SelectedFieldOptions]()), + "selected_field_option": stringEnumSchema[awstypes.SelectedFieldOptions](attrOptional), "selected_fields": { Type: schema.TypeList, Optional: true, @@ -73,7 +72,7 @@ func visualCustomActionsSchema(maxItems int) *schema.Schema { Optional: true, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "target_visual_option": stringSchema(false, enum.Validate[awstypes.TargetVisualOptions]()), + "target_visual_option": stringEnumSchema[awstypes.TargetVisualOptions](attrOptional), "target_visuals": { Type: schema.TypeSet, Optional: true, @@ -194,8 +193,8 @@ func visualCustomActionsSchema(maxItems int) *schema.Schema { }, }, }, - "select_all_value_options": stringSchema(false, enum.Validate[awstypes.SelectAllValueOptions]()), - "source_field": stringSchema(false, validation.StringLenBetween(1, 2048)), + "select_all_value_options": stringEnumSchema[awstypes.SelectAllValueOptions](attrOptional), + "source_field": stringLenBetweenSchema(attrOptional, 1, 2048), "source_parameter_name": { Type: schema.TypeString, Optional: true, @@ -216,8 +215,8 @@ func visualCustomActionsSchema(maxItems int) *schema.Schema { Optional: true, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "url_target": stringSchema(true, enum.Validate[awstypes.URLTargetConfiguration]()), - "url_template": stringSchema(true, validation.StringLenBetween(1, 2048)), + "url_target": stringEnumSchema[awstypes.URLTargetConfiguration](attrRequired), + "url_template": stringLenBetweenSchema(attrRequired, 1, 2048), }, }, }, @@ -225,9 +224,9 @@ func visualCustomActionsSchema(maxItems int) *schema.Schema { }, }, "custom_action_id": idSchema(), - names.AttrName: stringSchema(true, validation.StringLenBetween(1, 256)), - "trigger": stringSchema(true, enum.Validate[awstypes.VisualCustomActionTrigger]()), - names.AttrStatus: stringSchema(true, enum.Validate[awstypes.Status]()), + names.AttrName: stringLenBetweenSchema(attrRequired, 1, 256), + "trigger": stringEnumSchema[awstypes.VisualCustomActionTrigger](attrRequired), + names.AttrStatus: stringEnumSchema[awstypes.Status](attrRequired), }, }, } diff --git a/internal/service/quicksight/schema/visual_bar_chart.go b/internal/service/quicksight/schema/visual_bar_chart.go index 641663f069e2..f95831248330 100644 --- a/internal/service/quicksight/schema/visual_bar_chart.go +++ b/internal/service/quicksight/schema/visual_bar_chart.go @@ -7,7 +7,6 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awstypes "github.com/aws/aws-sdk-go-v2/service/quicksight/types" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - "github.com/hashicorp/terraform-provider-aws/internal/enum" "github.com/hashicorp/terraform-provider-aws/internal/verify" "github.com/hashicorp/terraform-provider-aws/names" ) @@ -29,7 +28,7 @@ func barCharVisualSchema() *schema.Schema { MaxItems: 1, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "bars_arrangement": stringOptionalComputedSchema(enum.Validate[awstypes.BarsArrangement]()), + "bars_arrangement": stringEnumSchema[awstypes.BarsArrangement](attrOptionalComputed), "category_axis": axisDisplayOptionsSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_AxisDisplayOptions.html "category_label_options": chartAxisLabelOptionsSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_ChartAxisLabelOptions.html "color_label_options": chartAxisLabelOptionsSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_ChartAxisLabelOptions.html @@ -60,9 +59,9 @@ func barCharVisualSchema() *schema.Schema { }, }, "legend": legendOptionsSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_LegendOptions.html - "orientation": stringOptionalComputedSchema(enum.Validate[awstypes.BarChartOrientation]()), - "reference_lines": referenceLineSchema(referenceLinesMaxItems), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_ReferenceLine.html - "small_multiples_options": smallMultiplesOptionsSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_SmallMultiplesOptions.html + "orientation": stringEnumSchema[awstypes.BarChartOrientation](attrOptionalComputed), + "reference_lines": referenceLineSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_ReferenceLine.html + "small_multiples_options": smallMultiplesOptionsSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_SmallMultiplesOptions.html "sort_configuration": { // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_BarChartSortConfiguration.html Type: schema.TypeList, Optional: true, @@ -71,12 +70,12 @@ func barCharVisualSchema() *schema.Schema { DiffSuppressFunc: verify.SuppressMissingOptionalConfigurationBlock, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "category_items_limit": itemsLimitConfigurationSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_ItemsLimitConfiguration.html - "category_sort": fieldSortOptionsSchema(fieldSortOptionsMaxItems100), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_FieldSortOptions.html, - "color_items_limit": itemsLimitConfigurationSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_ItemsLimitConfiguration.html - "color_sort": fieldSortOptionsSchema(fieldSortOptionsMaxItems100), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_FieldSortOptions.html - "small_multiples_limit_configuration": itemsLimitConfigurationSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_ItemsLimitConfiguration.html - "small_multiples_sort": fieldSortOptionsSchema(fieldSortOptionsMaxItems100), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_FieldSortOptions.html + "category_items_limit": itemsLimitConfigurationSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_ItemsLimitConfiguration.html + "category_sort": fieldSortOptionsSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_FieldSortOptions.html, + "color_items_limit": itemsLimitConfigurationSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_ItemsLimitConfiguration.html + "color_sort": fieldSortOptionsSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_FieldSortOptions.html + "small_multiples_limit_configuration": itemsLimitConfigurationSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_ItemsLimitConfiguration.html + "small_multiples_sort": fieldSortOptionsSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_FieldSortOptions.html }, }, }, diff --git a/internal/service/quicksight/schema/visual_box_plot.go b/internal/service/quicksight/schema/visual_box_plot.go index 5d0d38e304e4..84202c89459e 100644 --- a/internal/service/quicksight/schema/visual_box_plot.go +++ b/internal/service/quicksight/schema/visual_box_plot.go @@ -8,7 +8,6 @@ import ( awstypes "github.com/aws/aws-sdk-go-v2/service/quicksight/types" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" - "github.com/hashicorp/terraform-provider-aws/internal/enum" "github.com/hashicorp/terraform-provider-aws/internal/verify" "github.com/hashicorp/terraform-provider-aws/names" ) @@ -37,8 +36,8 @@ func boxPlotVisualSchema() *schema.Schema { MaxItems: 1, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "all_data_points_visibility": stringSchema(false, enum.Validate[awstypes.Visibility]()), - "outlier_visibility": stringSchema(false, enum.Validate[awstypes.Visibility]()), + "all_data_points_visibility": stringEnumSchema[awstypes.Visibility](attrOptional), + "outlier_visibility": stringEnumSchema[awstypes.Visibility](attrOptional), "style_options": { // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_BoxPlotStyleOptions.html Type: schema.TypeList, Optional: true, @@ -46,7 +45,7 @@ func boxPlotVisualSchema() *schema.Schema { MaxItems: 1, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "fill_style": stringSchema(false, enum.Validate[awstypes.BoxPlotFillStyle]()), + "fill_style": stringEnumSchema[awstypes.BoxPlotFillStyle](attrOptional), }, }, }, @@ -77,10 +76,10 @@ func boxPlotVisualSchema() *schema.Schema { }, }, }, - "legend": legendOptionsSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_LegendOptions.html - "primary_y_axis_display_options": axisDisplayOptionsSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_AxisDisplayOptions.html - "primary_y_axis_label_options": chartAxisLabelOptionsSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_ChartAxisLabelOptions.html - "reference_lines": referenceLineSchema(referenceLinesMaxItems), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_ReferenceLine.html + "legend": legendOptionsSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_LegendOptions.html + "primary_y_axis_display_options": axisDisplayOptionsSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_AxisDisplayOptions.html + "primary_y_axis_label_options": chartAxisLabelOptionsSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_ChartAxisLabelOptions.html + "reference_lines": referenceLineSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_ReferenceLine.html "sort_configuration": { // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_BoxPlotSortConfiguration.html Type: schema.TypeList, Optional: true, @@ -89,8 +88,8 @@ func boxPlotVisualSchema() *schema.Schema { DiffSuppressFunc: verify.SuppressMissingOptionalConfigurationBlock, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "category_sort": fieldSortOptionsSchema(fieldSortOptionsMaxItems100), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_FieldSortOptions.html, - "pagination_configuration": paginationConfigurationSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_PaginationConfiguration.html + "category_sort": fieldSortOptionsSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_FieldSortOptions.html, + "pagination_configuration": paginationConfigurationSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_PaginationConfiguration.html }, }, }, diff --git a/internal/service/quicksight/schema/visual_chart_configuration.go b/internal/service/quicksight/schema/visual_chart_configuration.go index 889f391297fa..aa659574e512 100644 --- a/internal/service/quicksight/schema/visual_chart_configuration.go +++ b/internal/service/quicksight/schema/visual_chart_configuration.go @@ -4,16 +4,15 @@ package schema import ( - "github.com/YakDriver/regexache" + "sync" + "github.com/aws/aws-sdk-go-v2/aws" awstypes "github.com/aws/aws-sdk-go-v2/service/quicksight/types" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" - "github.com/hashicorp/terraform-provider-aws/internal/enum" "github.com/hashicorp/terraform-provider-aws/names" ) -func axisDisplayOptionsSchema() *schema.Schema { +var axisDisplayOptionsSchema = sync.OnceValue(func() *schema.Schema { return &schema.Schema{ // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_AxisDisplayOptions.html Type: schema.TypeList, MinItems: 1, @@ -21,7 +20,7 @@ func axisDisplayOptionsSchema() *schema.Schema { Optional: true, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "axis_line_visibility": stringSchema(false, enum.Validate[awstypes.Visibility]()), + "axis_line_visibility": stringEnumSchema[awstypes.Visibility](attrOptional), "axis_offset": { Type: schema.TypeString, Optional: true, @@ -40,7 +39,7 @@ func axisDisplayOptionsSchema() *schema.Schema { Optional: true, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "missing_date_visibility": stringSchema(false, enum.Validate[awstypes.Visibility]()), + "missing_date_visibility": stringEnumSchema[awstypes.Visibility](attrOptional), }, }, }, @@ -136,7 +135,7 @@ func axisDisplayOptionsSchema() *schema.Schema { }, }, }, - "grid_line_visibility": stringSchema(false, enum.Validate[awstypes.Visibility]()), + "grid_line_visibility": stringEnumSchema[awstypes.Visibility](attrOptional), "scrollbar_options": { // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_ScrollBarOptions.html Type: schema.TypeList, MinItems: 1, @@ -144,7 +143,7 @@ func axisDisplayOptionsSchema() *schema.Schema { Optional: true, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "visibility": stringSchema(false, enum.Validate[awstypes.Visibility]()), + "visibility": stringEnumSchema[awstypes.Visibility](attrOptional), "visible_range": { // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_VisibleRangeOptions.html Type: schema.TypeList, MinItems: 1, @@ -159,8 +158,8 @@ func axisDisplayOptionsSchema() *schema.Schema { Optional: true, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "from": floatSchema(false, validation.FloatBetween(0, 100)), - "to": floatSchema(false, validation.FloatBetween(0, 100)), + "from": floatBetweenSchema(attrOptional, 0, 100), + "to": floatBetweenSchema(attrOptional, 0, 100), }, }, }, @@ -188,9 +187,9 @@ func axisDisplayOptionsSchema() *schema.Schema { }, }, } -} +}) -func chartAxisLabelOptionsSchema() *schema.Schema { +var chartAxisLabelOptionsSchema = sync.OnceValue(func() *schema.Schema { return &schema.Schema{ // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_ChartAxisLabelOptions.html Type: schema.TypeList, MinItems: 1, @@ -213,7 +212,7 @@ func chartAxisLabelOptionsSchema() *schema.Schema { Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ "column": columnSchema(true), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_ColumnIdentifier.html - "field_id": stringSchema(true, validation.StringLenBetween(1, 512)), + "field_id": stringLenBetweenSchema(attrRequired, 1, 512), }, }, }, @@ -225,14 +224,14 @@ func chartAxisLabelOptionsSchema() *schema.Schema { }, }, }, - "sort_icon_visibility": stringSchema(false, enum.Validate[awstypes.Visibility]()), - "visibility": stringSchema(false, enum.Validate[awstypes.Visibility]()), + "sort_icon_visibility": stringEnumSchema[awstypes.Visibility](attrOptional), + "visibility": stringEnumSchema[awstypes.Visibility](attrOptional), }, }, } -} +}) -func itemsLimitConfigurationSchema() *schema.Schema { +var itemsLimitConfigurationSchema = sync.OnceValue(func() *schema.Schema { return &schema.Schema{ // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_ItemsLimitConfiguration.html Type: schema.TypeList, Optional: true, @@ -244,13 +243,13 @@ func itemsLimitConfigurationSchema() *schema.Schema { Type: schema.TypeInt, Optional: true, }, - "other_categories": stringSchema(true, enum.Validate[awstypes.OtherCategories]()), + "other_categories": stringEnumSchema[awstypes.OtherCategories](attrRequired), }, }, } -} +}) -func contributionAnalysisDefaultsSchema() *schema.Schema { +var contributionAnalysisDefaultsSchema = sync.OnceValue(func() *schema.Schema { return &schema.Schema{ // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_ContributionAnalysisDefault.html Type: schema.TypeList, MinItems: 1, @@ -265,23 +264,23 @@ func contributionAnalysisDefaultsSchema() *schema.Schema { Required: true, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_ColumnIdentifier.html - "column_name": stringSchema(true, validation.StringLenBetween(1, 128)), - "data_set_identifier": stringSchema(true, validation.StringLenBetween(1, 2048)), + "column_name": stringLenBetweenSchema(attrRequired, 1, 128), + "data_set_identifier": stringLenBetweenSchema(attrRequired, 1, 2048), }, }, }, - "measure_field_id": stringSchema(true, validation.StringLenBetween(1, 512)), + "measure_field_id": stringLenBetweenSchema(attrRequired, 1, 512), }, }, } -} +}) -func referenceLineSchema(maxItems int) *schema.Schema { +var referenceLineSchema = sync.OnceValue(func() *schema.Schema { return &schema.Schema{ // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_ReferenceLine.html Type: schema.TypeList, Optional: true, MinItems: 1, - MaxItems: maxItems, + MaxItems: referenceLinesMaxItems, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ "data_configuration": { // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_ReferenceLineDataConfiguration.html @@ -291,7 +290,7 @@ func referenceLineSchema(maxItems int) *schema.Schema { MaxItems: 1, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "axis_binding": stringSchema(false, enum.Validate[awstypes.AxisBinding]()), + "axis_binding": stringEnumSchema[awstypes.AxisBinding](attrOptional), "dynamic_configuration": { // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_ReferenceLineDynamicDataConfiguration.html Type: schema.TypeList, Optional: true, @@ -336,13 +335,13 @@ func referenceLineSchema(maxItems int) *schema.Schema { MaxItems: 1, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "custom_label": stringSchema(true, validation.StringMatch(regexache.MustCompile(`.*\S.*`), "")), + "custom_label": stringMatchSchema(attrRequired, `.*\S.*`, ""), }, }, }, - "font_color": stringSchema(false, validation.StringMatch(regexache.MustCompile(`^#[0-9A-F]{6}$`), "")), + "font_color": hexColorSchema(attrOptional), "font_configuration": fontConfigurationSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_FontConfiguration.html - "horizontal_position": stringSchema(false, enum.Validate[awstypes.ReferenceLineLabelHorizontalPosition]()), + "horizontal_position": stringEnumSchema[awstypes.ReferenceLineLabelHorizontalPosition](attrOptional), "value_label_configuration": { // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_ReferenceLineValueLabelConfiguration.html Type: schema.TypeList, Optional: true, @@ -351,15 +350,15 @@ func referenceLineSchema(maxItems int) *schema.Schema { Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ "format_configuration": numericFormatConfigurationSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_NumericFormatConfiguration.html - "relative_position": stringSchema(false, enum.Validate[awstypes.ReferenceLineValueLabelRelativePosition]()), + "relative_position": stringEnumSchema[awstypes.ReferenceLineValueLabelRelativePosition](attrOptional), }, }, }, - "vertical_position": stringSchema(false, enum.Validate[awstypes.ReferenceLineLabelVerticalPosition]()), + "vertical_position": stringEnumSchema[awstypes.ReferenceLineLabelVerticalPosition](attrOptional), }, }, }, - names.AttrStatus: stringSchema(false, enum.Validate[awstypes.Status]()), + names.AttrStatus: stringEnumSchema[awstypes.Status](attrOptional), "style_configuration": { // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_ReferenceLineStyleConfiguration.html Type: schema.TypeList, Optional: true, @@ -367,17 +366,17 @@ func referenceLineSchema(maxItems int) *schema.Schema { MaxItems: 1, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "color": stringSchema(false, validation.StringMatch(regexache.MustCompile(`^#[0-9A-F]{6}$`), "")), - "pattern": stringSchema(false, enum.Validate[awstypes.ReferenceLinePatternType]()), + "color": hexColorSchema(attrOptional), + "pattern": stringEnumSchema[awstypes.ReferenceLinePatternType](attrOptional), }, }, }, }, }, } -} +}) -func smallMultiplesOptionsSchema() *schema.Schema { +var smallMultiplesOptionsSchema = sync.OnceValue(func() *schema.Schema { return &schema.Schema{ // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_SmallMultiplesOptions.html Type: schema.TypeList, Optional: true, @@ -385,16 +384,8 @@ func smallMultiplesOptionsSchema() *schema.Schema { MaxItems: 1, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "max_visible_columns": { - Type: schema.TypeInt, - Optional: true, - ValidateFunc: validation.IntBetween(1, 10), - }, - "max_visible_rows": { - Type: schema.TypeInt, - Optional: true, - ValidateFunc: validation.IntBetween(1, 10), - }, + "max_visible_columns": intBetweenSchema(attrOptional, 1, 10), + "max_visible_rows": intBetweenSchema(attrOptional, 1, 10), "panel_configuration": { // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_PanelConfiguration.html Type: schema.TypeList, Optional: true, @@ -402,20 +393,20 @@ func smallMultiplesOptionsSchema() *schema.Schema { MaxItems: 1, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "background_color": stringSchema(false, validation.StringMatch(regexache.MustCompile(`^#[0-9A-F]{6}(?:[0-9A-F]{2})?$`), "")), - "background_visibility": stringSchema(false, enum.Validate[awstypes.Visibility]()), - "border_color": stringSchema(false, validation.StringMatch(regexache.MustCompile(`^#[0-9A-F]{6}(?:[0-9A-F]{2})?$`), "")), - "border_style": stringSchema(false, enum.Validate[awstypes.PanelBorderStyle]()), + "background_color": stringMatchSchema(attrOptional, `^#[0-9A-F]{6}(?:[0-9A-F]{2})?$`, ""), + "background_visibility": stringEnumSchema[awstypes.Visibility](attrOptional), + "border_color": stringMatchSchema(attrOptional, `^#[0-9A-F]{6}(?:[0-9A-F]{2})?$`, ""), + "border_style": stringEnumSchema[awstypes.PanelBorderStyle](attrOptional), "border_thickness": { Type: schema.TypeString, Optional: true, }, - "border_visibility": stringSchema(false, enum.Validate[awstypes.Visibility]()), + "border_visibility": stringEnumSchema[awstypes.Visibility](attrOptional), "gutter_spacing": { Type: schema.TypeString, Optional: true, }, - "gutter_visibility": stringSchema(false, enum.Validate[awstypes.Visibility]()), + "gutter_visibility": stringEnumSchema[awstypes.Visibility](attrOptional), "title": { // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_PanelTitleOptions.html Type: schema.TypeList, Optional: true, @@ -424,8 +415,8 @@ func smallMultiplesOptionsSchema() *schema.Schema { Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ "font_configuration": fontConfigurationSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_FontConfiguration.html - "horizontal_text_alignment": stringSchema(false, enum.Validate[awstypes.HorizontalTextAlignment]()), - "visibility": stringSchema(false, enum.Validate[awstypes.Visibility]()), + "horizontal_text_alignment": stringEnumSchema[awstypes.HorizontalTextAlignment](attrOptional), + "visibility": stringEnumSchema[awstypes.Visibility](attrOptional), }, }, }, @@ -435,7 +426,7 @@ func smallMultiplesOptionsSchema() *schema.Schema { }, }, } -} +}) func expandAxisDisplayOptions(tfList []interface{}) *awstypes.AxisDisplayOptions { if len(tfList) == 0 || tfList[0] == nil { diff --git a/internal/service/quicksight/schema/visual_combo_chart.go b/internal/service/quicksight/schema/visual_combo_chart.go index 7db6b16e6b87..24f38ca55f3e 100644 --- a/internal/service/quicksight/schema/visual_combo_chart.go +++ b/internal/service/quicksight/schema/visual_combo_chart.go @@ -7,7 +7,6 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awstypes "github.com/aws/aws-sdk-go-v2/service/quicksight/types" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - "github.com/hashicorp/terraform-provider-aws/internal/enum" "github.com/hashicorp/terraform-provider-aws/internal/verify" "github.com/hashicorp/terraform-provider-aws/names" ) @@ -30,7 +29,7 @@ func comboChartVisualSchema() *schema.Schema { Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ "bar_data_labels": dataLabelOptionsSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_DataLabelOptions.html - "bars_arrangement": stringSchema(false, enum.Validate[awstypes.BarsArrangement]()), + "bars_arrangement": stringEnumSchema[awstypes.BarsArrangement](attrOptional), "category_axis": axisDisplayOptionsSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_AxisDisplayOptions.html "category_label_options": chartAxisLabelOptionsSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_ChartAxisLabelOptions.html "color_label_options": chartAxisLabelOptionsSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_ChartAxisLabelOptions.html @@ -58,13 +57,13 @@ func comboChartVisualSchema() *schema.Schema { }, }, }, - "legend": legendOptionsSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_LegendOptions.html - "line_data_labels": dataLabelOptionsSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_DataLabelOptions.html - "primary_y_axis_display_options": axisDisplayOptionsSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_AxisDisplayOptions.html - "primary_y_axis_label_options": chartAxisLabelOptionsSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_ChartAxisLabelOptions.html - "reference_lines": referenceLineSchema(referenceLinesMaxItems), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_ReferenceLine.html - "secondary_y_axis_display_options": axisDisplayOptionsSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_AxisDisplayOptions.html - "secondary_y_axis_label_options": chartAxisLabelOptionsSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_ChartAxisLabelOptions.html + "legend": legendOptionsSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_LegendOptions.html + "line_data_labels": dataLabelOptionsSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_DataLabelOptions.html + "primary_y_axis_display_options": axisDisplayOptionsSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_AxisDisplayOptions.html + "primary_y_axis_label_options": chartAxisLabelOptionsSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_ChartAxisLabelOptions.html + "reference_lines": referenceLineSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_ReferenceLine.html + "secondary_y_axis_display_options": axisDisplayOptionsSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_AxisDisplayOptions.html + "secondary_y_axis_label_options": chartAxisLabelOptionsSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_ChartAxisLabelOptions.html "sort_configuration": { // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_ComboChartSortConfiguration.html Type: schema.TypeList, Optional: true, @@ -73,10 +72,10 @@ func comboChartVisualSchema() *schema.Schema { DiffSuppressFunc: verify.SuppressMissingOptionalConfigurationBlock, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "category_items_limit": itemsLimitConfigurationSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_ItemsLimitConfiguration.html - "category_sort": fieldSortOptionsSchema(fieldSortOptionsMaxItems100), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_FieldSortOptions.html, - "color_items_limit": itemsLimitConfigurationSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_ItemsLimitConfiguration.html - "color_sort": fieldSortOptionsSchema(fieldSortOptionsMaxItems100), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_FieldSortOptions.html + "category_items_limit": itemsLimitConfigurationSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_ItemsLimitConfiguration.html + "category_sort": fieldSortOptionsSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_FieldSortOptions.html, + "color_items_limit": itemsLimitConfigurationSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_ItemsLimitConfiguration.html + "color_sort": fieldSortOptionsSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_FieldSortOptions.html }, }, }, diff --git a/internal/service/quicksight/schema/visual_conditional_formatting.go b/internal/service/quicksight/schema/visual_conditional_formatting.go index fdb1a9c9fa1a..9a3688410f68 100644 --- a/internal/service/quicksight/schema/visual_conditional_formatting.go +++ b/internal/service/quicksight/schema/visual_conditional_formatting.go @@ -4,16 +4,15 @@ package schema import ( - "github.com/YakDriver/regexache" + "sync" + "github.com/aws/aws-sdk-go-v2/aws" awstypes "github.com/aws/aws-sdk-go-v2/service/quicksight/types" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" - "github.com/hashicorp/terraform-provider-aws/internal/enum" "github.com/hashicorp/terraform-provider-aws/names" ) -func conditionalFormattingColorSchema() *schema.Schema { +var conditionalFormattingColorSchema = sync.OnceValue(func() *schema.Schema { return &schema.Schema{ // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_ConditionalFormattingColor.html Type: schema.TypeList, Required: true, @@ -46,7 +45,7 @@ func conditionalFormattingColorSchema() *schema.Schema { Type: schema.TypeFloat, Required: true, }, - "color": stringSchema(false, validation.StringMatch(regexache.MustCompile(`^#[0-9A-F]{6}$`), "")), + "color": hexColorSchema(attrOptional), "data_value": { Type: schema.TypeFloat, Optional: true, @@ -57,7 +56,7 @@ func conditionalFormattingColorSchema() *schema.Schema { }, }, }, - names.AttrExpression: stringSchema(true, validation.StringLenBetween(1, 4096)), + names.AttrExpression: stringLenBetweenSchema(attrRequired, 1, 4096), }, }, }, @@ -68,17 +67,17 @@ func conditionalFormattingColorSchema() *schema.Schema { MaxItems: 1, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "color": stringSchema(false, validation.StringMatch(regexache.MustCompile(`^#[0-9A-F]{6}$`), "")), - names.AttrExpression: stringSchema(true, validation.StringLenBetween(1, 4096)), + "color": hexColorSchema(attrOptional), + names.AttrExpression: stringLenBetweenSchema(attrRequired, 1, 4096), }, }, }, }, }, } -} +}) -func conditionalFormattingIconSchema() *schema.Schema { +var conditionalFormattingIconSchema = sync.OnceValue(func() *schema.Schema { return &schema.Schema{ // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_ConditionalFormattingIcon.html Type: schema.TypeList, Optional: true, @@ -93,8 +92,8 @@ func conditionalFormattingIconSchema() *schema.Schema { MaxItems: 1, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "color": stringSchema(false, validation.StringMatch(regexache.MustCompile(`^#[0-9A-F]{6}$`), "")), - names.AttrExpression: stringSchema(true, validation.StringLenBetween(1, 4096)), + "color": hexColorSchema(attrOptional), + names.AttrExpression: stringLenBetweenSchema(attrRequired, 1, 4096), "icon_options": { // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_ConditionalFormattingCustomIconOptions.html Type: schema.TypeList, Required: true, @@ -102,8 +101,8 @@ func conditionalFormattingIconSchema() *schema.Schema { MaxItems: 1, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "icon": stringSchema(false, enum.Validate[awstypes.Icon]()), - "unicode_icon": stringSchema(false, validation.StringMatch(regexache.MustCompile(`^[^\\u0000-\\u00FF]$`), "")), + "icon": stringEnumSchema[awstypes.Icon](attrOptional), + "unicode_icon": stringMatchSchema(attrOptional, `^[^\\u0000-\\u00FF]$`, ""), }, }, }, @@ -114,7 +113,7 @@ func conditionalFormattingIconSchema() *schema.Schema { MaxItems: 1, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "icon_display_option": stringSchema(false, enum.Validate[awstypes.ConditionalFormattingIconDisplayOption]())}, + "icon_display_option": stringEnumSchema[awstypes.ConditionalFormattingIconDisplayOption](attrOptional)}, }, }, }, @@ -127,15 +126,15 @@ func conditionalFormattingIconSchema() *schema.Schema { MaxItems: 1, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - names.AttrExpression: stringSchema(true, validation.StringLenBetween(1, 4096)), - "icon_set_type": stringSchema(false, enum.Validate[awstypes.ConditionalFormattingIconSetType]()), + names.AttrExpression: stringLenBetweenSchema(attrRequired, 1, 4096), + "icon_set_type": stringEnumSchema[awstypes.ConditionalFormattingIconSetType](attrOptional), }, }, }, }, }, } -} +}) func expandConditionalFormattingColor(tfList []interface{}) *awstypes.ConditionalFormattingColor { if len(tfList) == 0 || tfList[0] == nil { diff --git a/internal/service/quicksight/schema/visual_custom_content.go b/internal/service/quicksight/schema/visual_custom_content.go index c101ab896fa4..d9231f2c54c2 100644 --- a/internal/service/quicksight/schema/visual_custom_content.go +++ b/internal/service/quicksight/schema/visual_custom_content.go @@ -7,8 +7,6 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awstypes "github.com/aws/aws-sdk-go-v2/service/quicksight/types" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" - "github.com/hashicorp/terraform-provider-aws/internal/enum" "github.com/hashicorp/terraform-provider-aws/internal/verify" "github.com/hashicorp/terraform-provider-aws/names" ) @@ -21,7 +19,7 @@ func customContentVisualSchema() *schema.Schema { MaxItems: 1, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "data_set_identifier": stringSchema(true, validation.StringLenBetween(1, 2048)), + "data_set_identifier": stringLenBetweenSchema(attrRequired, 1, 2048), "visual_id": idSchema(), names.AttrActions: visualCustomActionsSchema(customActionsMaxItems), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_VisualCustomAction.html "chart_configuration": { // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_CustomContentConfiguration.html @@ -32,9 +30,9 @@ func customContentVisualSchema() *schema.Schema { DiffSuppressFunc: verify.SuppressMissingOptionalConfigurationBlock, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - names.AttrContentType: stringSchema(false, enum.Validate[awstypes.CustomContentType]()), - "content_url": stringSchema(false, validation.StringLenBetween(1, 2048)), - "image_scaling": stringSchema(false, enum.Validate[awstypes.CustomContentImageScalingConfiguration]()), + names.AttrContentType: stringEnumSchema[awstypes.CustomContentType](attrOptional), + "content_url": stringLenBetweenSchema(attrOptional, 1, 2048), + "image_scaling": stringEnumSchema[awstypes.CustomContentImageScalingConfiguration](attrOptional), }, }, }, diff --git a/internal/service/quicksight/schema/visual_empty.go b/internal/service/quicksight/schema/visual_empty.go index c8347b3830d6..fb434c1f9970 100644 --- a/internal/service/quicksight/schema/visual_empty.go +++ b/internal/service/quicksight/schema/visual_empty.go @@ -7,7 +7,6 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awstypes "github.com/aws/aws-sdk-go-v2/service/quicksight/types" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" "github.com/hashicorp/terraform-provider-aws/names" ) @@ -19,7 +18,7 @@ func emptyVisualSchema() *schema.Schema { MaxItems: 1, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "data_set_identifier": stringSchema(true, validation.StringLenBetween(1, 2048)), + "data_set_identifier": stringLenBetweenSchema(attrRequired, 1, 2048), "visual_id": idSchema(), names.AttrActions: visualCustomActionsSchema(customActionsMaxItems), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_VisualCustomAction.html }, diff --git a/internal/service/quicksight/schema/visual_fields.go b/internal/service/quicksight/schema/visual_fields.go index f1d7a6a69b32..def231c4a4fa 100644 --- a/internal/service/quicksight/schema/visual_fields.go +++ b/internal/service/quicksight/schema/visual_fields.go @@ -7,140 +7,181 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awstypes "github.com/aws/aws-sdk-go-v2/service/quicksight/types" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" - "github.com/hashicorp/terraform-provider-aws/internal/enum" "github.com/hashicorp/terraform-provider-aws/names" ) -const measureFieldsMaxItems5 = 5 -const measureFieldsMaxItems20 = 20 -const measureFieldsMaxItems40 = 40 -const measureFieldsMaxItems200 = 200 -const dimensionsFieldMaxItems10 = 10 -const dimensionsFieldMaxItems40 = 40 -const dimensionsFieldMaxItems200 = 200 - -func dimensionFieldSchema(maxItems int) *schema.Schema { - return &schema.Schema{ // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_DimensionField.html - Type: schema.TypeList, - MinItems: 1, - MaxItems: maxItems, - Optional: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "categorical_dimension_field": { // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_CategoricalDimensionField.html - Type: schema.TypeList, - MinItems: 1, - MaxItems: 1, - Optional: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "column": columnSchema(true), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_ColumnIdentifier.html - "field_id": stringSchema(true, validation.StringLenBetween(1, 512)), - "format_configuration": stringFormatConfigurationSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_StringFormatConfiguration.html - "hierarchy_id": stringSchema(false, validation.StringLenBetween(1, 512)), +type measureFieldsSize int + +const ( + measureFieldsMaxItems5 measureFieldsSize = 5 + measureFieldsMaxItems20 measureFieldsSize = 20 + measureFieldsMaxItems40 measureFieldsSize = 40 + measureFieldsMaxItems200 measureFieldsSize = 200 +) + +type dimensionFieldSize int + +const ( + dimensionsFieldMaxItems10 dimensionFieldSize = 10 + dimensionsFieldMaxItems40 dimensionFieldSize = 40 + dimensionsFieldMaxItems200 dimensionFieldSize = 200 +) + +type dimensionFieldSchemaIdentity dimensionFieldSize + +var dimensionFieldSchemaCache syncMap[dimensionFieldSchemaIdentity, *schema.Schema] + +func dimensionFieldSchema(maxItems dimensionFieldSize) *schema.Schema { + id := dimensionFieldSchemaIdentity(maxItems) + + s, ok := dimensionFieldSchemaCache.Load(id) + if ok { + return s + } + + // Use a separate `LoadOrStore` to avoid allocation if item is already in the cache + // Use `LoadOrStore` instead of `Store` in case there is a race + s, _ = dimensionFieldSchemaCache.LoadOrStore( + id, + &schema.Schema{ // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_DimensionField.html + Type: schema.TypeList, + MinItems: 1, + MaxItems: int(maxItems), + Optional: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "categorical_dimension_field": { // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_CategoricalDimensionField.html + Type: schema.TypeList, + MinItems: 1, + MaxItems: 1, + Optional: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "column": columnSchema(true), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_ColumnIdentifier.html + "field_id": stringLenBetweenSchema(attrRequired, 1, 512), + "format_configuration": stringFormatConfigurationSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_StringFormatConfiguration.html + "hierarchy_id": stringLenBetweenSchema(attrOptional, 1, 512), + }, }, }, - }, - "date_dimension_field": { // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_DateDimensionField.html - Type: schema.TypeList, - MinItems: 1, - MaxItems: 1, - Optional: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "column": columnSchema(true), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_ColumnIdentifier.html - "field_id": stringSchema(true, validation.StringLenBetween(1, 512)), - "date_granularity": stringSchema(false, enum.Validate[awstypes.TimeGranularity]()), - "format_configuration": dateTimeFormatConfigurationSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_DateTimeFormatConfiguration.html - "hierarchy_id": stringSchema(false, validation.StringLenBetween(1, 512)), + "date_dimension_field": { // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_DateDimensionField.html + Type: schema.TypeList, + MinItems: 1, + MaxItems: 1, + Optional: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "column": columnSchema(true), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_ColumnIdentifier.html + "field_id": stringLenBetweenSchema(attrRequired, 1, 512), + "date_granularity": stringEnumSchema[awstypes.TimeGranularity](attrOptional), + "format_configuration": dateTimeFormatConfigurationSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_DateTimeFormatConfiguration.html + "hierarchy_id": stringLenBetweenSchema(attrOptional, 1, 512), + }, }, }, - }, - "numerical_dimension_field": { // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_NumericalDimensionField.html - Type: schema.TypeList, - MinItems: 1, - MaxItems: 1, - Optional: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "column": columnSchema(true), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_ColumnIdentifier.html - "field_id": stringSchema(true, validation.StringLenBetween(1, 512)), - "format_configuration": numberFormatConfigurationSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_NumberFormatConfiguration.html - "hierarchy_id": stringSchema(false, validation.StringLenBetween(1, 512)), + "numerical_dimension_field": { // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_NumericalDimensionField.html + Type: schema.TypeList, + MinItems: 1, + MaxItems: 1, + Optional: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "column": columnSchema(true), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_ColumnIdentifier.html + "field_id": stringLenBetweenSchema(attrRequired, 1, 512), + "format_configuration": numberFormatConfigurationSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_NumberFormatConfiguration.html + "hierarchy_id": stringLenBetweenSchema(attrOptional, 1, 512), + }, }, }, }, }, }, - } + ) + return s } -func measureFieldSchema(maxItems int) *schema.Schema { - return &schema.Schema{ // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_MeasureField.html - Type: schema.TypeList, - MinItems: 1, - MaxItems: maxItems, - Optional: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "calculated_measure_field": { // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_CalculatedMeasureField.html - Type: schema.TypeList, - MinItems: 1, - MaxItems: 1, - Optional: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - names.AttrExpression: stringSchema(true, validation.StringLenBetween(1, 4096)), - "field_id": stringSchema(true, validation.StringLenBetween(1, 512)), +type meaureFieldSchemaIdentity measureFieldsSize + +var measureFieldSchemaCache syncMap[meaureFieldSchemaIdentity, *schema.Schema] + +func measureFieldSchema(maxItems measureFieldsSize) *schema.Schema { + id := meaureFieldSchemaIdentity(maxItems) + + s, ok := measureFieldSchemaCache.Load(id) + if ok { + return s + } + + // Use a separate `LoadOrStore` to avoid allocation if item is already in the cache + // Use `LoadOrStore` instead of `Store` in case there is a race + s, _ = measureFieldSchemaCache.LoadOrStore( + id, + &schema.Schema{ // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_MeasureField.html + Type: schema.TypeList, + MinItems: 1, + MaxItems: int(maxItems), + Optional: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "calculated_measure_field": { // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_CalculatedMeasureField.html + Type: schema.TypeList, + MinItems: 1, + MaxItems: 1, + Optional: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + names.AttrExpression: stringLenBetweenSchema(attrRequired, 1, 4096), + "field_id": stringLenBetweenSchema(attrRequired, 1, 512), + }, }, }, - }, - "categorical_measure_field": { // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_CategoricalMeasureField.html - Type: schema.TypeList, - MinItems: 1, - MaxItems: 1, - Optional: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "column": columnSchema(true), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_ColumnIdentifier.html - "field_id": stringSchema(true, validation.StringLenBetween(1, 512)), - "aggregation_function": stringSchema(false, enum.Validate[awstypes.CategoricalAggregationFunction]()), - "format_configuration": stringFormatConfigurationSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_StringFormatConfiguration.html + "categorical_measure_field": { // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_CategoricalMeasureField.html + Type: schema.TypeList, + MinItems: 1, + MaxItems: 1, + Optional: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "column": columnSchema(true), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_ColumnIdentifier.html + "field_id": stringLenBetweenSchema(attrRequired, 1, 512), + "aggregation_function": stringEnumSchema[awstypes.CategoricalAggregationFunction](attrOptional), + "format_configuration": stringFormatConfigurationSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_StringFormatConfiguration.html + }, }, }, - }, - "date_measure_field": { // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_DateMeasureField.html - Type: schema.TypeList, - MinItems: 1, - MaxItems: 1, - Optional: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "column": columnSchema(true), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_ColumnIdentifier.html - "field_id": stringSchema(true, validation.StringLenBetween(1, 512)), - "aggregation_function": stringSchema(false, enum.Validate[awstypes.DateAggregationFunction]()), - "format_configuration": dateTimeFormatConfigurationSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_DateTimeFormatConfiguration.html + "date_measure_field": { // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_DateMeasureField.html + Type: schema.TypeList, + MinItems: 1, + MaxItems: 1, + Optional: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "column": columnSchema(true), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_ColumnIdentifier.html + "field_id": stringLenBetweenSchema(attrRequired, 1, 512), + "aggregation_function": stringEnumSchema[awstypes.DateAggregationFunction](attrOptional), + "format_configuration": dateTimeFormatConfigurationSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_DateTimeFormatConfiguration.html + }, }, }, - }, - "numerical_measure_field": { // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_NumericalMeasureField.html - Type: schema.TypeList, - MinItems: 1, - MaxItems: 1, - Optional: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "column": columnSchema(true), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_ColumnIdentifier.html - "field_id": stringSchema(true, validation.StringLenBetween(1, 512)), - "aggregation_function": numericalAggregationFunctionSchema(false), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_NumericalAggregationFunction.html - "format_configuration": numberFormatConfigurationSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_NumberFormatConfiguration.html + "numerical_measure_field": { // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_NumericalMeasureField.html + Type: schema.TypeList, + MinItems: 1, + MaxItems: 1, + Optional: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "column": columnSchema(true), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_ColumnIdentifier.html + "field_id": stringLenBetweenSchema(attrRequired, 1, 512), + "aggregation_function": numericalAggregationFunctionSchema(false), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_NumericalAggregationFunction.html + "format_configuration": numberFormatConfigurationSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_NumberFormatConfiguration.html + }, }, }, }, }, }, - } + ) + return s } func expandDimensionFields(tfList []interface{}) []awstypes.DimensionField { diff --git a/internal/service/quicksight/schema/visual_filled_map.go b/internal/service/quicksight/schema/visual_filled_map.go index d86ac2d6dba0..0f53fbc04b81 100644 --- a/internal/service/quicksight/schema/visual_filled_map.go +++ b/internal/service/quicksight/schema/visual_filled_map.go @@ -7,7 +7,6 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awstypes "github.com/aws/aws-sdk-go-v2/service/quicksight/types" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" "github.com/hashicorp/terraform-provider-aws/internal/verify" "github.com/hashicorp/terraform-provider-aws/names" ) @@ -61,7 +60,7 @@ func filledMapVisualSchema() *schema.Schema { DiffSuppressFunc: verify.SuppressMissingOptionalConfigurationBlock, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "category_sort": fieldSortOptionsSchema(fieldSortOptionsMaxItems100), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_FieldSortOptions.html, + "category_sort": fieldSortOptionsSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_FieldSortOptions.html, }, }, }, @@ -92,7 +91,7 @@ func filledMapVisualSchema() *schema.Schema { MaxItems: 1, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "field_id": stringSchema(true, validation.StringLenBetween(1, 512)), + "field_id": stringLenBetweenSchema(attrRequired, 1, 512), names.AttrFormat: { // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_ShapeConditionalFormat.html Type: schema.TypeList, Optional: true, diff --git a/internal/service/quicksight/schema/visual_funnel_chart.go b/internal/service/quicksight/schema/visual_funnel_chart.go index 6ccd640b08b5..3e1d04403382 100644 --- a/internal/service/quicksight/schema/visual_funnel_chart.go +++ b/internal/service/quicksight/schema/visual_funnel_chart.go @@ -4,12 +4,9 @@ package schema import ( - "github.com/YakDriver/regexache" "github.com/aws/aws-sdk-go-v2/aws" awstypes "github.com/aws/aws-sdk-go-v2/service/quicksight/types" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" - "github.com/hashicorp/terraform-provider-aws/internal/enum" "github.com/hashicorp/terraform-provider-aws/internal/verify" "github.com/hashicorp/terraform-provider-aws/names" ) @@ -39,13 +36,13 @@ func funnelChartVisualSchema() *schema.Schema { MaxItems: 1, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "category_label_visibility": stringSchema(false, enum.Validate[awstypes.Visibility]()), - "label_color": stringSchema(false, validation.StringMatch(regexache.MustCompile(`^#[0-9A-F]{6}$`), "")), + "category_label_visibility": stringEnumSchema[awstypes.Visibility](attrOptional), + "label_color": hexColorSchema(attrOptional), "label_font_configuration": fontConfigurationSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_FontConfiguration.html - "measure_data_label_style": stringSchema(false, enum.Validate[awstypes.FunnelChartMeasureDataLabelStyle]()), - "measure_label_visibility": stringSchema(false, enum.Validate[awstypes.Visibility]()), - "position": stringSchema(false, enum.Validate[awstypes.DataLabelPosition]()), - "visibility": stringSchema(false, enum.Validate[awstypes.Visibility]()), + "measure_data_label_style": stringEnumSchema[awstypes.FunnelChartMeasureDataLabelStyle](attrOptional), + "measure_label_visibility": stringEnumSchema[awstypes.Visibility](attrOptional), + "position": stringEnumSchema[awstypes.DataLabelPosition](attrOptional), + "visibility": stringEnumSchema[awstypes.Visibility](attrOptional), }, }, }, @@ -79,8 +76,8 @@ func funnelChartVisualSchema() *schema.Schema { DiffSuppressFunc: verify.SuppressMissingOptionalConfigurationBlock, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "category_items_limit": itemsLimitConfigurationSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_ItemsLimitConfiguration.html - "category_sort": fieldSortOptionsSchema(fieldSortOptionsMaxItems100), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_FieldSortOptions.html, + "category_items_limit": itemsLimitConfigurationSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_ItemsLimitConfiguration.html + "category_sort": fieldSortOptionsSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_FieldSortOptions.html, }, }, }, diff --git a/internal/service/quicksight/schema/visual_gauge_chart.go b/internal/service/quicksight/schema/visual_gauge_chart.go index 6f64fb29c4ae..4c7449f92bd0 100644 --- a/internal/service/quicksight/schema/visual_gauge_chart.go +++ b/internal/service/quicksight/schema/visual_gauge_chart.go @@ -7,7 +7,6 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awstypes "github.com/aws/aws-sdk-go-v2/service/quicksight/types" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - "github.com/hashicorp/terraform-provider-aws/internal/enum" "github.com/hashicorp/terraform-provider-aws/names" ) @@ -59,7 +58,7 @@ func gaugeChartVisualSchema() *schema.Schema { Type: schema.TypeFloat, Optional: true, }, - "arc_thickness": stringSchema(false, enum.Validate[awstypes.ArcThicknessOptions]()), + "arc_thickness": stringEnumSchema[awstypes.ArcThicknessOptions](attrOptional), }, }, }, @@ -96,7 +95,7 @@ func gaugeChartVisualSchema() *schema.Schema { }, }, "comparison": comparisonConfigurationSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_ComparisonConfiguration.html - "primary_value_display_type": stringSchema(false, enum.Validate[awstypes.PrimaryValueDisplayType]()), + "primary_value_display_type": stringEnumSchema[awstypes.PrimaryValueDisplayType](attrOptional), "primary_value_font_configuration": fontConfigurationSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_FontConfiguration.html }, }, diff --git a/internal/service/quicksight/schema/visual_geospatial_map.go b/internal/service/quicksight/schema/visual_geospatial_map.go index e418e895c2b1..f9f60b4be7b5 100644 --- a/internal/service/quicksight/schema/visual_geospatial_map.go +++ b/internal/service/quicksight/schema/visual_geospatial_map.go @@ -4,12 +4,9 @@ package schema import ( - "github.com/YakDriver/regexache" "github.com/aws/aws-sdk-go-v2/aws" awstypes "github.com/aws/aws-sdk-go-v2/service/quicksight/types" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" - "github.com/hashicorp/terraform-provider-aws/internal/enum" "github.com/hashicorp/terraform-provider-aws/names" ) @@ -83,7 +80,7 @@ func geospatialMapVisualSchema() *schema.Schema { MaxItems: 1, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "color": stringSchema(false, validation.StringMatch(regexache.MustCompile(`^#[0-9A-F]{6}$`), "")), + "color": hexColorSchema(attrOptional), }, }, }, @@ -93,7 +90,7 @@ func geospatialMapVisualSchema() *schema.Schema { }, }, }, - "selected_point_style": stringSchema(false, enum.Validate[awstypes.GeospatialSelectedPointStyle]()), + "selected_point_style": stringEnumSchema[awstypes.GeospatialSelectedPointStyle](attrOptional), }, }, }, diff --git a/internal/service/quicksight/schema/visual_heat_map.go b/internal/service/quicksight/schema/visual_heat_map.go index 7234b76c8997..e28e122c54ec 100644 --- a/internal/service/quicksight/schema/visual_heat_map.go +++ b/internal/service/quicksight/schema/visual_heat_map.go @@ -64,10 +64,10 @@ func heatMapVisualSchema() *schema.Schema { DiffSuppressFunc: verify.SuppressMissingOptionalConfigurationBlock, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "heat_map_column_items_limit_configuration": itemsLimitConfigurationSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_ItemsLimitConfiguration.html - "heat_map_column_sort": fieldSortOptionsSchema(fieldSortOptionsMaxItems100), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_FieldSortOptions.html, - "heat_map_row_items_limit_configuration": itemsLimitConfigurationSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_ItemsLimitConfiguration.html - "heat_map_row_sort": fieldSortOptionsSchema(fieldSortOptionsMaxItems100), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_FieldSortOptions.html + "heat_map_column_items_limit_configuration": itemsLimitConfigurationSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_ItemsLimitConfiguration.html + "heat_map_column_sort": fieldSortOptionsSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_FieldSortOptions.html, + "heat_map_row_items_limit_configuration": itemsLimitConfigurationSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_ItemsLimitConfiguration.html + "heat_map_row_sort": fieldSortOptionsSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_FieldSortOptions.html }, }, }, diff --git a/internal/service/quicksight/schema/visual_histogram.go b/internal/service/quicksight/schema/visual_histogram.go index 44ed962b3f3a..d43c0711c5ba 100644 --- a/internal/service/quicksight/schema/visual_histogram.go +++ b/internal/service/quicksight/schema/visual_histogram.go @@ -8,7 +8,6 @@ import ( awstypes "github.com/aws/aws-sdk-go-v2/service/quicksight/types" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" - "github.com/hashicorp/terraform-provider-aws/internal/enum" "github.com/hashicorp/terraform-provider-aws/names" ) @@ -58,11 +57,7 @@ func histogramVisualSchema() *schema.Schema { MaxItems: 1, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "bin_count_limit": { - Type: schema.TypeInt, - Optional: true, - ValidateFunc: validation.IntBetween(0, 1000), - }, + "bin_count_limit": intBetweenSchema(attrOptional, 0, 1000), names.AttrValue: { Type: schema.TypeFloat, Optional: true, @@ -71,7 +66,7 @@ func histogramVisualSchema() *schema.Schema { }, }, }, - "selected_bin_type": stringSchema(false, enum.Validate[awstypes.HistogramBinType]()), + "selected_bin_type": stringEnumSchema[awstypes.HistogramBinType](attrOptional), "start_value": { Type: schema.TypeFloat, Optional: true, diff --git a/internal/service/quicksight/schema/visual_insight.go b/internal/service/quicksight/schema/visual_insight.go index 5c8cba89c156..3ad6eae69415 100644 --- a/internal/service/quicksight/schema/visual_insight.go +++ b/internal/service/quicksight/schema/visual_insight.go @@ -7,8 +7,6 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awstypes "github.com/aws/aws-sdk-go-v2/service/quicksight/types" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" - "github.com/hashicorp/terraform-provider-aws/internal/enum" "github.com/hashicorp/terraform-provider-aws/names" ) @@ -20,7 +18,7 @@ func insightVisualSchema() *schema.Schema { MaxItems: 1, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "data_set_identifier": stringSchema(true, validation.StringLenBetween(1, 2048)), + "data_set_identifier": stringLenBetweenSchema(attrRequired, 1, 2048), "visual_id": idSchema(), names.AttrActions: visualCustomActionsSchema(customActionsMaxItems), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_VisualCustomAction.html "insight_configuration": { // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_InsightConfiguration.html @@ -46,7 +44,7 @@ func insightVisualSchema() *schema.Schema { Schema: map[string]*schema.Schema{ "computation_id": idSchema(), "time": dimensionFieldSchema(1), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_DimensionField.html - "custom_seasonality_value": intSchema(false, validation.IntBetween(1, 180)), + "custom_seasonality_value": intBetweenSchema(attrOptional, 1, 180), "lower_boundary": { Type: schema.TypeFloat, Optional: true, @@ -55,10 +53,10 @@ func insightVisualSchema() *schema.Schema { Type: schema.TypeString, Optional: true, }, - "periods_backward": intSchema(false, validation.IntBetween(0, 1000)), - "periods_forward": intSchema(false, validation.IntBetween(1, 1000)), - "prediction_interval": intSchema(false, validation.IntBetween(50, 95)), - "seasonality": stringSchema(true, enum.Validate[awstypes.ForecastComputationSeasonality]()), + "periods_backward": intBetweenSchema(attrOptional, 0, 1000), + "periods_forward": intBetweenSchema(attrOptional, 1, 1000), + "prediction_interval": intBetweenSchema(attrOptional, 50, 95), + "seasonality": stringEnumSchema[awstypes.ForecastComputationSeasonality](attrRequired), "upper_boundary": { Type: schema.TypeFloat, Optional: true, @@ -80,7 +78,7 @@ func insightVisualSchema() *schema.Schema { Type: schema.TypeString, Optional: true, }, - "period_size": intSchema(false, validation.IntBetween(2, 52)), + "period_size": intBetweenSchema(attrOptional, 2, 52), names.AttrValue: measureFieldSchema(1), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_MeasureField.html }, }, @@ -94,7 +92,7 @@ func insightVisualSchema() *schema.Schema { Schema: map[string]*schema.Schema{ "computation_id": idSchema(), "time": dimensionFieldSchema(1), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_DimensionField.html - names.AttrType: stringSchema(true, enum.Validate[awstypes.MaximumMinimumComputationType]()), + names.AttrType: stringEnumSchema[awstypes.MaximumMinimumComputationType](attrRequired), names.AttrName: { Type: schema.TypeString, Optional: true, @@ -151,7 +149,7 @@ func insightVisualSchema() *schema.Schema { Type: schema.TypeString, Optional: true, }, - "period_time_granularity": stringSchema(true, enum.Validate[awstypes.TimeGranularity]()), + "period_time_granularity": stringEnumSchema[awstypes.TimeGranularity](attrRequired), names.AttrValue: measureFieldSchema(1), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_MeasureField.html }, }, @@ -166,9 +164,9 @@ func insightVisualSchema() *schema.Schema { "computation_id": idSchema(), "category": dimensionFieldSchema(1), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_DimensionField.html "time": dimensionFieldSchema(1), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_DimensionField.html - names.AttrType: stringSchema(true, enum.Validate[awstypes.TopBottomComputationType]()), - "mover_size": intSchema(false, validation.IntBetween(1, 20)), - "sort_order": stringSchema(true, enum.Validate[awstypes.TopBottomSortOrder]()), + names.AttrType: stringEnumSchema[awstypes.TopBottomComputationType](attrRequired), + "mover_size": intBetweenSchema(attrOptional, 1, 20), + "sort_order": stringEnumSchema[awstypes.TopBottomSortOrder](attrRequired), names.AttrName: { Type: schema.TypeString, Optional: true, @@ -190,8 +188,8 @@ func insightVisualSchema() *schema.Schema { Type: schema.TypeString, Optional: true, }, - "result_size": intSchema(false, validation.IntBetween(1, 20)), - names.AttrType: stringSchema(true, enum.Validate[awstypes.TopBottomComputationType]()), + "result_size": intBetweenSchema(attrOptional, 1, 20), + names.AttrType: stringEnumSchema[awstypes.TopBottomComputationType](attrRequired), names.AttrValue: measureFieldSchema(1), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_MeasureField.html }, }, @@ -238,7 +236,7 @@ func insightVisualSchema() *schema.Schema { MaxItems: 1, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "narrative": stringSchema(true, validation.StringLenBetween(1, 150000)), + "narrative": stringLenBetweenSchema(attrRequired, 1, 150000), }, }, }, diff --git a/internal/service/quicksight/schema/visual_kpi.go b/internal/service/quicksight/schema/visual_kpi.go index 3471c8aa5338..662fecc7c965 100644 --- a/internal/service/quicksight/schema/visual_kpi.go +++ b/internal/service/quicksight/schema/visual_kpi.go @@ -4,12 +4,9 @@ package schema import ( - "github.com/YakDriver/regexache" "github.com/aws/aws-sdk-go-v2/aws" awstypes "github.com/aws/aws-sdk-go-v2/service/quicksight/types" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" - "github.com/hashicorp/terraform-provider-aws/internal/enum" "github.com/hashicorp/terraform-provider-aws/internal/verify" "github.com/hashicorp/terraform-provider-aws/names" ) @@ -52,7 +49,7 @@ func kpiVisualSchema() *schema.Schema { Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ "comparison": comparisonConfigurationSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_ComparisonConfiguration.html - "primary_value_display_type": stringSchema(false, enum.Validate[awstypes.PrimaryValueDisplayType]()), + "primary_value_display_type": stringEnumSchema[awstypes.PrimaryValueDisplayType](attrOptional), "primary_value_font_configuration": fontConfigurationSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_FontConfiguration.html "progress_bar": { // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_ProgressBarOptions.html Type: schema.TypeList, @@ -61,7 +58,7 @@ func kpiVisualSchema() *schema.Schema { MaxItems: 1, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "visibility": stringSchema(false, enum.Validate[awstypes.Visibility]()), + "visibility": stringEnumSchema[awstypes.Visibility](attrOptional), }, }, }, @@ -72,7 +69,7 @@ func kpiVisualSchema() *schema.Schema { MaxItems: 1, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "visibility": stringSchema(false, enum.Validate[awstypes.Visibility]()), + "visibility": stringEnumSchema[awstypes.Visibility](attrOptional), }, }, }, @@ -84,10 +81,10 @@ func kpiVisualSchema() *schema.Schema { MaxItems: 1, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "color": stringSchema(false, validation.StringMatch(regexache.MustCompile(`^#[0-9A-F]{6}$`), "")), - "tooltip_visibility": stringSchema(false, enum.Validate[awstypes.Visibility]()), - names.AttrType: stringSchema(true, enum.Validate[awstypes.KPISparklineType]()), - "visibility": stringSchema(false, enum.Validate[awstypes.Visibility]()), + "color": hexColorSchema(attrOptional), + "tooltip_visibility": stringEnumSchema[awstypes.Visibility](attrOptional), + names.AttrType: stringEnumSchema[awstypes.KPISparklineType](attrRequired), + "visibility": stringEnumSchema[awstypes.Visibility](attrOptional), }, }, }, @@ -98,7 +95,7 @@ func kpiVisualSchema() *schema.Schema { MaxItems: 1, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "visibility": stringSchema(false, enum.Validate[awstypes.Visibility]()), + "visibility": stringEnumSchema[awstypes.Visibility](attrOptional), }, }, }, @@ -116,7 +113,7 @@ func kpiVisualSchema() *schema.Schema { MaxItems: 1, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - names.AttrType: stringSchema(true, enum.Validate[awstypes.KPIVisualStandardLayoutType]()), + names.AttrType: stringEnumSchema[awstypes.KPIVisualStandardLayoutType](attrRequired), }, }, }, @@ -134,7 +131,7 @@ func kpiVisualSchema() *schema.Schema { DiffSuppressFunc: verify.SuppressMissingOptionalConfigurationBlock, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "trend_group_sort": fieldSortOptionsSchema(fieldSortOptionsMaxItems100), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_FieldSortOptions.html, + "trend_group_sort": fieldSortOptionsSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_FieldSortOptions.html, }, }, }, diff --git a/internal/service/quicksight/schema/visual_line_chart.go b/internal/service/quicksight/schema/visual_line_chart.go index a7e80f9758a5..37c343659488 100644 --- a/internal/service/quicksight/schema/visual_line_chart.go +++ b/internal/service/quicksight/schema/visual_line_chart.go @@ -4,14 +4,12 @@ package schema import ( + "sync" "time" - "github.com/YakDriver/regexache" "github.com/aws/aws-sdk-go-v2/aws" awstypes "github.com/aws/aws-sdk-go-v2/service/quicksight/types" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" - "github.com/hashicorp/terraform-provider-aws/internal/enum" "github.com/hashicorp/terraform-provider-aws/internal/verify" "github.com/hashicorp/terraform-provider-aws/names" ) @@ -42,7 +40,7 @@ func lineChartVisualSchema() *schema.Schema { MaxItems: 1, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "axis_binding": stringSchema(false, enum.Validate[awstypes.AxisBinding]()), + "axis_binding": stringEnumSchema[awstypes.AxisBinding](attrOptional), "line_style_settings": lineChartLineStyleSettingsSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_LineChartLineStyleSettings.html "marker_style_settings": lineChartMarkerStyleSettingsSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_LineChartMarkerStyleSettings.html }, @@ -90,10 +88,10 @@ func lineChartVisualSchema() *schema.Schema { Type: schema.TypeFloat, Optional: true, }, - "periods_backward": intSchema(false, validation.IntBetween(0, 1000)), - "periods_forward": intSchema(false, validation.IntBetween(1, 1000)), - "prediction_interval": intSchema(false, validation.IntBetween(50, 95)), - "seasonality": intSchema(false, validation.IntBetween(1, 180)), + "periods_backward": intBetweenSchema(attrOptional, 0, 1000), + "periods_forward": intBetweenSchema(attrOptional, 1, 1000), + "prediction_interval": intBetweenSchema(attrOptional, 50, 95), + "seasonality": intBetweenSchema(attrOptional, 1, 180), "upper_boundary": { Type: schema.TypeFloat, Optional: true, @@ -115,7 +113,7 @@ func lineChartVisualSchema() *schema.Schema { MaxItems: 1, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "date": stringSchema(true, verify.ValidUTCTimestamp), + "date": utcTimestampStringSchema(attrRequired), names.AttrValue: { Type: schema.TypeFloat, Required: true, @@ -130,8 +128,8 @@ func lineChartVisualSchema() *schema.Schema { MaxItems: 1, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "end_date": stringSchema(true, verify.ValidUTCTimestamp), - "start_date": stringSchema(true, verify.ValidUTCTimestamp), + "end_date": utcTimestampStringSchema(attrRequired), + "start_date": utcTimestampStringSchema(attrRequired), names.AttrValue: { Type: schema.TypeFloat, Required: true, @@ -161,15 +159,15 @@ func lineChartVisualSchema() *schema.Schema { MaxItems: 100, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "treatment_option": stringSchema(false, enum.Validate[awstypes.MissingDataTreatmentOption]()), + "treatment_option": stringEnumSchema[awstypes.MissingDataTreatmentOption](attrOptional), }, }, }, }, }, }, - "primary_y_axis_label_options": chartAxisLabelOptionsSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_ChartAxisLabelOptions.html - "reference_lines": referenceLineSchema(referenceLinesMaxItems), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_ReferenceLine.html + "primary_y_axis_label_options": chartAxisLabelOptionsSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_ChartAxisLabelOptions.html + "reference_lines": referenceLineSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_ReferenceLine.html "secondary_y_axis_display_options": { // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_LineSeriesAxisDisplayOptions.html Type: schema.TypeList, Optional: true, @@ -185,7 +183,7 @@ func lineChartVisualSchema() *schema.Schema { MaxItems: 100, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "treatment_option": stringSchema(false, enum.Validate[awstypes.MissingDataTreatmentOption]()), + "treatment_option": stringEnumSchema[awstypes.MissingDataTreatmentOption](attrOptional), }, }, }, @@ -207,8 +205,8 @@ func lineChartVisualSchema() *schema.Schema { MaxItems: 1, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "axis_binding": stringSchema(true, enum.Validate[awstypes.AxisBinding]()), - "field_id": stringSchema(true, validation.StringLenBetween(1, 512)), + "axis_binding": stringEnumSchema[awstypes.AxisBinding](attrRequired), + "field_id": stringLenBetweenSchema(attrRequired, 1, 512), "field_value": { Type: schema.TypeString, Optional: true, @@ -235,8 +233,8 @@ func lineChartVisualSchema() *schema.Schema { MaxItems: 1, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "axis_binding": stringSchema(true, enum.Validate[awstypes.AxisBinding]()), - "field_id": stringSchema(true, validation.StringLenBetween(1, 512)), + "axis_binding": stringEnumSchema[awstypes.AxisBinding](attrRequired), + "field_id": stringLenBetweenSchema(attrRequired, 1, 512), "settings": { // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_LineChartSeriesSettings.html Type: schema.TypeList, Optional: true, @@ -264,16 +262,16 @@ func lineChartVisualSchema() *schema.Schema { DiffSuppressFunc: verify.SuppressMissingOptionalConfigurationBlock, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "category_items_limit_configuration": itemsLimitConfigurationSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_ItemsLimitConfiguration.html - "category_sort": fieldSortOptionsSchema(fieldSortOptionsMaxItems100), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_FieldSortOptions.html, - "color_items_limit_configuration": itemsLimitConfigurationSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_ItemsLimitConfiguration.html - "small_multiples_limit_configuration": itemsLimitConfigurationSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_ItemsLimitConfiguration.html - "small_multiples_sort": fieldSortOptionsSchema(fieldSortOptionsMaxItems100), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_FieldSortOptions.html + "category_items_limit_configuration": itemsLimitConfigurationSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_ItemsLimitConfiguration.html + "category_sort": fieldSortOptionsSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_FieldSortOptions.html, + "color_items_limit_configuration": itemsLimitConfigurationSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_ItemsLimitConfiguration.html + "small_multiples_limit_configuration": itemsLimitConfigurationSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_ItemsLimitConfiguration.html + "small_multiples_sort": fieldSortOptionsSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_FieldSortOptions.html }, }, }, "tooltip": tooltipOptionsSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_TooltipOptions.html - names.AttrType: stringOptionalComputedSchema(enum.Validate[awstypes.LineChartType]()), + names.AttrType: stringEnumSchema[awstypes.LineChartType](attrOptionalComputed), "visual_palette": visualPaletteSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_VisualPalette.html "x_axis_display_options": axisDisplayOptionsSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_AxisDisplayOptions.html "x_axis_label_options": chartAxisLabelOptionsSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_ChartAxisLabelOptions.html @@ -288,7 +286,7 @@ func lineChartVisualSchema() *schema.Schema { } } -func lineChartLineStyleSettingsSchema() *schema.Schema { +var lineChartLineStyleSettingsSchema = sync.OnceValue(func() *schema.Schema { return &schema.Schema{ // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_LineChartLineStyleSettings.html Type: schema.TypeList, Optional: true, @@ -296,9 +294,9 @@ func lineChartLineStyleSettingsSchema() *schema.Schema { MaxItems: 1, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "line_interpolation": stringSchema(false, enum.Validate[awstypes.LineInterpolation]()), - "line_style": stringSchema(false, enum.Validate[awstypes.LineChartLineStyle]()), - "line_visibility": stringSchema(false, enum.Validate[awstypes.Visibility]()), + "line_interpolation": stringEnumSchema[awstypes.LineInterpolation](attrOptional), + "line_style": stringEnumSchema[awstypes.LineChartLineStyle](attrOptional), + "line_visibility": stringEnumSchema[awstypes.Visibility](attrOptional), "line_width": { Type: schema.TypeString, Optional: true, @@ -306,9 +304,9 @@ func lineChartLineStyleSettingsSchema() *schema.Schema { }, }, } -} +}) -func lineChartMarkerStyleSettingsSchema() *schema.Schema { +var lineChartMarkerStyleSettingsSchema = sync.OnceValue(func() *schema.Schema { return &schema.Schema{ // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_LineChartMarkerStyleSettings.html Type: schema.TypeList, Optional: true, @@ -316,17 +314,17 @@ func lineChartMarkerStyleSettingsSchema() *schema.Schema { MaxItems: 1, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "marker_color": stringSchema(false, validation.StringMatch(regexache.MustCompile(`^#[0-9A-F]{6}$`), "")), - "marker_shape": stringSchema(false, enum.Validate[awstypes.LineChartMarkerShape]()), + "marker_color": hexColorSchema(attrOptional), + "marker_shape": stringEnumSchema[awstypes.LineChartMarkerShape](attrOptional), "marker_size": { Type: schema.TypeString, Optional: true, }, - "marker_visibility": stringSchema(false, enum.Validate[awstypes.Visibility]()), + "marker_visibility": stringEnumSchema[awstypes.Visibility](attrOptional), }, }, } -} +}) func expandLineChartVisual(tfList []interface{}) *awstypes.LineChartVisual { if len(tfList) == 0 || tfList[0] == nil { diff --git a/internal/service/quicksight/schema/visual_map.go b/internal/service/quicksight/schema/visual_map.go index b98dd2559c17..46505c4a5771 100644 --- a/internal/service/quicksight/schema/visual_map.go +++ b/internal/service/quicksight/schema/visual_map.go @@ -4,14 +4,14 @@ package schema import ( + "sync" + "github.com/aws/aws-sdk-go-v2/aws" awstypes "github.com/aws/aws-sdk-go-v2/service/quicksight/types" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" - "github.com/hashicorp/terraform-provider-aws/internal/enum" ) -func geospatialMapStyleOptionsSchema() *schema.Schema { +var geospatialMapStyleOptionsSchema = sync.OnceValue(func() *schema.Schema { return &schema.Schema{ // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_GeospatialMapStyleOptions.html Type: schema.TypeList, Optional: true, @@ -19,13 +19,13 @@ func geospatialMapStyleOptionsSchema() *schema.Schema { MaxItems: 1, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "base_map_style": stringSchema(false, enum.Validate[awstypes.BaseMapStyleType]()), + "base_map_style": stringEnumSchema[awstypes.BaseMapStyleType](attrOptional), }, }, } -} +}) -func geospatialWindowOptionsSchema() *schema.Schema { +var geospatialWindowOptionsSchema = sync.OnceValue(func() *schema.Schema { return &schema.Schema{ // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_GeospatialWindowOptions.html Type: schema.TypeList, Optional: true, @@ -40,34 +40,18 @@ func geospatialWindowOptionsSchema() *schema.Schema { MaxItems: 1, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "east": { - Type: schema.TypeFloat, - Required: true, - ValidateFunc: validation.FloatBetween(-1800, 1800), - }, - "north": { - Type: schema.TypeFloat, - Required: true, - ValidateFunc: validation.FloatBetween(-90, 90), - }, - "south": { - Type: schema.TypeFloat, - Required: true, - ValidateFunc: validation.FloatBetween(-90, 90), - }, - "west": { - Type: schema.TypeFloat, - Required: true, - ValidateFunc: validation.FloatBetween(-1800, 1800), - }, + "east": floatBetweenSchema(attrRequired, -1800, 1800), + "north": floatBetweenSchema(attrRequired, -90, 90), + "south": floatBetweenSchema(attrRequired, -90, 90), + "west": floatBetweenSchema(attrRequired, -1800, 1800), }, }, }, - "map_zoom_mode": stringSchema(false, enum.Validate[awstypes.MapZoomMode]()), + "map_zoom_mode": stringEnumSchema[awstypes.MapZoomMode](attrOptional), }, }, } -} +}) func expandGeospatialMapStyleOptions(tfList []interface{}) *awstypes.GeospatialMapStyleOptions { if len(tfList) == 0 || tfList[0] == nil { diff --git a/internal/service/quicksight/schema/visual_pie_chart.go b/internal/service/quicksight/schema/visual_pie_chart.go index e857c53bc2ac..62c5c4bf61df 100644 --- a/internal/service/quicksight/schema/visual_pie_chart.go +++ b/internal/service/quicksight/schema/visual_pie_chart.go @@ -7,7 +7,6 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awstypes "github.com/aws/aws-sdk-go-v2/service/quicksight/types" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - "github.com/hashicorp/terraform-provider-aws/internal/enum" "github.com/hashicorp/terraform-provider-aws/internal/verify" "github.com/hashicorp/terraform-provider-aws/names" ) @@ -46,7 +45,7 @@ func pieChartVisualSchema() *schema.Schema { MaxItems: 1, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "arc_thickness": stringSchema(false, enum.Validate[awstypes.ArcThicknessOptions]()), + "arc_thickness": stringEnumSchema[awstypes.ArcThicknessOptions](attrOptional), }, }, }, @@ -57,7 +56,7 @@ func pieChartVisualSchema() *schema.Schema { MaxItems: 1, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "label_visibility": stringSchema(false, enum.Validate[awstypes.Visibility]()), + "label_visibility": stringEnumSchema[awstypes.Visibility](attrOptional), }, }, }, @@ -97,10 +96,10 @@ func pieChartVisualSchema() *schema.Schema { DiffSuppressFunc: verify.SuppressMissingOptionalConfigurationBlock, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "category_items_limit": itemsLimitConfigurationSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_ItemsLimitConfiguration.html - "category_sort": fieldSortOptionsSchema(fieldSortOptionsMaxItems100), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_FieldSortOptions.html, - "small_multiples_limit_configuration": itemsLimitConfigurationSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_ItemsLimitConfiguration.html - "small_multiples_sort": fieldSortOptionsSchema(fieldSortOptionsMaxItems100), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_FieldSortOptions.html + "category_items_limit": itemsLimitConfigurationSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_ItemsLimitConfiguration.html + "category_sort": fieldSortOptionsSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_FieldSortOptions.html, + "small_multiples_limit_configuration": itemsLimitConfigurationSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_ItemsLimitConfiguration.html + "small_multiples_sort": fieldSortOptionsSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_FieldSortOptions.html }, }, }, diff --git a/internal/service/quicksight/schema/visual_pivot_table.go b/internal/service/quicksight/schema/visual_pivot_table.go index a257cf5893fe..1d0db32346f3 100644 --- a/internal/service/quicksight/schema/visual_pivot_table.go +++ b/internal/service/quicksight/schema/visual_pivot_table.go @@ -4,12 +4,13 @@ package schema import ( + "sync" + "github.com/YakDriver/regexache" "github.com/aws/aws-sdk-go-v2/aws" awstypes "github.com/aws/aws-sdk-go-v2/service/quicksight/types" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" - "github.com/hashicorp/terraform-provider-aws/internal/enum" "github.com/hashicorp/terraform-provider-aws/internal/flex" "github.com/hashicorp/terraform-provider-aws/internal/verify" "github.com/hashicorp/terraform-provider-aws/names" @@ -53,8 +54,8 @@ func pivotTableVisualSchema() *schema.Schema { MaxItems: 20, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "field_id": stringSchema(true, validation.StringLenBetween(1, 512)), - "field_value": stringSchema(true, validation.StringLenBetween(1, 2048)), + "field_id": stringLenBetweenSchema(attrRequired, 1, 512), + "field_value": stringLenBetweenSchema(attrRequired, 1, 2048), }, }, }, @@ -72,9 +73,9 @@ func pivotTableVisualSchema() *schema.Schema { MaxItems: 100, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "field_id": stringSchema(true, validation.StringLenBetween(1, 512)), - "custom_label": stringSchema(false, validation.StringLenBetween(1, 2048)), - "visibility": stringSchema(false, enum.Validate[awstypes.Visibility]()), + "field_id": stringLenBetweenSchema(attrRequired, 1, 512), + "custom_label": stringLenBetweenSchema(attrOptional, 1, 2048), + "visibility": stringEnumSchema[awstypes.Visibility](attrOptional), }, }, }, @@ -111,8 +112,8 @@ func pivotTableVisualSchema() *schema.Schema { MaxItems: 1, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "overflow_column_header_visibility": stringSchema(false, enum.Validate[awstypes.Visibility]()), - "vertical_overflow_visibility": stringSchema(false, enum.Validate[awstypes.Visibility]()), + "overflow_column_header_visibility": stringEnumSchema[awstypes.Visibility](attrOptional), + "vertical_overflow_visibility": stringEnumSchema[awstypes.Visibility](attrOptional), }, }, }, @@ -131,7 +132,7 @@ func pivotTableVisualSchema() *schema.Schema { MaxItems: 200, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "field_id": stringSchema(true, validation.StringLenBetween(1, 512)), + "field_id": stringLenBetweenSchema(attrRequired, 1, 512), "sort_by": { // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_PivotTableSortBy.html Type: schema.TypeList, Required: true, @@ -147,7 +148,7 @@ func pivotTableVisualSchema() *schema.Schema { MaxItems: 1, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "direction": stringSchema(true, enum.Validate[awstypes.SortDirection]()), + "direction": stringEnumSchema[awstypes.SortDirection](attrRequired), "sort_paths": dataPathValueSchema(dataPathValueMaxItems), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_DataPathValue.html }, }, @@ -170,15 +171,15 @@ func pivotTableVisualSchema() *schema.Schema { Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ "cell_style": tableCellStyleSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_TableCellStyle.html - "collapsed_row_dimensions_visibility": stringSchema(false, enum.Validate[awstypes.Visibility]()), + "collapsed_row_dimensions_visibility": stringEnumSchema[awstypes.Visibility](attrOptional), "column_header_style": tableCellStyleSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_TableCellStyle.html - "column_names_visibility": stringSchema(false, enum.Validate[awstypes.Visibility]()), - "metric_placement": stringSchema(false, enum.Validate[awstypes.PivotTableMetricPlacement]()), + "column_names_visibility": stringEnumSchema[awstypes.Visibility](attrOptional), + "metric_placement": stringEnumSchema[awstypes.PivotTableMetricPlacement](attrOptional), "row_alternate_color_options": rowAlternateColorOptionsSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_RowAlternateColorOptions.html "row_field_names_style": tableCellStyleSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_TableCellStyle.html "row_header_style": tableCellStyleSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_TableCellStyle.html - "single_metric_visibility": stringSchema(false, enum.Validate[awstypes.Visibility]()), - "toggle_buttons_visibility": stringSchema(false, enum.Validate[awstypes.Visibility]()), + "single_metric_visibility": stringEnumSchema[awstypes.Visibility](attrOptional), + "toggle_buttons_visibility": stringEnumSchema[awstypes.Visibility](attrOptional), }, }, }, @@ -220,7 +221,7 @@ func pivotTableVisualSchema() *schema.Schema { MaxItems: 1, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "field_id": stringSchema(true, validation.StringLenBetween(1, 512)), + "field_id": stringLenBetweenSchema(attrRequired, 1, 512), names.AttrScope: { // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_PivotTableConditionalFormattingScope.html Type: schema.TypeList, Optional: true, @@ -228,7 +229,7 @@ func pivotTableVisualSchema() *schema.Schema { MaxItems: 1, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - names.AttrRole: stringSchema(false, enum.Validate[awstypes.PivotTableConditionalFormattingScopeRole]()), + names.AttrRole: stringEnumSchema[awstypes.PivotTableConditionalFormattingScopeRole](attrOptional), }, }, }, @@ -249,7 +250,7 @@ func pivotTableVisualSchema() *schema.Schema { } } -func tableBorderOptionsSchema() *schema.Schema { +var tableBorderOptionsSchema = sync.OnceValue(func() *schema.Schema { return &schema.Schema{ // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_TableBorderOptions.html Type: schema.TypeList, Required: true, @@ -257,15 +258,15 @@ func tableBorderOptionsSchema() *schema.Schema { MaxItems: 1, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "color": stringSchema(false, validation.StringMatch(regexache.MustCompile(`^#[0-9A-F]{6}$`), "")), - "style": stringSchema(false, enum.Validate[awstypes.TableBorderStyle]()), - "thickness": intSchema(false, validation.IntBetween(1, 4)), + "color": hexColorSchema(attrOptional), + "style": stringEnumSchema[awstypes.TableBorderStyle](attrOptional), + "thickness": intBetweenSchema(attrOptional, 1, 4), }, }, } -} +}) -func tableCellStyleSchema() *schema.Schema { +var tableCellStyleSchema = sync.OnceValue(func() *schema.Schema { return &schema.Schema{ // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_TableCellStyle.html Type: schema.TypeList, Optional: true, @@ -273,7 +274,7 @@ func tableCellStyleSchema() *schema.Schema { MaxItems: 1, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "background_color": stringSchema(false, validation.StringMatch(regexache.MustCompile(`^#[0-9A-F]{6}$`), "")), + "background_color": hexColorSchema(attrOptional), "border": { // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_GlobalTableBorderOptions.html Type: schema.TypeList, Optional: true, @@ -302,17 +303,17 @@ func tableCellStyleSchema() *schema.Schema { }, }, "font_configuration": fontConfigurationSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_FontConfiguration.html - "height": intSchema(false, validation.IntBetween(8, 500)), - "horizontal_text_alignment": stringSchema(false, enum.Validate[awstypes.HorizontalTextAlignment]()), - "text_wrap": stringSchema(false, enum.Validate[awstypes.TextWrap]()), - "vertical_text_alignment": stringSchema(false, enum.Validate[awstypes.VerticalTextAlignment]()), - "visibility": stringSchema(false, enum.Validate[awstypes.Visibility]()), + "height": intBetweenSchema(attrOptional, 8, 500), + "horizontal_text_alignment": stringEnumSchema[awstypes.HorizontalTextAlignment](attrOptional), + "text_wrap": stringEnumSchema[awstypes.TextWrap](attrOptional), + "vertical_text_alignment": stringEnumSchema[awstypes.VerticalTextAlignment](attrOptional), + "visibility": stringEnumSchema[awstypes.Visibility](attrOptional), }, }, } -} +}) -func subtotalOptionsSchema() *schema.Schema { +var subtotalOptionsSchema = sync.OnceValue(func() *schema.Schema { return &schema.Schema{ // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_SubtotalOptions.html Type: schema.TypeList, Optional: true, @@ -324,7 +325,7 @@ func subtotalOptionsSchema() *schema.Schema { Type: schema.TypeString, Optional: true, }, - "field_level": stringSchema(false, enum.Validate[awstypes.PivotTableSubtotalLevel]()), + "field_level": stringEnumSchema[awstypes.PivotTableSubtotalLevel](attrOptional), "field_level_options": { // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_PivotTableFieldSubtotalOptions.html Type: schema.TypeList, Optional: true, @@ -332,20 +333,20 @@ func subtotalOptionsSchema() *schema.Schema { MaxItems: 100, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "field_id": stringSchema(false, validation.StringLenBetween(1, 512)), + "field_id": stringLenBetweenSchema(attrOptional, 1, 512), }, }, }, "metric_header_cell_style": tableCellStyleSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_TableCellStyle.html "total_cell_style": tableCellStyleSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_TableCellStyle.html - "totals_visibility": stringSchema(false, enum.Validate[awstypes.Visibility]()), + "totals_visibility": stringEnumSchema[awstypes.Visibility](attrOptional), "value_cell_style": tableCellStyleSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_TableCellStyle.html }, }, } -} +}) -func pivotTotalOptionsSchema() *schema.Schema { +var pivotTotalOptionsSchema = sync.OnceValue(func() *schema.Schema { return &schema.Schema{ // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_PivotTotalOptions.html Type: schema.TypeList, Optional: true, @@ -358,17 +359,17 @@ func pivotTotalOptionsSchema() *schema.Schema { Optional: true, }, "metric_header_cell_style": tableCellStyleSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_TableCellStyle.html - "placement": stringSchema(false, enum.Validate[awstypes.TableTotalsPlacement]()), - "scroll_status": stringSchema(false, enum.Validate[awstypes.TableTotalsScrollStatus]()), + "placement": stringEnumSchema[awstypes.TableTotalsPlacement](attrOptional), + "scroll_status": stringEnumSchema[awstypes.TableTotalsScrollStatus](attrOptional), "total_cell_style": tableCellStyleSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_TableCellStyle.html - "totals_visibility": stringSchema(false, enum.Validate[awstypes.Visibility]()), + "totals_visibility": stringEnumSchema[awstypes.Visibility](attrOptional), "value_cell_style": tableCellStyleSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_TableCellStyle.html }, }, } -} +}) -func rowAlternateColorOptionsSchema() *schema.Schema { +var rowAlternateColorOptionsSchema = sync.OnceValue(func() *schema.Schema { return &schema.Schema{ // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_RowAlternateColorOptions.html Type: schema.TypeList, Optional: true, @@ -383,13 +384,13 @@ func rowAlternateColorOptionsSchema() *schema.Schema { MaxItems: 1, Elem: &schema.Schema{Type: schema.TypeString, ValidateFunc: validation.StringMatch(regexache.MustCompile(`^#[0-9A-F]{6}$`), "")}, }, - names.AttrStatus: stringSchema(false, enum.Validate[awstypes.Status]()), + names.AttrStatus: stringEnumSchema[awstypes.Status](attrOptional), }, }, } -} +}) -func textConditionalFormatSchema() *schema.Schema { +var textConditionalFormatSchema = sync.OnceValue(func() *schema.Schema { return &schema.Schema{ // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_TextConditionalFormat.html Type: schema.TypeList, Optional: true, @@ -403,7 +404,7 @@ func textConditionalFormatSchema() *schema.Schema { }, }, } -} +}) func expandPivotTableVisual(tfList []interface{}) *awstypes.PivotTableVisual { if len(tfList) == 0 || tfList[0] == nil { diff --git a/internal/service/quicksight/schema/visual_radar_chart.go b/internal/service/quicksight/schema/visual_radar_chart.go index 48514f902d0a..19dfed233964 100644 --- a/internal/service/quicksight/schema/visual_radar_chart.go +++ b/internal/service/quicksight/schema/visual_radar_chart.go @@ -4,12 +4,9 @@ package schema import ( - "github.com/YakDriver/regexache" "github.com/aws/aws-sdk-go-v2/aws" awstypes "github.com/aws/aws-sdk-go-v2/service/quicksight/types" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" - "github.com/hashicorp/terraform-provider-aws/internal/enum" "github.com/hashicorp/terraform-provider-aws/internal/verify" "github.com/hashicorp/terraform-provider-aws/names" ) @@ -31,9 +28,9 @@ func radarChartVisualSchema() *schema.Schema { MaxItems: 1, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "alternate_band_colors_visibility": stringSchema(false, enum.Validate[awstypes.Visibility]()), - "alternate_band_even_color": stringSchema(false, validation.StringMatch(regexache.MustCompile(`^#[0-9A-F]{6}$`), "")), - "alternate_band_odd_color": stringSchema(false, validation.StringMatch(regexache.MustCompile(`^#[0-9A-F]{6}$`), "")), + "alternate_band_colors_visibility": stringEnumSchema[awstypes.Visibility](attrOptional), + "alternate_band_even_color": hexColorSchema(attrOptional), + "alternate_band_odd_color": hexColorSchema(attrOptional), "base_series_settings": { // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_RadarChartSeriesSettings.html Type: schema.TypeList, Optional: true, @@ -48,7 +45,7 @@ func radarChartVisualSchema() *schema.Schema { MaxItems: 1, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "visibility": stringSchema(false, enum.Validate[awstypes.Visibility]()), + "visibility": stringEnumSchema[awstypes.Visibility](attrOptional), }, }, }, @@ -83,7 +80,7 @@ func radarChartVisualSchema() *schema.Schema { }, }, "legend": legendOptionsSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_LegendOptions.html - "shape": stringSchema(false, enum.Validate[awstypes.RadarChartShape]()), + "shape": stringEnumSchema[awstypes.RadarChartShape](attrOptional), "sort_configuration": { // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_RadarChartSortConfiguration.html Type: schema.TypeList, Optional: true, @@ -92,14 +89,14 @@ func radarChartVisualSchema() *schema.Schema { DiffSuppressFunc: verify.SuppressMissingOptionalConfigurationBlock, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "category_items_limit": itemsLimitConfigurationSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_ItemsLimitConfiguration.html - "category_sort": fieldSortOptionsSchema(fieldSortOptionsMaxItems100), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_FieldSortOptions.html, - "color_items_limit": itemsLimitConfigurationSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_ItemsLimitConfiguration.html - "color_sort": fieldSortOptionsSchema(fieldSortOptionsMaxItems100), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_FieldSortOptions.html + "category_items_limit": itemsLimitConfigurationSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_ItemsLimitConfiguration.html + "category_sort": fieldSortOptionsSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_FieldSortOptions.html, + "color_items_limit": itemsLimitConfigurationSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_ItemsLimitConfiguration.html + "color_sort": fieldSortOptionsSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_FieldSortOptions.html }, }, }, - "start_angle": floatSchema(false, validation.FloatBetween(-360, 360)), + "start_angle": floatBetweenSchema(attrOptional, -360, 360), "visual_palette": visualPaletteSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_VisualPalette.html }, }, diff --git a/internal/service/quicksight/schema/visual_sankey_diagram.go b/internal/service/quicksight/schema/visual_sankey_diagram.go index 56d1e2ccdc32..43b03f8e3f2b 100644 --- a/internal/service/quicksight/schema/visual_sankey_diagram.go +++ b/internal/service/quicksight/schema/visual_sankey_diagram.go @@ -60,9 +60,9 @@ func sankeyDiagramVisualSchema() *schema.Schema { DiffSuppressFunc: verify.SuppressMissingOptionalConfigurationBlock, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "destination_items_limit": itemsLimitConfigurationSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_ItemsLimitConfiguration.html - "source_items_limit": itemsLimitConfigurationSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_ItemsLimitConfiguration.html - "weight_sort": fieldSortOptionsSchema(fieldSortOptionsMaxItems100), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_FieldSortOptions.html + "destination_items_limit": itemsLimitConfigurationSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_ItemsLimitConfiguration.html + "source_items_limit": itemsLimitConfigurationSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_ItemsLimitConfiguration.html + "weight_sort": fieldSortOptionsSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_FieldSortOptions.html }, }, }, diff --git a/internal/service/quicksight/schema/visual_sort.go b/internal/service/quicksight/schema/visual_sort.go index 2c48915c8cb5..c412931721fa 100644 --- a/internal/service/quicksight/schema/visual_sort.go +++ b/internal/service/quicksight/schema/visual_sort.go @@ -4,21 +4,21 @@ package schema import ( + "sync" + "github.com/aws/aws-sdk-go-v2/aws" awstypes "github.com/aws/aws-sdk-go-v2/service/quicksight/types" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" - "github.com/hashicorp/terraform-provider-aws/internal/enum" ) const fieldSortOptionsMaxItems100 = 100 -func fieldSortOptionsSchema(maxItems int) *schema.Schema { +var fieldSortOptionsSchema = sync.OnceValue(func() *schema.Schema { return &schema.Schema{ // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_FieldSortOptions.html Type: schema.TypeList, Optional: true, MinItems: 1, - MaxItems: maxItems, + MaxItems: fieldSortOptionsMaxItems100, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ "column_sort": columnSortSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_ColumnSort.html @@ -26,9 +26,9 @@ func fieldSortOptionsSchema(maxItems int) *schema.Schema { }, }, } -} +}) -func columnSortSchema() *schema.Schema { +var columnSortSchema = sync.OnceValue(func() *schema.Schema { return &schema.Schema{ // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_ColumnSort.html Type: schema.TypeList, Optional: true, @@ -36,15 +36,15 @@ func columnSortSchema() *schema.Schema { MaxItems: 1, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "direction": stringSchema(true, enum.Validate[awstypes.SortDirection]()), + "direction": stringEnumSchema[awstypes.SortDirection](attrRequired), "sort_by": columnSchema(true), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_ColumnIdentifier.html "aggregation_function": aggregationFunctionSchema(false), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_AggregationFunction.html }, }, } -} +}) -func fieldSortSchema() *schema.Schema { +var fieldSortSchema = sync.OnceValue(func() *schema.Schema { return &schema.Schema{ // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_FieldSort.html Type: schema.TypeList, Optional: true, @@ -52,12 +52,12 @@ func fieldSortSchema() *schema.Schema { MaxItems: 1, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "direction": stringSchema(true, enum.Validate[awstypes.SortDirection]()), - "field_id": stringSchema(true, validation.StringLenBetween(1, 512)), + "direction": stringEnumSchema[awstypes.SortDirection](attrRequired), + "field_id": stringLenBetweenSchema(attrRequired, 1, 512), }, }, } -} +}) func expandFieldSortOptionsList(tfList []interface{}) []awstypes.FieldSortOptions { if len(tfList) == 0 { diff --git a/internal/service/quicksight/schema/visual_table.go b/internal/service/quicksight/schema/visual_table.go index 177e74eb8d07..a019ae3cd590 100644 --- a/internal/service/quicksight/schema/visual_table.go +++ b/internal/service/quicksight/schema/visual_table.go @@ -4,12 +4,10 @@ package schema import ( - "github.com/YakDriver/regexache" "github.com/aws/aws-sdk-go-v2/aws" awstypes "github.com/aws/aws-sdk-go-v2/service/quicksight/types" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" - "github.com/hashicorp/terraform-provider-aws/internal/enum" "github.com/hashicorp/terraform-provider-aws/internal/flex" "github.com/hashicorp/terraform-provider-aws/internal/verify" "github.com/hashicorp/terraform-provider-aws/names" @@ -53,8 +51,8 @@ func tableVisualSchema() *schema.Schema { MaxItems: 100, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "field_id": stringSchema(true, validation.StringLenBetween(1, 512)), - "custom_label": stringSchema(false, validation.StringLenBetween(1, 2048)), + "field_id": stringLenBetweenSchema(attrRequired, 1, 512), + "custom_label": stringLenBetweenSchema(attrOptional, 1, 2048), "url_styling": { // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_TableFieldURLConfiguration.html Type: schema.TypeList, Optional: true, @@ -76,7 +74,7 @@ func tableVisualSchema() *schema.Schema { MaxItems: 1, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "table_cell_image_scaling_configuration": stringSchema(false, enum.Validate[awstypes.TableCellImageScalingConfiguration]()), + "table_cell_image_scaling_configuration": stringEnumSchema[awstypes.TableCellImageScalingConfiguration](attrOptional), }, }, }, @@ -104,7 +102,7 @@ func tableVisualSchema() *schema.Schema { MaxItems: 1, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "icon": stringSchema(false, enum.Validate[awstypes.TableFieldIconSetType]()), + "icon": stringEnumSchema[awstypes.TableFieldIconSetType](attrOptional), }, }, }, @@ -126,14 +124,14 @@ func tableVisualSchema() *schema.Schema { }, }, }, - names.AttrTarget: stringSchema(false, enum.Validate[awstypes.URLTargetConfiguration]()), + names.AttrTarget: stringEnumSchema[awstypes.URLTargetConfiguration](attrOptional), }, }, }, }, }, }, - "visibility": stringSchema(false, enum.Validate[awstypes.Visibility]()), + "visibility": stringEnumSchema[awstypes.Visibility](attrOptional), "width": { Type: schema.TypeString, Optional: true, @@ -178,7 +176,7 @@ func tableVisualSchema() *schema.Schema { Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ "column": columnSchema(true), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_ColumnIdentifier.html - "field_id": stringSchema(true, validation.StringLenBetween(1, 512)), + "field_id": stringLenBetweenSchema(attrRequired, 1, 512), "format_configuration": formatConfigurationSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_FormatConfiguration.html }, }, @@ -196,8 +194,8 @@ func tableVisualSchema() *schema.Schema { MaxItems: 1, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "overflow_column_header_visibility": stringSchema(false, enum.Validate[awstypes.Visibility]()), - "vertical_overflow_visibility": stringSchema(false, enum.Validate[awstypes.Visibility]()), + "overflow_column_header_visibility": stringEnumSchema[awstypes.Visibility](attrOptional), + "vertical_overflow_visibility": stringEnumSchema[awstypes.Visibility](attrOptional), }, }, }, @@ -216,7 +214,7 @@ func tableVisualSchema() *schema.Schema { MaxItems: 1, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "page_number": intSchema(true, validation.IntAtLeast(1)), + "page_number": intAtLeastSchema(attrRequired, 1), "page_size": { Type: schema.TypeInt, Required: true, @@ -224,7 +222,7 @@ func tableVisualSchema() *schema.Schema { }, }, }, - "row_sort": fieldSortOptionsSchema(fieldSortOptionsMaxItems100), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_FieldSortOptions.html + "row_sort": fieldSortOptionsSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_FieldSortOptions.html }, }, }, @@ -242,9 +240,9 @@ func tableVisualSchema() *schema.Schema { MaxItems: 1, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "field_id": stringSchema(true, validation.StringLenBetween(1, 512)), - "negative_color": stringSchema(false, validation.StringMatch(regexache.MustCompile(`^#[0-9A-F]{6}$`), "")), - "positive_color": stringSchema(false, validation.StringMatch(regexache.MustCompile(`^#[0-9A-F]{6}$`), "")), + "field_id": stringLenBetweenSchema(attrRequired, 1, 512), + "negative_color": hexColorSchema(attrOptional), + "positive_color": hexColorSchema(attrOptional), }, }, }, @@ -260,7 +258,7 @@ func tableVisualSchema() *schema.Schema { Schema: map[string]*schema.Schema{ "cell_style": tableCellStyleSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_TableCellStyle.html "header_style": tableCellStyleSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_TableCellStyle.html - "orientation": stringSchema(false, enum.Validate[awstypes.TableOrientation]()), + "orientation": stringEnumSchema[awstypes.TableOrientation](attrOptional), "row_alternate_color_options": rowAlternateColorOptionsSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_RowAlternateColorOptions.html }, }, @@ -276,10 +274,10 @@ func tableVisualSchema() *schema.Schema { Type: schema.TypeString, Optional: true, }, - "placement": stringSchema(false, enum.Validate[awstypes.TableTotalsPlacement]()), - "scroll_status": stringSchema(false, enum.Validate[awstypes.TableTotalsScrollStatus]()), + "placement": stringEnumSchema[awstypes.TableTotalsPlacement](attrOptional), + "scroll_status": stringEnumSchema[awstypes.TableTotalsScrollStatus](attrOptional), "total_cell_style": tableCellStyleSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_TableCellStyle.html - "totals_visibility": stringSchema(false, enum.Validate[awstypes.Visibility]()), + "totals_visibility": stringEnumSchema[awstypes.Visibility](attrOptional), }, }, }, @@ -307,7 +305,7 @@ func tableVisualSchema() *schema.Schema { MaxItems: 1, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "field_id": stringSchema(true, validation.StringLenBetween(1, 512)), + "field_id": stringLenBetweenSchema(attrRequired, 1, 512), "text_format": textConditionalFormatSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_TextConditionalFormat.html }, }, diff --git a/internal/service/quicksight/schema/visual_tree_map.go b/internal/service/quicksight/schema/visual_tree_map.go index 95e27c1a5b5f..cbe19741333e 100644 --- a/internal/service/quicksight/schema/visual_tree_map.go +++ b/internal/service/quicksight/schema/visual_tree_map.go @@ -66,7 +66,7 @@ func treeMapVisualSchema() *schema.Schema { Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ "tree_map_group_items_limit_configuration": itemsLimitConfigurationSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_ItemsLimitConfiguration.html - "tree_map_sort": fieldSortOptionsSchema(fieldSortOptionsMaxItems100), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_FieldSortOptions.html + "tree_map_sort": fieldSortOptionsSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_FieldSortOptions.html }, }, }, diff --git a/internal/service/quicksight/schema/visual_waterfall.go b/internal/service/quicksight/schema/visual_waterfall.go index 14ed00b037ca..1d4a004afa77 100644 --- a/internal/service/quicksight/schema/visual_waterfall.go +++ b/internal/service/quicksight/schema/visual_waterfall.go @@ -65,8 +65,8 @@ func waterfallVisualSchema() *schema.Schema { DiffSuppressFunc: verify.SuppressMissingOptionalConfigurationBlock, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "breakdown_items_limit": itemsLimitConfigurationSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_ItemsLimitConfiguration.html - "category_sort": fieldSortOptionsSchema(fieldSortOptionsMaxItems100), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_FieldSortOptions.html + "breakdown_items_limit": itemsLimitConfigurationSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_ItemsLimitConfiguration.html + "category_sort": fieldSortOptionsSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_FieldSortOptions.html }, }, }, diff --git a/internal/service/quicksight/schema/visual_word_cloud.go b/internal/service/quicksight/schema/visual_word_cloud.go index 879adeb47e73..1d021eea0593 100644 --- a/internal/service/quicksight/schema/visual_word_cloud.go +++ b/internal/service/quicksight/schema/visual_word_cloud.go @@ -7,8 +7,6 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awstypes "github.com/aws/aws-sdk-go-v2/service/quicksight/types" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" - "github.com/hashicorp/terraform-provider-aws/internal/enum" "github.com/hashicorp/terraform-provider-aws/internal/verify" "github.com/hashicorp/terraform-provider-aws/names" ) @@ -61,8 +59,8 @@ func wordCloudVisualSchema() *schema.Schema { DiffSuppressFunc: verify.SuppressMissingOptionalConfigurationBlock, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "category_items_limit": itemsLimitConfigurationSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_ItemsLimitConfiguration.html - "category_sort": fieldSortOptionsSchema(fieldSortOptionsMaxItems100), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_FieldSortOptions.html + "category_items_limit": itemsLimitConfigurationSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_ItemsLimitConfiguration.html + "category_sort": fieldSortOptionsSchema(), // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_FieldSortOptions.html }, }, }, @@ -73,12 +71,12 @@ func wordCloudVisualSchema() *schema.Schema { MaxItems: 1, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "cloud_layout": stringSchema(false, enum.Validate[awstypes.WordCloudCloudLayout]()), - "maximum_string_length": intSchema(false, validation.IntBetween(1, 100)), - "word_casing": stringSchema(false, enum.Validate[awstypes.WordCloudWordCasing]()), - "word_orientation": stringSchema(false, enum.Validate[awstypes.WordCloudWordOrientation]()), - "word_padding": stringSchema(false, enum.Validate[awstypes.WordCloudWordPadding]()), - "word_scaling": stringSchema(false, enum.Validate[awstypes.WordCloudWordScaling]()), + "cloud_layout": stringEnumSchema[awstypes.WordCloudCloudLayout](attrOptional), + "maximum_string_length": intBetweenSchema(attrOptional, 1, 100), + "word_casing": stringEnumSchema[awstypes.WordCloudWordCasing](attrOptional), + "word_orientation": stringEnumSchema[awstypes.WordCloudWordOrientation](attrOptional), + "word_padding": stringEnumSchema[awstypes.WordCloudWordPadding](attrOptional), + "word_scaling": stringEnumSchema[awstypes.WordCloudWordScaling](attrOptional), }, }, },