Skip to content

Commit

Permalink
Merge pull request #39652 from hashicorp/td-quicksight-schema-memory-…
Browse files Browse the repository at this point in the history
…usage

provider: Reduce schema memory usage by 36.2 MB (69.5%)
  • Loading branch information
gdavison authored Oct 15, 2024
2 parents a9e1cd7 + 78db232 commit 68730b2
Show file tree
Hide file tree
Showing 47 changed files with 1,398 additions and 1,349 deletions.
1 change: 1 addition & 0 deletions .actrc
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 4 additions & 0 deletions .ci/.golangci2.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ linters-settings:
- retry.RetryContext
- schema.DefaultTimeout
- validation.*
# QuickSight schema
- floatBetweenSchema
- intBetweenSchema
- stringLenBetweenSchema
# Terraform Plugin Framework
- int32validator.*
- int64validator.*
Expand Down
166 changes: 166 additions & 0 deletions .ci/semgrep/pluginsdk/quicksight/schema.yml
Original file line number Diff line number Diff line change
@@ -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[<type>](<required>)
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
1 change: 1 addition & 0 deletions internal/service/quicksight/ingestion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ func TestAccQuickSightIngestion_basic(t *testing.T) {
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{
"ingestion_status",
"ingestion_type",
},
},
Expand Down
32 changes: 10 additions & 22 deletions internal/service/quicksight/schema/analysis.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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),
},
},
},
Expand All @@ -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),
},
},
},
Expand All @@ -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
Expand All @@ -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
},
},
Expand Down Expand Up @@ -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
},
},
Expand Down
31 changes: 10 additions & 21 deletions internal/service/quicksight/schema/dashboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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),
},
},
},
Expand All @@ -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),
},
},
},
Expand All @@ -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
Expand All @@ -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
},
},
Expand Down Expand Up @@ -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
},
},
Expand Down
Loading

0 comments on commit 68730b2

Please sign in to comment.