From b8ce8404312ec9133d0dc1c82c8e02812260ae36 Mon Sep 17 00:00:00 2001 From: Andrew Tulloch Date: Fri, 28 Jun 2024 15:09:00 +0100 Subject: [PATCH 01/17] skaff datasource --- .../attribute_group_data_source.go | 121 +++++++++++++++ .../attribute_group_data_source_test.go | 142 ++++++++++++++++++ ...gappregistry_attribute_group.html.markdown | 38 +++++ 3 files changed, 301 insertions(+) create mode 100644 internal/service/servicecatalogappregistry/attribute_group_data_source.go create mode 100644 internal/service/servicecatalogappregistry/attribute_group_data_source_test.go create mode 100644 website/docs/d/servicecatalogappregistry_attribute_group.html.markdown diff --git a/internal/service/servicecatalogappregistry/attribute_group_data_source.go b/internal/service/servicecatalogappregistry/attribute_group_data_source.go new file mode 100644 index 00000000000..119ea1ce72f --- /dev/null +++ b/internal/service/servicecatalogappregistry/attribute_group_data_source.go @@ -0,0 +1,121 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +package servicecatalogappregistry + +import ( + "context" + + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/service/servicecatalogappregistry" + awstypes "github.com/aws/aws-sdk-go-v2/service/servicecatalogappregistry/types" + "github.com/hashicorp/terraform-plugin-framework/datasource" + "github.com/hashicorp/terraform-plugin-framework/datasource/schema" + "github.com/hashicorp/terraform-plugin-framework/types" + "github.com/hashicorp/terraform-provider-aws/internal/create" + "github.com/hashicorp/terraform-provider-aws/internal/framework" + "github.com/hashicorp/terraform-provider-aws/internal/framework/flex" + tftags "github.com/hashicorp/terraform-provider-aws/internal/tags" + "github.com/hashicorp/terraform-provider-aws/names" +) + + +// Function annotations are used for datasource registration to the Provider. DO NOT EDIT. +// @FrameworkDataSource(name="Attribute Group") +func newDataSourceAttributeGroup(context.Context) (datasource.DataSourceWithConfigure, error) { + return &dataSourceAttributeGroup{}, nil +} + +const ( + DSNameAttributeGroup = "Attribute Group Data Source" +) + +type dataSourceAttributeGroup struct { + framework.DataSourceWithConfigure +} + +func (d *dataSourceAttributeGroup) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) { // nosemgrep:ci.meta-in-func-name + resp.TypeName = "aws_servicecatalogappregistry_attribute_group" +} + +func (d *dataSourceAttributeGroup) Schema(ctx context.Context, req datasource.SchemaRequest, resp *datasource.SchemaResponse) { + resp.Schema = schema.Schema{ + Attributes: map[string]schema.Attribute{ + "arn": framework.ARNAttributeComputedOnly(), + "description": schema.StringAttribute{ + Computed: true, + }, + "id": framework.IDAttribute(), + "name": schema.StringAttribute{ + Required: true, + }, + names.AttrTags: tftags.TagsAttributeComputedOnly(), + "type": schema.StringAttribute{ + Computed: true, + }, + }, + Blocks: map[string]schema.Block{ + "complex_argument": schema.ListNestedBlock{ + NestedObject: schema.NestedBlockObject{ + Attributes: map[string]schema.Attribute{ + "nested_required": schema.StringAttribute{ + Computed: true, + }, + "nested_computed": schema.StringAttribute{ + Computed: true, + }, + }, + }, + }, + }, + } +} +func (d *dataSourceAttributeGroup) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { + conn := d.Meta().ServiceCatalogAppRegistryClient(ctx) + + var data dataSourceAttributeGroupData + resp.Diagnostics.Append(req.Config.Get(ctx, &data)...) + if resp.Diagnostics.HasError() { + return + } + + out, err := findAttributeGroupByName(ctx, conn, data.Name.ValueString()) + if err != nil { + resp.Diagnostics.AddError( + create.ProblemStandardMessage(names.ServiceCatalogAppRegistry, create.ErrActionReading, DSNameAttributeGroup, data.Name.String(), err), + err.Error(), + ) + return + } + + data.ARN = flex.StringToFramework(ctx, out.Arn) + data.ID = flex.StringToFramework(ctx, out.AttributeGroupId) + data.Name = flex.StringToFramework(ctx, out.AttributeGroupName) + data.Type = flex.StringToFramework(ctx, out.AttributeGroupType) + + complexArgument, diag := flattenComplexArgument(ctx, out.ComplexArgument) + resp.Diagnostics.Append(diag...) + data.ComplexArgument = complexArgument + + ignoreTagsConfig := d.Meta().IgnoreTagsConfig + tags := KeyValueTags(ctx, out.Tags).IgnoreAWS().IgnoreConfig(ignoreTagsConfig) + data.Tags = flex.FlattenFrameworkStringValueMapLegacy(ctx, tags.Map()) + + resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) +} + + +type dataSourceAttributeGroupData struct { + ARN types.String `tfsdk:"arn"` + ComplexArgument types.List `tfsdk:"complex_argument"` + Description types.String `tfsdk:"description"` + ID types.String `tfsdk:"id"` + Name types.String `tfsdk:"name"` + Tags types.Map `tfsdk:"tags"` + Type types.String `tfsdk:"type"` +} + +type complexArgumentData struct { + NestedRequired types.String `tfsdk:"nested_required"` + NestedOptional types.String `tfsdk:"nested_optional"` +} \ No newline at end of file diff --git a/internal/service/servicecatalogappregistry/attribute_group_data_source_test.go b/internal/service/servicecatalogappregistry/attribute_group_data_source_test.go new file mode 100644 index 00000000000..d8a93817b9b --- /dev/null +++ b/internal/service/servicecatalogappregistry/attribute_group_data_source_test.go @@ -0,0 +1,142 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +package servicecatalogappregistry_test + +import ( + "fmt" + "strings" + "testing" + + "github.com/YakDriver/regexache" + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/service/servicecatalogappregistry" + "github.com/aws/aws-sdk-go-v2/service/servicecatalogappregistry/types" + "github.com/hashicorp/aws-sdk-go-base/v2/awsv1shim/v2/tfawserr" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + sdkacctest "github.com/hashicorp/terraform-plugin-testing/helper/acctest" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/terraform" + "github.com/hashicorp/terraform-provider-aws/internal/acctest" + "github.com/hashicorp/terraform-provider-aws/internal/conns" + "github.com/hashicorp/terraform-provider-aws/internal/create" + tfservicecatalogappregistry "github.com/hashicorp/terraform-provider-aws/internal/service/servicecatalogappregistry" + "github.com/hashicorp/terraform-provider-aws/names" +) + + +func TestAttributeGroupExampleUnitTest(t *testing.T) { + t.Parallel() + + testCases := []struct { + TestName string + Input string + Expected string + Error bool + }{ + { + TestName: "empty", + Input: "", + Expected: "", + Error: true, + }, + { + TestName: "descriptive name", + Input: "some input", + Expected: "some output", + Error: false, + }, + { + TestName: "another descriptive name", + Input: "more input", + Expected: "more output", + Error: false, + }, + } + + for _, testCase := range testCases { + testCase := testCase + t.Run(testCase.TestName, func(t *testing.T) { + t.Parallel() + got, err := tfservicecatalogappregistry.FunctionFromDataSource(testCase.Input) + + if err != nil && !testCase.Error { + t.Errorf("got error (%s), expected no error", err) + } + + if err == nil && testCase.Error { + t.Errorf("got (%s) and no error, expected error", got) + } + + if got != testCase.Expected { + t.Errorf("got %s, expected %s", got, testCase.Expected) + } + }) + } +} + +func TestAccServiceCatalogAppRegistryAttributeGroupDataSource_basic(t *testing.T) { + ctx := acctest.Context(t) + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + + var attributegroup servicecatalogappregistry.DescribeAttributeGroupResponse + rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) + dataSourceName := "data.aws_servicecatalogappregistry_attribute_group.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { + acctest.PreCheck(ctx, t) + acctest.PreCheckPartitionHasService(t, names.ServiceCatalogAppRegistryEndpointID) + testAccPreCheck(ctx, t) + }, + ErrorCheck: acctest.ErrorCheck(t, names.ServiceCatalogAppRegistryServiceID), + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + CheckDestroy: testAccCheckAttributeGroupDestroy(ctx), + Steps: []resource.TestStep{ + { + Config: testAccAttributeGroupDataSourceConfig_basic(rName), + Check: resource.ComposeTestCheckFunc( + testAccCheckAttributeGroupExists(ctx, dataSourceName, &attributegroup), + resource.TestCheckResourceAttr(dataSourceName, "auto_minor_version_upgrade", "false"), + resource.TestCheckResourceAttrSet(dataSourceName, "maintenance_window_start_time.0.day_of_week"), + resource.TestCheckTypeSetElemNestedAttrs(dataSourceName, "user.*", map[string]string{ + "console_access": "false", + "groups.#": "0", + "username": "Test", + "password": "TestTest1234", + }), + acctest.MatchResourceAttrRegionalARN(dataSourceName, "arn", "servicecatalogappregistry", regexache.MustCompile(`attributegroup:+.`)), + ), + }, + }, + }) +} + +func testAccAttributeGroupDataSourceConfig_basic(rName, version string) string { + return fmt.Sprintf(` +data "aws_security_group" "test" { + name = %[1]q +} + +data "aws_servicecatalogappregistry_attribute_group" "test" { + attribute_group_name = %[1]q + engine_type = "ActiveServiceCatalogAppRegistry" + engine_version = %[2]q + host_instance_type = "servicecatalogappregistry.t2.micro" + security_groups = [aws_security_group.test.id] + authentication_strategy = "simple" + storage_type = "efs" + + logs { + general = true + } + + user { + username = "Test" + password = "TestTest1234" + } +} +`, rName, version) +} diff --git a/website/docs/d/servicecatalogappregistry_attribute_group.html.markdown b/website/docs/d/servicecatalogappregistry_attribute_group.html.markdown new file mode 100644 index 00000000000..77a125b9b2c --- /dev/null +++ b/website/docs/d/servicecatalogappregistry_attribute_group.html.markdown @@ -0,0 +1,38 @@ +--- +subcategory: "Service Catalog AppRegistry" +layout: "aws" +page_title: "AWS: aws_servicecatalogappregistry_attribute_group" +description: |- + Terraform data source for managing an AWS Service Catalog AppRegistry Attribute Group. +--- + +# Data Source: aws_servicecatalogappregistry_attribute_group + +Terraform data source for managing an AWS Service Catalog AppRegistry Attribute Group. + +## Example Usage + +### Basic Usage + +```terraform +data "aws_servicecatalogappregistry_attribute_group" "example" { +} +``` + +## Argument Reference + +The following arguments are required: + +* `example_arg` - (Required) Concise argument description. Do not begin the description with "An", "The", "Defines", "Indicates", or "Specifies," as these are verbose. In other words, "Indicates the amount of storage," can be rewritten as "Amount of storage," without losing any information. + +The following arguments are optional: + +* `optional_arg` - (Optional) Concise argument description. Do not begin the description with "An", "The", "Defines", "Indicates", or "Specifies," as these are verbose. In other words, "Indicates the amount of storage," can be rewritten as "Amount of storage," without losing any information. + +## Attribute Reference + +This data source exports the following attributes in addition to the arguments above: + +* `arn` - ARN of the Attribute Group. Do not begin the description with "An", "The", "Defines", "Indicates", or "Specifies," as these are verbose. In other words, "Indicates the amount of storage," can be rewritten as "Amount of storage," without losing any information. +* `example_attribute` - Concise description. Do not begin the description with "An", "The", "Defines", "Indicates", or "Specifies," as these are verbose. In other words, "Indicates the amount of storage," can be rewritten as "Amount of storage," without losing any information. +* `tags` - Mapping of Key-Value tags for the resource. \ No newline at end of file From 371cd6679ab403def877d81a8a394e454aee69db Mon Sep 17 00:00:00 2001 From: Andrew Tulloch Date: Fri, 28 Jun 2024 19:30:31 +0100 Subject: [PATCH 02/17] Get this running and the tests --- .../attribute_group_data_source.go | 91 ++++++-------- .../attribute_group_data_source_test.go | 113 ++++-------------- .../service_package_gen.go | 4 + 3 files changed, 61 insertions(+), 147 deletions(-) diff --git a/internal/service/servicecatalogappregistry/attribute_group_data_source.go b/internal/service/servicecatalogappregistry/attribute_group_data_source.go index 119ea1ce72f..edb6066696d 100644 --- a/internal/service/servicecatalogappregistry/attribute_group_data_source.go +++ b/internal/service/servicecatalogappregistry/attribute_group_data_source.go @@ -5,12 +5,11 @@ package servicecatalogappregistry import ( "context" - - "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/service/servicecatalogappregistry" - awstypes "github.com/aws/aws-sdk-go-v2/service/servicecatalogappregistry/types" + "github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator" "github.com/hashicorp/terraform-plugin-framework/datasource" "github.com/hashicorp/terraform-plugin-framework/datasource/schema" + "github.com/hashicorp/terraform-plugin-framework/path" + "github.com/hashicorp/terraform-plugin-framework/schema/validator" "github.com/hashicorp/terraform-plugin-framework/types" "github.com/hashicorp/terraform-provider-aws/internal/create" "github.com/hashicorp/terraform-provider-aws/internal/framework" @@ -19,9 +18,8 @@ import ( "github.com/hashicorp/terraform-provider-aws/names" ) - // Function annotations are used for datasource registration to the Provider. DO NOT EDIT. -// @FrameworkDataSource(name="Attribute Group") +// @FrameworkDataSource("aws_servicecatalogappregistry_attribute_group", name="Attribute Group") func newDataSourceAttributeGroup(context.Context) (datasource.DataSourceWithConfigure, error) { return &dataSourceAttributeGroup{}, nil } @@ -41,45 +39,41 @@ func (d *dataSourceAttributeGroup) Metadata(_ context.Context, req datasource.Me func (d *dataSourceAttributeGroup) Schema(ctx context.Context, req datasource.SchemaRequest, resp *datasource.SchemaResponse) { resp.Schema = schema.Schema{ Attributes: map[string]schema.Attribute{ - "arn": framework.ARNAttributeComputedOnly(), - "description": schema.StringAttribute{ + names.AttrARN: framework.ARNAttributeComputedOnly(), + names.AttrAttributes: schema.StringAttribute{ Computed: true, }, - "id": framework.IDAttribute(), - "name": schema.StringAttribute{ - Required: true, + names.AttrDescription: schema.StringAttribute{ + Optional: true, }, - names.AttrTags: tftags.TagsAttributeComputedOnly(), - "type": schema.StringAttribute{ + names.AttrID: schema.StringAttribute{ + Optional: true, Computed: true, - }, - }, - Blocks: map[string]schema.Block{ - "complex_argument": schema.ListNestedBlock{ - NestedObject: schema.NestedBlockObject{ - Attributes: map[string]schema.Attribute{ - "nested_required": schema.StringAttribute{ - Computed: true, - }, - "nested_computed": schema.StringAttribute{ - Computed: true, - }, - }, + Validators: []validator.String{ + stringvalidator.AtLeastOneOf(path.Expressions{ + path.MatchRoot(names.AttrName), + }...), }, }, + names.AttrName: schema.StringAttribute{ + Optional: true, + Computed: true, + }, + names.AttrTags: tftags.TagsAttribute(), }, } } + func (d *dataSourceAttributeGroup) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { conn := d.Meta().ServiceCatalogAppRegistryClient(ctx) - + var data dataSourceAttributeGroupData resp.Diagnostics.Append(req.Config.Get(ctx, &data)...) if resp.Diagnostics.HasError() { return } - - out, err := findAttributeGroupByName(ctx, conn, data.Name.ValueString()) + + out, err := findAttributeGroupByID(ctx, conn, data.Name.ValueString()) if err != nil { resp.Diagnostics.AddError( create.ProblemStandardMessage(names.ServiceCatalogAppRegistry, create.ErrActionReading, DSNameAttributeGroup, data.Name.String(), err), @@ -87,35 +81,20 @@ func (d *dataSourceAttributeGroup) Read(ctx context.Context, req datasource.Read ) return } - - data.ARN = flex.StringToFramework(ctx, out.Arn) - data.ID = flex.StringToFramework(ctx, out.AttributeGroupId) - data.Name = flex.StringToFramework(ctx, out.AttributeGroupName) - data.Type = flex.StringToFramework(ctx, out.AttributeGroupType) - - complexArgument, diag := flattenComplexArgument(ctx, out.ComplexArgument) - resp.Diagnostics.Append(diag...) - data.ComplexArgument = complexArgument - - ignoreTagsConfig := d.Meta().IgnoreTagsConfig - tags := KeyValueTags(ctx, out.Tags).IgnoreAWS().IgnoreConfig(ignoreTagsConfig) - data.Tags = flex.FlattenFrameworkStringValueMapLegacy(ctx, tags.Map()) - + + resp.Diagnostics.Append(flex.Flatten(ctx, out, &data)...) + if resp.Diagnostics.HasError() { + return + } + resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) } - type dataSourceAttributeGroupData struct { - ARN types.String `tfsdk:"arn"` - ComplexArgument types.List `tfsdk:"complex_argument"` - Description types.String `tfsdk:"description"` - ID types.String `tfsdk:"id"` - Name types.String `tfsdk:"name"` - Tags types.Map `tfsdk:"tags"` - Type types.String `tfsdk:"type"` + ARN types.String `tfsdk:"arn"` + Attributes types.String `tfsdk:"attributes"` + Description types.String `tfsdk:"description"` + ID types.String `tfsdk:"id"` + Name types.String `tfsdk:"name"` + Tags types.Map `tfsdk:"tags"` } - -type complexArgumentData struct { - NestedRequired types.String `tfsdk:"nested_required"` - NestedOptional types.String `tfsdk:"nested_optional"` -} \ No newline at end of file diff --git a/internal/service/servicecatalogappregistry/attribute_group_data_source_test.go b/internal/service/servicecatalogappregistry/attribute_group_data_source_test.go index d8a93817b9b..2d6656b0406 100644 --- a/internal/service/servicecatalogappregistry/attribute_group_data_source_test.go +++ b/internal/service/servicecatalogappregistry/attribute_group_data_source_test.go @@ -5,84 +5,26 @@ package servicecatalogappregistry_test import ( "fmt" - "strings" "testing" "github.com/YakDriver/regexache" - "github.com/aws/aws-sdk-go-v2/aws" "github.com/aws/aws-sdk-go-v2/service/servicecatalogappregistry" - "github.com/aws/aws-sdk-go-v2/service/servicecatalogappregistry/types" - "github.com/hashicorp/aws-sdk-go-base/v2/awsv1shim/v2/tfawserr" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" sdkacctest "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" - "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/hashicorp/terraform-provider-aws/internal/acctest" - "github.com/hashicorp/terraform-provider-aws/internal/conns" - "github.com/hashicorp/terraform-provider-aws/internal/create" - tfservicecatalogappregistry "github.com/hashicorp/terraform-provider-aws/internal/service/servicecatalogappregistry" "github.com/hashicorp/terraform-provider-aws/names" ) - -func TestAttributeGroupExampleUnitTest(t *testing.T) { - t.Parallel() - - testCases := []struct { - TestName string - Input string - Expected string - Error bool - }{ - { - TestName: "empty", - Input: "", - Expected: "", - Error: true, - }, - { - TestName: "descriptive name", - Input: "some input", - Expected: "some output", - Error: false, - }, - { - TestName: "another descriptive name", - Input: "more input", - Expected: "more output", - Error: false, - }, - } - - for _, testCase := range testCases { - testCase := testCase - t.Run(testCase.TestName, func(t *testing.T) { - t.Parallel() - got, err := tfservicecatalogappregistry.FunctionFromDataSource(testCase.Input) - - if err != nil && !testCase.Error { - t.Errorf("got error (%s), expected no error", err) - } - - if err == nil && testCase.Error { - t.Errorf("got (%s) and no error, expected error", got) - } - - if got != testCase.Expected { - t.Errorf("got %s, expected %s", got, testCase.Expected) - } - }) - } -} - func TestAccServiceCatalogAppRegistryAttributeGroupDataSource_basic(t *testing.T) { ctx := acctest.Context(t) if testing.Short() { t.Skip("skipping long-running test in short mode") } - var attributegroup servicecatalogappregistry.DescribeAttributeGroupResponse + var attributegroup servicecatalogappregistry.GetAttributeGroupOutput rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) + rDesc := "Simple Description" + expectJsonV1 := `{"a":"1","b":"2"}` dataSourceName := "data.aws_servicecatalogappregistry_attribute_group.test" resource.ParallelTest(t, resource.TestCase{ @@ -96,47 +38,36 @@ func TestAccServiceCatalogAppRegistryAttributeGroupDataSource_basic(t *testing.T CheckDestroy: testAccCheckAttributeGroupDestroy(ctx), Steps: []resource.TestStep{ { - Config: testAccAttributeGroupDataSourceConfig_basic(rName), + Config: testAccAttributeGroupDataSourceConfig_basic(rName, rDesc), Check: resource.ComposeTestCheckFunc( testAccCheckAttributeGroupExists(ctx, dataSourceName, &attributegroup), - resource.TestCheckResourceAttr(dataSourceName, "auto_minor_version_upgrade", "false"), - resource.TestCheckResourceAttrSet(dataSourceName, "maintenance_window_start_time.0.day_of_week"), - resource.TestCheckTypeSetElemNestedAttrs(dataSourceName, "user.*", map[string]string{ - "console_access": "false", - "groups.#": "0", - "username": "Test", - "password": "TestTest1234", - }), - acctest.MatchResourceAttrRegionalARN(dataSourceName, "arn", "servicecatalogappregistry", regexache.MustCompile(`attributegroup:+.`)), + resource.TestCheckResourceAttr(dataSourceName, names.AttrName, rName), + resource.TestCheckResourceAttr(dataSourceName, names.AttrDescription, rDesc), + resource.TestCheckResourceAttr(dataSourceName, names.AttrAttributes, expectJsonV1), + acctest.MatchResourceAttrRegionalARN(dataSourceName, names.AttrARN, "servicecatalog", regexache.MustCompile(`/attribute-groups/+.`)), ), }, }, }) } -func testAccAttributeGroupDataSourceConfig_basic(rName, version string) string { +func testAccAttributeGroupDataSourceConfig_basic(rName, description string) string { return fmt.Sprintf(` -data "aws_security_group" "test" { - name = %[1]q -} - data "aws_servicecatalogappregistry_attribute_group" "test" { - attribute_group_name = %[1]q - engine_type = "ActiveServiceCatalogAppRegistry" - engine_version = %[2]q - host_instance_type = "servicecatalogappregistry.t2.micro" - security_groups = [aws_security_group.test.id] - authentication_strategy = "simple" - storage_type = "efs" - - logs { - general = true - } + name = aws_servicecatalogappregistry_attribute_group.test.name +} - user { - username = "Test" - password = "TestTest1234" +resource "aws_servicecatalogappregistry_attribute_group" "test" { + name = %[1]q + description = %[2]q + attributes = jsonencode({ + a = "1" + b = "2" + }) + tags = { + tag1 = "v1" + tag2 = "v2" } } -`, rName, version) +`, rName, description) } diff --git a/internal/service/servicecatalogappregistry/service_package_gen.go b/internal/service/servicecatalogappregistry/service_package_gen.go index d36b197a62b..9e71d1bc162 100644 --- a/internal/service/servicecatalogappregistry/service_package_gen.go +++ b/internal/service/servicecatalogappregistry/service_package_gen.go @@ -20,6 +20,10 @@ func (p *servicePackage) FrameworkDataSources(ctx context.Context) []*types.Serv Factory: newDataSourceApplication, Name: "Application", }, + { + Factory: newDataSourceAttributeGroup, + Name: "Attribute Group", + }, } } From 8f99ef18fdc111c1e21b763c75debf648fc7041f Mon Sep 17 00:00:00 2001 From: Andrew Tulloch Date: Fri, 28 Jun 2024 19:43:03 +0100 Subject: [PATCH 03/17] add docs --- ...cecatalogappregistry_attribute_group.html.markdown | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/website/docs/d/servicecatalogappregistry_attribute_group.html.markdown b/website/docs/d/servicecatalogappregistry_attribute_group.html.markdown index 77a125b9b2c..bc0cddf4f3f 100644 --- a/website/docs/d/servicecatalogappregistry_attribute_group.html.markdown +++ b/website/docs/d/servicecatalogappregistry_attribute_group.html.markdown @@ -16,6 +16,7 @@ Terraform data source for managing an AWS Service Catalog AppRegistry Attribute ```terraform data "aws_servicecatalogappregistry_attribute_group" "example" { + name = "example_attribute_group" } ``` @@ -23,16 +24,16 @@ data "aws_servicecatalogappregistry_attribute_group" "example" { The following arguments are required: -* `example_arg` - (Required) Concise argument description. Do not begin the description with "An", "The", "Defines", "Indicates", or "Specifies," as these are verbose. In other words, "Indicates the amount of storage," can be rewritten as "Amount of storage," without losing any information. The following arguments are optional: -* `optional_arg` - (Optional) Concise argument description. Do not begin the description with "An", "The", "Defines", "Indicates", or "Specifies," as these are verbose. In other words, "Indicates the amount of storage," can be rewritten as "Amount of storage," without losing any information. +* `id` - (Optional) ID of the Attribute Group to find. +* `name` - (Optional) Name of the Attribute Group to find. ## Attribute Reference This data source exports the following attributes in addition to the arguments above: -* `arn` - ARN of the Attribute Group. Do not begin the description with "An", "The", "Defines", "Indicates", or "Specifies," as these are verbose. In other words, "Indicates the amount of storage," can be rewritten as "Amount of storage," without losing any information. -* `example_attribute` - Concise description. Do not begin the description with "An", "The", "Defines", "Indicates", or "Specifies," as these are verbose. In other words, "Indicates the amount of storage," can be rewritten as "Amount of storage," without losing any information. -* `tags` - Mapping of Key-Value tags for the resource. \ No newline at end of file +* `attributes` - A JSON string of nested key-value pairs that represents the attributes of the group. +* `description` - Description of the Attribute Group. +* `tags` - A map of tags assigned to the Attribute Group. If configured with a provider [`default_tags` configuration block](https://registry.terraform.io/providers/hashicorp/aws/latest/docs#default_tags-configuration-block) present, tags with matching keys will overwrite those defined at the provider-level. From d28241ae1725407be0d5257be7dc05f69d1b0c9c Mon Sep 17 00:00:00 2001 From: Andrew Tulloch Date: Wed, 3 Jul 2024 15:21:06 +0100 Subject: [PATCH 04/17] Sort Tags --- .../attribute_group_data_source.go | 23 +++++++--- ...tribute_group_data_source_tags_gen_test.go | 44 +++++++++++++++++++ .../service_package_gen.go | 3 ++ .../AttributeGroup/data.tags/main_gen.tf | 30 +++++++++++++ .../tmpl/attribute_group_data_source.gtpl | 3 ++ 5 files changed, 98 insertions(+), 5 deletions(-) create mode 100644 internal/service/servicecatalogappregistry/attribute_group_data_source_tags_gen_test.go create mode 100644 internal/service/servicecatalogappregistry/testdata/AttributeGroup/data.tags/main_gen.tf create mode 100644 internal/service/servicecatalogappregistry/testdata/tmpl/attribute_group_data_source.gtpl diff --git a/internal/service/servicecatalogappregistry/attribute_group_data_source.go b/internal/service/servicecatalogappregistry/attribute_group_data_source.go index edb6066696d..535f8027fdc 100644 --- a/internal/service/servicecatalogappregistry/attribute_group_data_source.go +++ b/internal/service/servicecatalogappregistry/attribute_group_data_source.go @@ -20,6 +20,7 @@ import ( // Function annotations are used for datasource registration to the Provider. DO NOT EDIT. // @FrameworkDataSource("aws_servicecatalogappregistry_attribute_group", name="Attribute Group") +// @Tags(identifierAttribute="arn") func newDataSourceAttributeGroup(context.Context) (datasource.DataSourceWithConfigure, error) { return &dataSourceAttributeGroup{}, nil } @@ -50,22 +51,21 @@ func (d *dataSourceAttributeGroup) Schema(ctx context.Context, req datasource.Sc Optional: true, Computed: true, Validators: []validator.String{ - stringvalidator.AtLeastOneOf(path.Expressions{ - path.MatchRoot(names.AttrName), - }...), + stringvalidator.AtLeastOneOf(path.MatchRoot(names.AttrName), path.MatchRoot(names.AttrARN)), }, }, names.AttrName: schema.StringAttribute{ Optional: true, Computed: true, }, - names.AttrTags: tftags.TagsAttribute(), + names.AttrTags: tftags.TagsAttributeComputedOnly(), }, } } func (d *dataSourceAttributeGroup) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { conn := d.Meta().ServiceCatalogAppRegistryClient(ctx) + ignoreTagsConfig := d.Meta().IgnoreTagsConfig var data dataSourceAttributeGroupData resp.Diagnostics.Append(req.Config.Get(ctx, &data)...) @@ -73,7 +73,17 @@ func (d *dataSourceAttributeGroup) Read(ctx context.Context, req datasource.Read return } - out, err := findAttributeGroupByID(ctx, conn, data.Name.ValueString()) + var id string + + if !data.ID.IsNull() { + id = data.ID.ValueString() + } else if !data.Name.IsNull() { + id = data.Name.ValueString() + } else if !data.ARN.IsNull() { + id = data.ARN.ValueString() + } + + out, err := findAttributeGroupByID(ctx, conn, id) if err != nil { resp.Diagnostics.AddError( create.ProblemStandardMessage(names.ServiceCatalogAppRegistry, create.ErrActionReading, DSNameAttributeGroup, data.Name.String(), err), @@ -87,6 +97,9 @@ func (d *dataSourceAttributeGroup) Read(ctx context.Context, req datasource.Read return } + // Transparent tagging doesn't work for DataSource yet + data.Tags = flex.FlattenFrameworkStringValueMapLegacy(ctx, KeyValueTags(ctx, out.Tags).IgnoreAWS().IgnoreConfig(ignoreTagsConfig).Map()) + resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) } diff --git a/internal/service/servicecatalogappregistry/attribute_group_data_source_tags_gen_test.go b/internal/service/servicecatalogappregistry/attribute_group_data_source_tags_gen_test.go new file mode 100644 index 00000000000..0391847d4c4 --- /dev/null +++ b/internal/service/servicecatalogappregistry/attribute_group_data_source_tags_gen_test.go @@ -0,0 +1,44 @@ +// Code generated by internal/generate/tagstests/main.go; DO NOT EDIT. + +package servicecatalogappregistry_test + +import ( + "testing" + + "github.com/hashicorp/terraform-plugin-testing/config" + sdkacctest "github.com/hashicorp/terraform-plugin-testing/helper/acctest" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/knownvalue" + "github.com/hashicorp/terraform-plugin-testing/statecheck" + "github.com/hashicorp/terraform-plugin-testing/tfjsonpath" + "github.com/hashicorp/terraform-provider-aws/internal/acctest" + "github.com/hashicorp/terraform-provider-aws/names" +) + +func TestAccServiceCatalogAppRegistryAttributeGroupDataSource_tags(t *testing.T) { + ctx := acctest.Context(t) + dataSourceName := "data.aws_servicecatalogappregistry_attribute_group.test" + rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acctest.PreCheck(ctx, t) }, + ErrorCheck: acctest.ErrorCheck(t, names.ServiceCatalogAppRegistryServiceID), + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + Steps: []resource.TestStep{ + { + ConfigDirectory: config.StaticDirectory("testdata/AttributeGroup/data.tags/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ + acctest.CtKey1: config.StringVariable(acctest.CtValue1), + }), + }, + ConfigStateChecks: []statecheck.StateCheck{ + statecheck.ExpectKnownValue(dataSourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), + })), + }, + }, + }, + }) +} diff --git a/internal/service/servicecatalogappregistry/service_package_gen.go b/internal/service/servicecatalogappregistry/service_package_gen.go index 9e71d1bc162..70d5bb305e4 100644 --- a/internal/service/servicecatalogappregistry/service_package_gen.go +++ b/internal/service/servicecatalogappregistry/service_package_gen.go @@ -23,6 +23,9 @@ func (p *servicePackage) FrameworkDataSources(ctx context.Context) []*types.Serv { Factory: newDataSourceAttributeGroup, Name: "Attribute Group", + Tags: &types.ServicePackageResourceTags{ + IdentifierAttribute: names.AttrARN, + }, }, } } diff --git a/internal/service/servicecatalogappregistry/testdata/AttributeGroup/data.tags/main_gen.tf b/internal/service/servicecatalogappregistry/testdata/AttributeGroup/data.tags/main_gen.tf new file mode 100644 index 00000000000..92e98274b85 --- /dev/null +++ b/internal/service/servicecatalogappregistry/testdata/AttributeGroup/data.tags/main_gen.tf @@ -0,0 +1,30 @@ +# Copyright (c) HashiCorp, Inc. +# SPDX-License-Identifier: MPL-2.0 + +data "aws_servicecatalogappregistry_attribute_group" "test" { + id = aws_servicecatalogappregistry_attribute_group.test.id +} +resource "aws_servicecatalogappregistry_attribute_group" "test" { + name = var.rName + description = "Some attribute group" + + attributes = jsonencode({ + a = "1" + b = "2" + }) + + tags = var.resource_tags +} + +variable "rName" { + description = "Name for resource" + type = string + nullable = false +} + +variable "resource_tags" { + description = "Tags to set on resource. To specify no tags, set to `null`" + # Not setting a default, so that this must explicitly be set to `null` to specify no tags + type = map(string) + nullable = true +} diff --git a/internal/service/servicecatalogappregistry/testdata/tmpl/attribute_group_data_source.gtpl b/internal/service/servicecatalogappregistry/testdata/tmpl/attribute_group_data_source.gtpl new file mode 100644 index 00000000000..ce3a8faa16a --- /dev/null +++ b/internal/service/servicecatalogappregistry/testdata/tmpl/attribute_group_data_source.gtpl @@ -0,0 +1,3 @@ +data "aws_servicecatalogappregistry_attribute_group" "test" { + id = aws_servicecatalogappregistry_attribute_group.test.id +} \ No newline at end of file From a9ceda86f6c39a3299f754a65c309a95c7efe0d5 Mon Sep 17 00:00:00 2001 From: Andrew Tulloch Date: Wed, 3 Jul 2024 15:24:06 +0100 Subject: [PATCH 05/17] Fix test formatting --- .../attribute_group_data_source_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/service/servicecatalogappregistry/attribute_group_data_source_test.go b/internal/service/servicecatalogappregistry/attribute_group_data_source_test.go index 2d6656b0406..5bb142c9745 100644 --- a/internal/service/servicecatalogappregistry/attribute_group_data_source_test.go +++ b/internal/service/servicecatalogappregistry/attribute_group_data_source_test.go @@ -54,7 +54,7 @@ func TestAccServiceCatalogAppRegistryAttributeGroupDataSource_basic(t *testing.T func testAccAttributeGroupDataSourceConfig_basic(rName, description string) string { return fmt.Sprintf(` data "aws_servicecatalogappregistry_attribute_group" "test" { - name = aws_servicecatalogappregistry_attribute_group.test.name + name = aws_servicecatalogappregistry_attribute_group.test.name } resource "aws_servicecatalogappregistry_attribute_group" "test" { From c6a3bc05c5e2ed9332f63e8c82ef7e8d0dc355be Mon Sep 17 00:00:00 2001 From: Andrew Tulloch Date: Wed, 3 Jul 2024 16:03:15 +0100 Subject: [PATCH 06/17] Formatting --- .../d/servicecatalogappregistry_attribute_group.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/docs/d/servicecatalogappregistry_attribute_group.html.markdown b/website/docs/d/servicecatalogappregistry_attribute_group.html.markdown index bc0cddf4f3f..094f4f37c93 100644 --- a/website/docs/d/servicecatalogappregistry_attribute_group.html.markdown +++ b/website/docs/d/servicecatalogappregistry_attribute_group.html.markdown @@ -24,11 +24,11 @@ data "aws_servicecatalogappregistry_attribute_group" "example" { The following arguments are required: - The following arguments are optional: * `id` - (Optional) ID of the Attribute Group to find. * `name` - (Optional) Name of the Attribute Group to find. +* `arn` - (Optional) ARN of the Attribute Group to find. ## Attribute Reference From f3e697d7105dbdc05092fea3e4cd93be69d90b65 Mon Sep 17 00:00:00 2001 From: Andrew Tulloch Date: Wed, 3 Jul 2024 16:08:03 +0100 Subject: [PATCH 07/17] Imports --- .../servicecatalogappregistry/attribute_group_data_source.go | 1 + 1 file changed, 1 insertion(+) diff --git a/internal/service/servicecatalogappregistry/attribute_group_data_source.go b/internal/service/servicecatalogappregistry/attribute_group_data_source.go index 535f8027fdc..1cee4585a80 100644 --- a/internal/service/servicecatalogappregistry/attribute_group_data_source.go +++ b/internal/service/servicecatalogappregistry/attribute_group_data_source.go @@ -5,6 +5,7 @@ package servicecatalogappregistry import ( "context" + "github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator" "github.com/hashicorp/terraform-plugin-framework/datasource" "github.com/hashicorp/terraform-plugin-framework/datasource/schema" From bfe98f6a4024cc8f10056e6fd8bd543e81b8a3f6 Mon Sep 17 00:00:00 2001 From: Andrew Tulloch Date: Fri, 5 Jul 2024 11:06:11 +0100 Subject: [PATCH 08/17] Add releas notes --- .changelog/38188.txt | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .changelog/38188.txt diff --git a/.changelog/38188.txt b/.changelog/38188.txt new file mode 100644 index 00000000000..e91e3cae75e --- /dev/null +++ b/.changelog/38188.txt @@ -0,0 +1,3 @@ +```release-note:new-data-source +aws_servicecatalogappregistry_attribute_group +``` \ No newline at end of file From dc17e79d79089593d2c4eb42d1bfae87c564aa14 Mon Sep 17 00:00:00 2001 From: Andrew Tulloch Date: Mon, 8 Jul 2024 10:58:28 +0100 Subject: [PATCH 09/17] Use Normalized JSON type --- .../attribute_group_data_source.go | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/internal/service/servicecatalogappregistry/attribute_group_data_source.go b/internal/service/servicecatalogappregistry/attribute_group_data_source.go index 1cee4585a80..ecabdd3cfdd 100644 --- a/internal/service/servicecatalogappregistry/attribute_group_data_source.go +++ b/internal/service/servicecatalogappregistry/attribute_group_data_source.go @@ -5,6 +5,7 @@ package servicecatalogappregistry import ( "context" + "github.com/hashicorp/terraform-plugin-framework-jsontypes/jsontypes" "github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator" "github.com/hashicorp/terraform-plugin-framework/datasource" @@ -43,7 +44,8 @@ func (d *dataSourceAttributeGroup) Schema(ctx context.Context, req datasource.Sc Attributes: map[string]schema.Attribute{ names.AttrARN: framework.ARNAttributeComputedOnly(), names.AttrAttributes: schema.StringAttribute{ - Computed: true, + Computed: true, + CustomType: jsontypes.NormalizedType{}, }, names.AttrDescription: schema.StringAttribute{ Optional: true, @@ -105,10 +107,10 @@ func (d *dataSourceAttributeGroup) Read(ctx context.Context, req datasource.Read } type dataSourceAttributeGroupData struct { - ARN types.String `tfsdk:"arn"` - Attributes types.String `tfsdk:"attributes"` - Description types.String `tfsdk:"description"` - ID types.String `tfsdk:"id"` - Name types.String `tfsdk:"name"` - Tags types.Map `tfsdk:"tags"` + ARN types.String `tfsdk:"arn"` + Attributes jsontypes.Normalized `tfsdk:"attributes"` + Description types.String `tfsdk:"description"` + ID types.String `tfsdk:"id"` + Name types.String `tfsdk:"name"` + Tags types.Map `tfsdk:"tags"` } From e9c5e3fdf139c5215704a5ff1bd5523fbaa7c996 Mon Sep 17 00:00:00 2001 From: Andrew Tulloch Date: Mon, 8 Jul 2024 17:17:58 +0100 Subject: [PATCH 10/17] Fix imports --- .../servicecatalogappregistry/attribute_group_data_source.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/service/servicecatalogappregistry/attribute_group_data_source.go b/internal/service/servicecatalogappregistry/attribute_group_data_source.go index ecabdd3cfdd..c8bc9b20944 100644 --- a/internal/service/servicecatalogappregistry/attribute_group_data_source.go +++ b/internal/service/servicecatalogappregistry/attribute_group_data_source.go @@ -5,8 +5,8 @@ package servicecatalogappregistry import ( "context" - "github.com/hashicorp/terraform-plugin-framework-jsontypes/jsontypes" + "github.com/hashicorp/terraform-plugin-framework-jsontypes/jsontypes" "github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator" "github.com/hashicorp/terraform-plugin-framework/datasource" "github.com/hashicorp/terraform-plugin-framework/datasource/schema" From de35889ed5fcc31a1e996d2c0a16e39bd6cd0174 Mon Sep 17 00:00:00 2001 From: Andrew Tulloch Date: Fri, 29 Nov 2024 14:47:14 +0000 Subject: [PATCH 11/17] Update to add ctx arg --- .../attribute_group_data_source_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/service/servicecatalogappregistry/attribute_group_data_source_test.go b/internal/service/servicecatalogappregistry/attribute_group_data_source_test.go index 5bb142c9745..f7667733f98 100644 --- a/internal/service/servicecatalogappregistry/attribute_group_data_source_test.go +++ b/internal/service/servicecatalogappregistry/attribute_group_data_source_test.go @@ -44,7 +44,7 @@ func TestAccServiceCatalogAppRegistryAttributeGroupDataSource_basic(t *testing.T resource.TestCheckResourceAttr(dataSourceName, names.AttrName, rName), resource.TestCheckResourceAttr(dataSourceName, names.AttrDescription, rDesc), resource.TestCheckResourceAttr(dataSourceName, names.AttrAttributes, expectJsonV1), - acctest.MatchResourceAttrRegionalARN(dataSourceName, names.AttrARN, "servicecatalog", regexache.MustCompile(`/attribute-groups/+.`)), + acctest.MatchResourceAttrRegionalARN(ctx, dataSourceName, names.AttrARN, "servicecatalog", regexache.MustCompile(`/attribute-groups/+.`)), ), }, }, From fd12ec4a4079ff78e829ddc2abbbb017b2956742 Mon Sep 17 00:00:00 2001 From: Andrew Tulloch Date: Fri, 29 Nov 2024 14:52:34 +0000 Subject: [PATCH 12/17] Update for IgnoreTagsConfig being a function --- .../servicecatalogappregistry/attribute_group_data_source.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/service/servicecatalogappregistry/attribute_group_data_source.go b/internal/service/servicecatalogappregistry/attribute_group_data_source.go index c8bc9b20944..169ba7e2d9b 100644 --- a/internal/service/servicecatalogappregistry/attribute_group_data_source.go +++ b/internal/service/servicecatalogappregistry/attribute_group_data_source.go @@ -68,7 +68,7 @@ func (d *dataSourceAttributeGroup) Schema(ctx context.Context, req datasource.Sc func (d *dataSourceAttributeGroup) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { conn := d.Meta().ServiceCatalogAppRegistryClient(ctx) - ignoreTagsConfig := d.Meta().IgnoreTagsConfig + ignoreTagsConfig := d.Meta().IgnoreTagsConfig(ctx) var data dataSourceAttributeGroupData resp.Diagnostics.Append(req.Config.Get(ctx, &data)...) From 91183691ba6335d8fe9fc037a621f6f56c15805a Mon Sep 17 00:00:00 2001 From: Andrew Tulloch Date: Fri, 29 Nov 2024 14:58:03 +0000 Subject: [PATCH 13/17] Fix type error for tags --- .../servicecatalogappregistry/attribute_group_data_source.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/service/servicecatalogappregistry/attribute_group_data_source.go b/internal/service/servicecatalogappregistry/attribute_group_data_source.go index 169ba7e2d9b..b403370d021 100644 --- a/internal/service/servicecatalogappregistry/attribute_group_data_source.go +++ b/internal/service/servicecatalogappregistry/attribute_group_data_source.go @@ -101,7 +101,7 @@ func (d *dataSourceAttributeGroup) Read(ctx context.Context, req datasource.Read } // Transparent tagging doesn't work for DataSource yet - data.Tags = flex.FlattenFrameworkStringValueMapLegacy(ctx, KeyValueTags(ctx, out.Tags).IgnoreAWS().IgnoreConfig(ignoreTagsConfig).Map()) + data.Tags = tftags.NewMapFromMapValue(flex.FlattenFrameworkStringValueMapLegacy(ctx, KeyValueTags(ctx, out.Tags).IgnoreAWS().IgnoreConfig(ignoreTagsConfig).Map())) resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) } @@ -112,5 +112,5 @@ type dataSourceAttributeGroupData struct { Description types.String `tfsdk:"description"` ID types.String `tfsdk:"id"` Name types.String `tfsdk:"name"` - Tags types.Map `tfsdk:"tags"` + Tags tftags.Map `tfsdk:"tags"` } From b1522315941e01ddbba6c498423debf500c61617 Mon Sep 17 00:00:00 2001 From: Andrew Tulloch Date: Fri, 29 Nov 2024 15:38:23 +0000 Subject: [PATCH 14/17] Make gen --- ...tribute_group_data_source_tags_gen_test.go | 150 ++++++++++++++++++ .../tags_gen_test.go | 4 + .../AttributeGroup/data.tags/main_gen.tf | 1 + .../data.tags_defaults/main_gen.tf | 42 +++++ .../data.tags_ignore/main_gen.tf | 51 ++++++ 5 files changed, 248 insertions(+) create mode 100644 internal/service/servicecatalogappregistry/testdata/AttributeGroup/data.tags_defaults/main_gen.tf create mode 100644 internal/service/servicecatalogappregistry/testdata/AttributeGroup/data.tags_ignore/main_gen.tf diff --git a/internal/service/servicecatalogappregistry/attribute_group_data_source_tags_gen_test.go b/internal/service/servicecatalogappregistry/attribute_group_data_source_tags_gen_test.go index 0391847d4c4..b3a73fac174 100644 --- a/internal/service/servicecatalogappregistry/attribute_group_data_source_tags_gen_test.go +++ b/internal/service/servicecatalogappregistry/attribute_group_data_source_tags_gen_test.go @@ -42,3 +42,153 @@ func TestAccServiceCatalogAppRegistryAttributeGroupDataSource_tags(t *testing.T) }, }) } + +func TestAccServiceCatalogAppRegistryAttributeGroupDataSource_tags_NullMap(t *testing.T) { + ctx := acctest.Context(t) + dataSourceName := "data.aws_servicecatalogappregistry_attribute_group.test" + rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acctest.PreCheck(ctx, t) }, + ErrorCheck: acctest.ErrorCheck(t, names.ServiceCatalogAppRegistryServiceID), + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + Steps: []resource.TestStep{ + { + ConfigDirectory: config.StaticDirectory("testdata/AttributeGroup/data.tags/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtResourceTags: nil, + }, + ConfigStateChecks: []statecheck.StateCheck{ + statecheck.ExpectKnownValue(dataSourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{})), + }, + }, + }, + }) +} + +func TestAccServiceCatalogAppRegistryAttributeGroupDataSource_tags_EmptyMap(t *testing.T) { + ctx := acctest.Context(t) + dataSourceName := "data.aws_servicecatalogappregistry_attribute_group.test" + rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acctest.PreCheck(ctx, t) }, + ErrorCheck: acctest.ErrorCheck(t, names.ServiceCatalogAppRegistryServiceID), + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + Steps: []resource.TestStep{ + { + ConfigDirectory: config.StaticDirectory("testdata/AttributeGroup/data.tags/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{}), + }, + ConfigStateChecks: []statecheck.StateCheck{ + statecheck.ExpectKnownValue(dataSourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{})), + }, + }, + }, + }) +} + +func TestAccServiceCatalogAppRegistryAttributeGroupDataSource_tags_DefaultTags_nonOverlapping(t *testing.T) { + ctx := acctest.Context(t) + dataSourceName := "data.aws_servicecatalogappregistry_attribute_group.test" + rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acctest.PreCheck(ctx, t) }, + ErrorCheck: acctest.ErrorCheck(t, names.ServiceCatalogAppRegistryServiceID), + Steps: []resource.TestStep{ + { + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + ConfigDirectory: config.StaticDirectory("testdata/AttributeGroup/data.tags_defaults/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtProviderTags: config.MapVariable(map[string]config.Variable{ + acctest.CtProviderKey1: config.StringVariable(acctest.CtProviderValue1), + }), + acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ + acctest.CtResourceKey1: config.StringVariable(acctest.CtResourceValue1), + }), + }, + ConfigStateChecks: []statecheck.StateCheck{ + statecheck.ExpectKnownValue(dataSourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtProviderKey1: knownvalue.StringExact(acctest.CtProviderValue1), + acctest.CtResourceKey1: knownvalue.StringExact(acctest.CtResourceValue1), + })), + }, + }, + }, + }) +} + +func TestAccServiceCatalogAppRegistryAttributeGroupDataSource_tags_IgnoreTags_Overlap_DefaultTag(t *testing.T) { + ctx := acctest.Context(t) + dataSourceName := "data.aws_servicecatalogappregistry_attribute_group.test" + rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acctest.PreCheck(ctx, t) }, + ErrorCheck: acctest.ErrorCheck(t, names.ServiceCatalogAppRegistryServiceID), + Steps: []resource.TestStep{ + { + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + ConfigDirectory: config.StaticDirectory("testdata/AttributeGroup/data.tags_ignore/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtProviderTags: config.MapVariable(map[string]config.Variable{ + acctest.CtProviderKey1: config.StringVariable(acctest.CtProviderValue1), + }), + acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ + acctest.CtResourceKey1: config.StringVariable(acctest.CtResourceValue1), + }), + "ignore_tag_keys": config.SetVariable( + config.StringVariable(acctest.CtProviderKey1), + ), + }, + ConfigStateChecks: []statecheck.StateCheck{ + statecheck.ExpectKnownValue(dataSourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtResourceKey1: knownvalue.StringExact(acctest.CtResourceValue1), + })), + expectFullDataSourceTags(dataSourceName, knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtProviderKey1: knownvalue.StringExact(acctest.CtProviderValue1), + acctest.CtResourceKey1: knownvalue.StringExact(acctest.CtResourceValue1), + })), + }, + }, + }, + }) +} + +func TestAccServiceCatalogAppRegistryAttributeGroupDataSource_tags_IgnoreTags_Overlap_ResourceTag(t *testing.T) { + ctx := acctest.Context(t) + dataSourceName := "data.aws_servicecatalogappregistry_attribute_group.test" + rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acctest.PreCheck(ctx, t) }, + ErrorCheck: acctest.ErrorCheck(t, names.ServiceCatalogAppRegistryServiceID), + Steps: []resource.TestStep{ + { + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + ConfigDirectory: config.StaticDirectory("testdata/AttributeGroup/data.tags_ignore/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ + acctest.CtResourceKey1: config.StringVariable(acctest.CtResourceValue1), + }), + "ignore_tag_keys": config.SetVariable( + config.StringVariable(acctest.CtResourceKey1), + ), + }, + ConfigStateChecks: []statecheck.StateCheck{ + statecheck.ExpectKnownValue(dataSourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{})), + expectFullDataSourceTags(dataSourceName, knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtResourceKey1: knownvalue.StringExact(acctest.CtResourceValue1), + })), + }, + }, + }, + }) +} diff --git a/internal/service/servicecatalogappregistry/tags_gen_test.go b/internal/service/servicecatalogappregistry/tags_gen_test.go index 5535f5b9352..86b752a6b93 100644 --- a/internal/service/servicecatalogappregistry/tags_gen_test.go +++ b/internal/service/servicecatalogappregistry/tags_gen_test.go @@ -14,3 +14,7 @@ import ( func expectFullResourceTags(resourceAddress string, knownValue knownvalue.Check) statecheck.StateCheck { return tfstatecheck.ExpectFullResourceTags(tfservicecatalogappregistry.ServicePackage(context.Background()), resourceAddress, knownValue) } + +func expectFullDataSourceTags(resourceAddress string, knownValue knownvalue.Check) statecheck.StateCheck { + return tfstatecheck.ExpectFullDataSourceTags(tfservicecatalogappregistry.ServicePackage(context.Background()), resourceAddress, knownValue) +} diff --git a/internal/service/servicecatalogappregistry/testdata/AttributeGroup/data.tags/main_gen.tf b/internal/service/servicecatalogappregistry/testdata/AttributeGroup/data.tags/main_gen.tf index 92e98274b85..b86a4938938 100644 --- a/internal/service/servicecatalogappregistry/testdata/AttributeGroup/data.tags/main_gen.tf +++ b/internal/service/servicecatalogappregistry/testdata/AttributeGroup/data.tags/main_gen.tf @@ -1,6 +1,7 @@ # Copyright (c) HashiCorp, Inc. # SPDX-License-Identifier: MPL-2.0 +# tflint-ignore: terraform_unused_declarations data "aws_servicecatalogappregistry_attribute_group" "test" { id = aws_servicecatalogappregistry_attribute_group.test.id } diff --git a/internal/service/servicecatalogappregistry/testdata/AttributeGroup/data.tags_defaults/main_gen.tf b/internal/service/servicecatalogappregistry/testdata/AttributeGroup/data.tags_defaults/main_gen.tf new file mode 100644 index 00000000000..ebc191b3c50 --- /dev/null +++ b/internal/service/servicecatalogappregistry/testdata/AttributeGroup/data.tags_defaults/main_gen.tf @@ -0,0 +1,42 @@ +# Copyright (c) HashiCorp, Inc. +# SPDX-License-Identifier: MPL-2.0 + +provider "aws" { + default_tags { + tags = var.provider_tags + } +} + +# tflint-ignore: terraform_unused_declarations +data "aws_servicecatalogappregistry_attribute_group" "test" { + id = aws_servicecatalogappregistry_attribute_group.test.id +} +resource "aws_servicecatalogappregistry_attribute_group" "test" { + name = var.rName + description = "Some attribute group" + + attributes = jsonencode({ + a = "1" + b = "2" + }) + + tags = var.resource_tags +} + +variable "rName" { + description = "Name for resource" + type = string + nullable = false +} + +variable "resource_tags" { + description = "Tags to set on resource. To specify no tags, set to `null`" + # Not setting a default, so that this must explicitly be set to `null` to specify no tags + type = map(string) + nullable = true +} + +variable "provider_tags" { + type = map(string) + nullable = false +} diff --git a/internal/service/servicecatalogappregistry/testdata/AttributeGroup/data.tags_ignore/main_gen.tf b/internal/service/servicecatalogappregistry/testdata/AttributeGroup/data.tags_ignore/main_gen.tf new file mode 100644 index 00000000000..7e2a4ed38f0 --- /dev/null +++ b/internal/service/servicecatalogappregistry/testdata/AttributeGroup/data.tags_ignore/main_gen.tf @@ -0,0 +1,51 @@ +# Copyright (c) HashiCorp, Inc. +# SPDX-License-Identifier: MPL-2.0 + +provider "aws" { + default_tags { + tags = var.provider_tags + } + ignore_tags { + keys = var.ignore_tag_keys + } +} + +# tflint-ignore: terraform_unused_declarations +data "aws_servicecatalogappregistry_attribute_group" "test" { + id = aws_servicecatalogappregistry_attribute_group.test.id +} +resource "aws_servicecatalogappregistry_attribute_group" "test" { + name = var.rName + description = "Some attribute group" + + attributes = jsonencode({ + a = "1" + b = "2" + }) + + tags = var.resource_tags +} + +variable "rName" { + description = "Name for resource" + type = string + nullable = false +} + +variable "resource_tags" { + description = "Tags to set on resource. To specify no tags, set to `null`" + # Not setting a default, so that this must explicitly be set to `null` to specify no tags + type = map(string) + nullable = true +} + +variable "provider_tags" { + type = map(string) + nullable = true + default = null +} + +variable "ignore_tag_keys" { + type = set(string) + nullable = false +} From 4c25a9e8a555157d6d1bc7d7617ed4f83348be7c Mon Sep 17 00:00:00 2001 From: Jared Baker Date: Thu, 5 Dec 2024 16:22:53 -0500 Subject: [PATCH 15/17] d/aws_servicecatalogappregistry_attribute_group: make `arn`, `id`, and `name` mutually exclusive --- .../attribute_group_data_source.go | 30 ++++++++++++------- ...gappregistry_attribute_group.html.markdown | 6 ++-- 2 files changed, 23 insertions(+), 13 deletions(-) diff --git a/internal/service/servicecatalogappregistry/attribute_group_data_source.go b/internal/service/servicecatalogappregistry/attribute_group_data_source.go index b403370d021..58948e8dfc5 100644 --- a/internal/service/servicecatalogappregistry/attribute_group_data_source.go +++ b/internal/service/servicecatalogappregistry/attribute_group_data_source.go @@ -7,20 +7,19 @@ import ( "context" "github.com/hashicorp/terraform-plugin-framework-jsontypes/jsontypes" - "github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator" + "github.com/hashicorp/terraform-plugin-framework-validators/datasourcevalidator" "github.com/hashicorp/terraform-plugin-framework/datasource" "github.com/hashicorp/terraform-plugin-framework/datasource/schema" "github.com/hashicorp/terraform-plugin-framework/path" - "github.com/hashicorp/terraform-plugin-framework/schema/validator" "github.com/hashicorp/terraform-plugin-framework/types" "github.com/hashicorp/terraform-provider-aws/internal/create" "github.com/hashicorp/terraform-provider-aws/internal/framework" "github.com/hashicorp/terraform-provider-aws/internal/framework/flex" + fwtypes "github.com/hashicorp/terraform-provider-aws/internal/framework/types" tftags "github.com/hashicorp/terraform-provider-aws/internal/tags" "github.com/hashicorp/terraform-provider-aws/names" ) -// Function annotations are used for datasource registration to the Provider. DO NOT EDIT. // @FrameworkDataSource("aws_servicecatalogappregistry_attribute_group", name="Attribute Group") // @Tags(identifierAttribute="arn") func newDataSourceAttributeGroup(context.Context) (datasource.DataSourceWithConfigure, error) { @@ -42,20 +41,21 @@ func (d *dataSourceAttributeGroup) Metadata(_ context.Context, req datasource.Me func (d *dataSourceAttributeGroup) Schema(ctx context.Context, req datasource.SchemaRequest, resp *datasource.SchemaResponse) { resp.Schema = schema.Schema{ Attributes: map[string]schema.Attribute{ - names.AttrARN: framework.ARNAttributeComputedOnly(), - names.AttrAttributes: schema.StringAttribute{ + names.AttrARN: schema.StringAttribute{ + CustomType: fwtypes.ARNType, + Optional: true, Computed: true, + }, + names.AttrAttributes: schema.StringAttribute{ CustomType: jsontypes.NormalizedType{}, + Computed: true, }, names.AttrDescription: schema.StringAttribute{ - Optional: true, + Computed: true, }, names.AttrID: schema.StringAttribute{ Optional: true, Computed: true, - Validators: []validator.String{ - stringvalidator.AtLeastOneOf(path.MatchRoot(names.AttrName), path.MatchRoot(names.AttrARN)), - }, }, names.AttrName: schema.StringAttribute{ Optional: true, @@ -66,6 +66,16 @@ func (d *dataSourceAttributeGroup) Schema(ctx context.Context, req datasource.Sc } } +func (d *dataSourceAttributeGroup) ConfigValidators(_ context.Context) []datasource.ConfigValidator { + return []datasource.ConfigValidator{ + datasourcevalidator.ExactlyOneOf( + path.MatchRoot(names.AttrARN), + path.MatchRoot(names.AttrID), + path.MatchRoot(names.AttrName), + ), + } +} + func (d *dataSourceAttributeGroup) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { conn := d.Meta().ServiceCatalogAppRegistryClient(ctx) ignoreTagsConfig := d.Meta().IgnoreTagsConfig(ctx) @@ -107,7 +117,7 @@ func (d *dataSourceAttributeGroup) Read(ctx context.Context, req datasource.Read } type dataSourceAttributeGroupData struct { - ARN types.String `tfsdk:"arn"` + ARN fwtypes.ARN `tfsdk:"arn"` Attributes jsontypes.Normalized `tfsdk:"attributes"` Description types.String `tfsdk:"description"` ID types.String `tfsdk:"id"` diff --git a/website/docs/d/servicecatalogappregistry_attribute_group.html.markdown b/website/docs/d/servicecatalogappregistry_attribute_group.html.markdown index 094f4f37c93..e8e365ef080 100644 --- a/website/docs/d/servicecatalogappregistry_attribute_group.html.markdown +++ b/website/docs/d/servicecatalogappregistry_attribute_group.html.markdown @@ -22,13 +22,13 @@ data "aws_servicecatalogappregistry_attribute_group" "example" { ## Argument Reference -The following arguments are required: - The following arguments are optional: +~> Exactly one of `arn`, `id`, or `name` must be set. + +* `arn` - (Optional) ARN of the Attribute Group to find. * `id` - (Optional) ID of the Attribute Group to find. * `name` - (Optional) Name of the Attribute Group to find. -* `arn` - (Optional) ARN of the Attribute Group to find. ## Attribute Reference From a33f4c69717999a4431fcdf786ec4b3d696a78a9 Mon Sep 17 00:00:00 2001 From: Jared Baker Date: Thu, 5 Dec 2024 16:28:51 -0500 Subject: [PATCH 16/17] d/aws_servicecatalogappregistry_attribute_group: rely on transparent tagging --- .../servicecatalogappregistry/attribute_group_data_source.go | 4 ---- 1 file changed, 4 deletions(-) diff --git a/internal/service/servicecatalogappregistry/attribute_group_data_source.go b/internal/service/servicecatalogappregistry/attribute_group_data_source.go index 58948e8dfc5..ce61f63b30b 100644 --- a/internal/service/servicecatalogappregistry/attribute_group_data_source.go +++ b/internal/service/servicecatalogappregistry/attribute_group_data_source.go @@ -78,7 +78,6 @@ func (d *dataSourceAttributeGroup) ConfigValidators(_ context.Context) []datasou func (d *dataSourceAttributeGroup) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { conn := d.Meta().ServiceCatalogAppRegistryClient(ctx) - ignoreTagsConfig := d.Meta().IgnoreTagsConfig(ctx) var data dataSourceAttributeGroupData resp.Diagnostics.Append(req.Config.Get(ctx, &data)...) @@ -110,9 +109,6 @@ func (d *dataSourceAttributeGroup) Read(ctx context.Context, req datasource.Read return } - // Transparent tagging doesn't work for DataSource yet - data.Tags = tftags.NewMapFromMapValue(flex.FlattenFrameworkStringValueMapLegacy(ctx, KeyValueTags(ctx, out.Tags).IgnoreAWS().IgnoreConfig(ignoreTagsConfig).Map())) - resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) } From c915ceedc7bf8e9147380f683491f3cead16efb7 Mon Sep 17 00:00:00 2001 From: Jared Baker Date: Thu, 5 Dec 2024 16:29:14 -0500 Subject: [PATCH 17/17] d/aws_servicecatalogappregistry_attribute_group(test): tidy basic config --- .../attribute_group_data_source_test.go | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/internal/service/servicecatalogappregistry/attribute_group_data_source_test.go b/internal/service/servicecatalogappregistry/attribute_group_data_source_test.go index f7667733f98..d3b9e48c77c 100644 --- a/internal/service/servicecatalogappregistry/attribute_group_data_source_test.go +++ b/internal/service/servicecatalogappregistry/attribute_group_data_source_test.go @@ -17,13 +17,10 @@ import ( func TestAccServiceCatalogAppRegistryAttributeGroupDataSource_basic(t *testing.T) { ctx := acctest.Context(t) - if testing.Short() { - t.Skip("skipping long-running test in short mode") - } var attributegroup servicecatalogappregistry.GetAttributeGroupOutput rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) - rDesc := "Simple Description" + description := "Simple Description" expectJsonV1 := `{"a":"1","b":"2"}` dataSourceName := "data.aws_servicecatalogappregistry_attribute_group.test" @@ -38,11 +35,11 @@ func TestAccServiceCatalogAppRegistryAttributeGroupDataSource_basic(t *testing.T CheckDestroy: testAccCheckAttributeGroupDestroy(ctx), Steps: []resource.TestStep{ { - Config: testAccAttributeGroupDataSourceConfig_basic(rName, rDesc), + Config: testAccAttributeGroupDataSourceConfig_basic(rName, description), Check: resource.ComposeTestCheckFunc( testAccCheckAttributeGroupExists(ctx, dataSourceName, &attributegroup), resource.TestCheckResourceAttr(dataSourceName, names.AttrName, rName), - resource.TestCheckResourceAttr(dataSourceName, names.AttrDescription, rDesc), + resource.TestCheckResourceAttr(dataSourceName, names.AttrDescription, description), resource.TestCheckResourceAttr(dataSourceName, names.AttrAttributes, expectJsonV1), acctest.MatchResourceAttrRegionalARN(ctx, dataSourceName, names.AttrARN, "servicecatalog", regexache.MustCompile(`/attribute-groups/+.`)), ), @@ -64,10 +61,6 @@ resource "aws_servicecatalogappregistry_attribute_group" "test" { a = "1" b = "2" }) - tags = { - tag1 = "v1" - tag2 = "v2" - } } `, rName, description) }