From 593405dac6b8d4535b5ce008e3e5cf2dbce2a05c Mon Sep 17 00:00:00 2001 From: drfaust92 Date: Fri, 19 Feb 2021 17:55:29 +0200 Subject: [PATCH 01/17] initial commit --- ..._aws_resourcegroupstaggingapi_resources.go | 182 ++++++++++++++++++ ...resourcegroupstaggingapi_resources_test.go | 151 +++++++++++++++ aws/provider.go | 1 + 3 files changed, 334 insertions(+) create mode 100644 aws/data_source_aws_resourcegroupstaggingapi_resources.go create mode 100644 aws/data_source_aws_resourcegroupstaggingapi_resources_test.go diff --git a/aws/data_source_aws_resourcegroupstaggingapi_resources.go b/aws/data_source_aws_resourcegroupstaggingapi_resources.go new file mode 100644 index 000000000000..e697d53f028b --- /dev/null +++ b/aws/data_source_aws_resourcegroupstaggingapi_resources.go @@ -0,0 +1,182 @@ +package aws + +import ( + "fmt" + + "github.com/aws/aws-sdk-go/aws" + "github.com/aws/aws-sdk-go/service/resourcegroupstaggingapi" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/terraform-providers/terraform-provider-aws/aws/internal/keyvaluetags" +) + +func dataSourceAwsResourceGroupsTaggingAPIResources() *schema.Resource { + return &schema.Resource{ + Read: dataSourceAwsResourceGroupsTaggingAPIResourcesRead, + + Schema: map[string]*schema.Schema{ + "exclude_compliant_resources": { + Type: schema.TypeBool, + Optional: true, + }, + "include_compliance_details": { + Type: schema.TypeBool, + Optional: true, + }, + "resource_type_filters": { + Type: schema.TypeSet, + Optional: true, + MaxItems: 100, + Elem: &schema.Schema{Type: schema.TypeString}, + }, + "tag_filters": { + Type: schema.TypeList, + Optional: true, + MaxItems: 50, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "key": { + Type: schema.TypeString, + Required: true, + }, + "values": { + Type: schema.TypeSet, + Optional: true, + MaxItems: 20, + Elem: &schema.Schema{Type: schema.TypeString}, + }, + }, + }, + }, + "resource_tag_mapping_list": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "resource_arn": { + Type: schema.TypeString, + Computed: true, + }, + "compliance_details": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "compliance_status": { + Type: schema.TypeBool, + Computed: true, + }, + "keys_with_noncompliant_values": { + Type: schema.TypeSet, + Computed: true, + Elem: &schema.Schema{Type: schema.TypeString}, + }, + "non_compliant_keys": { + Type: schema.TypeSet, + Computed: true, + Elem: &schema.Schema{Type: schema.TypeString}, + }, + }, + }, + }, + "tags": tagsSchemaComputed(), + }, + }, + }, + }, + } +} + +func dataSourceAwsResourceGroupsTaggingAPIResourcesRead(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*AWSClient).resourcegroupstaggingapiconn + + input := &resourcegroupstaggingapi.GetResourcesInput{} + + if v, ok := d.GetOk("include_compliance_details"); ok { + input.IncludeComplianceDetails = aws.Bool(v.(bool)) + } + + if v, ok := d.GetOk("exclude_compliant_resources"); ok { + input.ExcludeCompliantResources = aws.Bool(v.(bool)) + } + + if v, ok := d.GetOk("tag_filters"); ok { + input.TagFilters = expandAwsResourceGroupsTaggingAPITagFilters(v.([]interface{})) + } + + if v, ok := d.GetOk("resource_type_filters"); ok && v.(*schema.Set).Len() > 0 { + input.ResourceTypeFilters = expandStringSet(v.(*schema.Set)) + } + + var taggings []*resourcegroupstaggingapi.ResourceTagMapping + + err := conn.GetResourcesPages(input, func(page *resourcegroupstaggingapi.GetResourcesOutput, lastPage bool) bool { + if page == nil { + return !lastPage + } + + taggings = append(taggings, page.ResourceTagMappingList...) + return !lastPage + }) + if err != nil { + return err + } + + d.SetId(meta.(*AWSClient).partition) + + if err := d.Set("resource_tag_mapping_list", flattenAwsResourceGroupsTaggingAPIResourcesTagMappingList(taggings)); err != nil { + return fmt.Errorf("error setting resource tag mapping list: %w", err) + } + + return nil +} + +func expandAwsResourceGroupsTaggingAPITagFilters(filters []interface{}) []*resourcegroupstaggingapi.TagFilter { + result := make([]*resourcegroupstaggingapi.TagFilter, len(filters)) + + for i, filter := range filters { + m := filter.(map[string]interface{}) + + result[i] = &resourcegroupstaggingapi.TagFilter{ + Key: aws.String(m["key"].(string)), + } + + if v, ok := m["values"]; ok && v.(*schema.Set).Len() > 0 { + result[i].Values = expandStringSet(v.(*schema.Set)) + } + } + + return result +} + +func flattenAwsResourceGroupsTaggingAPIResourcesTagMappingList(list []*resourcegroupstaggingapi.ResourceTagMapping) []map[string]interface{} { + result := make([]map[string]interface{}, 0, len(list)) + + for _, i := range list { + l := map[string]interface{}{ + "resource_arn": aws.StringValue(i.ResourceARN), + "tags": keyvaluetags.ResourcegroupstaggingapiKeyValueTags(i.Tags).IgnoreAws().Map(), + } + + if i.ComplianceDetails != nil { + l["compliance_details"] = flattenAwsResourceGroupsTaggingAPIComplianceDetails(i.ComplianceDetails) + } + + result = append(result, l) + } + + return result +} + +func flattenAwsResourceGroupsTaggingAPIComplianceDetails(details *resourcegroupstaggingapi.ComplianceDetails) []map[string]interface{} { + if details == nil { + return []map[string]interface{}{} + } + + m := map[string]interface{}{ + "compliance_status": aws.BoolValue(details.ComplianceStatus), + "keys_with_noncompliant_values": flattenStringSet(details.KeysWithNoncompliantValues), + "non_compliant_keys": flattenStringSet(details.NoncompliantKeys), + } + + return []map[string]interface{}{m} +} diff --git a/aws/data_source_aws_resourcegroupstaggingapi_resources_test.go b/aws/data_source_aws_resourcegroupstaggingapi_resources_test.go new file mode 100644 index 000000000000..3788e59d5f14 --- /dev/null +++ b/aws/data_source_aws_resourcegroupstaggingapi_resources_test.go @@ -0,0 +1,151 @@ +package aws + +import ( + "fmt" + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" +) + +func TestAccDataSourceAwsResourceGroupsTaggingAPIResources_basic(t *testing.T) { + dataSourceName := "data.aws_resourcegroupstaggingapi_resources.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + Steps: []resource.TestStep{ + { + Config: testAccDataSourceAwsResourceGroupsTaggingAPIResourcesBasicConfig, + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttrSet(dataSourceName, "resource_tag_mapping_list.#"), + resource.TestCheckResourceAttrSet(dataSourceName, "resource_tag_mapping_list.0.resource_arn"), + ), + }, + }, + }) +} + +func TestAccDataSourceAwsResourceGroupsTaggingAPIResources_tag_key_filter(t *testing.T) { + dataSourceName := "data.aws_resourcegroupstaggingapi_resources.test" + resourceName := "aws_lambda_function.test" + rName := acctest.RandomWithPrefix("tf-acc-test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + Steps: []resource.TestStep{ + { + Config: testAccDataSourceAwsResourceGroupsTaggingAPIResourcesTagKeyFilterConfig(rName), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr(dataSourceName, "resource_tag_mapping_list.#", "1"), + resource.TestCheckTypeSetElemNestedAttrs(dataSourceName, "resource_tag_mapping_list.*", map[string]string{ + "tags.Key": rName, + }), + resource.TestCheckTypeSetElemAttrPair(dataSourceName, "resource_tag_mapping_list.*.resource_arn", resourceName, "arn"), + ), + }, + }, + }) +} + +func TestAccDataSourceAwsResourceGroupsTaggingAPIResources_compliance(t *testing.T) { + dataSourceName := "data.aws_resourcegroupstaggingapi_resources.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + Steps: []resource.TestStep{ + { + Config: testAccDataSourceAwsResourceGroupsTaggingAPIResourcesComplianceConfig, + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr(dataSourceName, "resource_tag_mapping_list.0.compliance_details.#", "1"), + resource.TestCheckResourceAttr(dataSourceName, "resource_tag_mapping_list.0.compliance_details.0.compliance_status", "true"), + resource.TestCheckResourceAttrSet(dataSourceName, "resource_tag_mapping_list.0.resource_arn"), + ), + }, + }, + }) +} + +func TestAccDataSourceAwsResourceGroupsTaggingAPIResources_resource_type_filters(t *testing.T) { + dataSourceName := "data.aws_resourcegroupstaggingapi_resources.test" + resourceName := "aws_lambda_function.test" + rName := acctest.RandomWithPrefix("tf-acc-test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + Steps: []resource.TestStep{ + { + Config: testAccDataSourceAwsResourceGroupsTaggingAPIResourcesResourceTypeFiltersConfig(rName), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr(dataSourceName, "resource_tag_mapping_list.#", "1"), + resource.TestCheckTypeSetElemNestedAttrs(dataSourceName, "resource_tag_mapping_list.*", map[string]string{ + "tags.Key": rName, + }), + resource.TestCheckTypeSetElemAttrPair(dataSourceName, "resource_tag_mapping_list.*.resource_arn", resourceName, "arn"), + ), + }, + }, + }) +} + +const testAccDataSourceAwsResourceGroupsTaggingAPIResourcesBasicConfig = ` +data "aws_resourcegroupstaggingapi_resources" "test" {} +` + +func testAccDataSourceAwsResourceGroupsTaggingAPIResourcesTagKeyFilterConfig(rName string) string { + return testAccDataSourceAWSLambdaFunctionConfigBase(rName) + fmt.Sprintf(` +resource "aws_lambda_function" "test" { + filename = "test-fixtures/lambdatest.zip" + function_name = %[1]q + handler = "exports.example" + role = aws_iam_role.lambda.arn + runtime = "nodejs12.x" + + tags = { + Key = %[1]q + } +} + +data "aws_resourcegroupstaggingapi_resources" "test" { + tag_filters { + key = "Key" + } + + depends_on = [aws_lambda_function.test] +} +`, rName) +} + +func testAccDataSourceAwsResourceGroupsTaggingAPIResourcesResourceTypeFiltersConfig(rName string) string { + return testAccDataSourceAWSLambdaFunctionConfigBase(rName) + fmt.Sprintf(` +resource "aws_lambda_function" "test" { + filename = "test-fixtures/lambdatest.zip" + function_name = %[1]q + handler = "exports.example" + role = aws_iam_role.lambda.arn + runtime = "nodejs12.x" +} + +data "aws_resourcegroupstaggingapi_resources" "test" { + resource_type_filters = ["lambda"] + + depends_on = [aws_lambda_function.test] +} +`, rName) +} + +const testAccDataSourceAwsResourceGroupsTaggingAPIResourcesComplianceConfig = ` +data "aws_resourcegroupstaggingapi_resources" "test" { + include_compliance_details = true + exclude_compliant_resources = false +} +` + +const testAccDataSourceAwsResourceGroupsTaggingAPIResourcesResourceTypeConfig = ` +data "aws_resourcegroupstaggingapi_resources" "test" { + resource_type_filters = ["ec2:instance"] +} +` diff --git a/aws/provider.go b/aws/provider.go index 27bf36d6f018..6d128150d3ec 100644 --- a/aws/provider.go +++ b/aws/provider.go @@ -360,6 +360,7 @@ func Provider() *schema.Provider { "aws_redshift_service_account": dataSourceAwsRedshiftServiceAccount(), "aws_region": dataSourceAwsRegion(), "aws_regions": dataSourceAwsRegions(), + "aws_resourcegroupstaggingapi_resources": dataSourceAwsResourceGroupsTaggingAPIResources(), "aws_route": dataSourceAwsRoute(), "aws_route_table": dataSourceAwsRouteTable(), "aws_route_tables": dataSourceAwsRouteTables(), From f46a3bb2533bb1d901f4899db90b23ceb5741113 Mon Sep 17 00:00:00 2001 From: drfaust92 Date: Thu, 25 Feb 2021 00:23:26 +0200 Subject: [PATCH 02/17] add resource_arn_list + tests --- ..._aws_resourcegroupstaggingapi_resources.go | 19 ++++- ...resourcegroupstaggingapi_resources_test.go | 74 +++++++++++++------ 2 files changed, 68 insertions(+), 25 deletions(-) diff --git a/aws/data_source_aws_resourcegroupstaggingapi_resources.go b/aws/data_source_aws_resourcegroupstaggingapi_resources.go index e697d53f028b..aceb75c48c0b 100644 --- a/aws/data_source_aws_resourcegroupstaggingapi_resources.go +++ b/aws/data_source_aws_resourcegroupstaggingapi_resources.go @@ -22,11 +22,18 @@ func dataSourceAwsResourceGroupsTaggingAPIResources() *schema.Resource { Type: schema.TypeBool, Optional: true, }, + "resource_arn_list": { + Type: schema.TypeSet, + Optional: true, + Elem: &schema.Schema{Type: schema.TypeString}, + ConflictsWith: []string{"tag_filters"}, + }, "resource_type_filters": { - Type: schema.TypeSet, - Optional: true, - MaxItems: 100, - Elem: &schema.Schema{Type: schema.TypeString}, + Type: schema.TypeSet, + Optional: true, + MaxItems: 100, + Elem: &schema.Schema{Type: schema.TypeString}, + ConflictsWith: []string{"resource_arn_list"}, }, "tag_filters": { Type: schema.TypeList, @@ -99,6 +106,10 @@ func dataSourceAwsResourceGroupsTaggingAPIResourcesRead(d *schema.ResourceData, input.ExcludeCompliantResources = aws.Bool(v.(bool)) } + if v, ok := d.GetOk("resource_arn_list"); ok && v.(*schema.Set).Len() > 0 { + input.ResourceARNList = expandStringSet(v.(*schema.Set)) + } + if v, ok := d.GetOk("tag_filters"); ok { input.TagFilters = expandAwsResourceGroupsTaggingAPITagFilters(v.([]interface{})) } diff --git a/aws/data_source_aws_resourcegroupstaggingapi_resources_test.go b/aws/data_source_aws_resourcegroupstaggingapi_resources_test.go index 3788e59d5f14..ba114202818c 100644 --- a/aws/data_source_aws_resourcegroupstaggingapi_resources_test.go +++ b/aws/data_source_aws_resourcegroupstaggingapi_resources_test.go @@ -28,7 +28,7 @@ func TestAccDataSourceAwsResourceGroupsTaggingAPIResources_basic(t *testing.T) { func TestAccDataSourceAwsResourceGroupsTaggingAPIResources_tag_key_filter(t *testing.T) { dataSourceName := "data.aws_resourcegroupstaggingapi_resources.test" - resourceName := "aws_lambda_function.test" + resourceName := "aws_api_gateway_rest_api.test" rName := acctest.RandomWithPrefix("tf-acc-test") resource.ParallelTest(t, resource.TestCase{ @@ -38,7 +38,6 @@ func TestAccDataSourceAwsResourceGroupsTaggingAPIResources_tag_key_filter(t *tes { Config: testAccDataSourceAwsResourceGroupsTaggingAPIResourcesTagKeyFilterConfig(rName), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(dataSourceName, "resource_tag_mapping_list.#", "1"), resource.TestCheckTypeSetElemNestedAttrs(dataSourceName, "resource_tag_mapping_list.*", map[string]string{ "tags.Key": rName, }), @@ -70,7 +69,7 @@ func TestAccDataSourceAwsResourceGroupsTaggingAPIResources_compliance(t *testing func TestAccDataSourceAwsResourceGroupsTaggingAPIResources_resource_type_filters(t *testing.T) { dataSourceName := "data.aws_resourcegroupstaggingapi_resources.test" - resourceName := "aws_lambda_function.test" + resourceName := "aws_api_gateway_rest_api.test" rName := acctest.RandomWithPrefix("tf-acc-test") resource.ParallelTest(t, resource.TestCase{ @@ -80,7 +79,28 @@ func TestAccDataSourceAwsResourceGroupsTaggingAPIResources_resource_type_filters { Config: testAccDataSourceAwsResourceGroupsTaggingAPIResourcesResourceTypeFiltersConfig(rName), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(dataSourceName, "resource_tag_mapping_list.#", "1"), + resource.TestCheckTypeSetElemNestedAttrs(dataSourceName, "resource_tag_mapping_list.*", map[string]string{ + "tags.Key": rName, + }), + resource.TestCheckTypeSetElemAttrPair(dataSourceName, "resource_tag_mapping_list.*.resource_arn", resourceName, "arn"), + ), + }, + }, + }) +} + +func TestAccDataSourceAwsResourceGroupsTaggingAPIResources_resource_arn_list(t *testing.T) { + dataSourceName := "data.aws_resourcegroupstaggingapi_resources.test" + resourceName := "aws_api_gateway_rest_api.test" + rName := acctest.RandomWithPrefix("tf-acc-test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + Steps: []resource.TestStep{ + { + Config: testAccDataSourceAwsResourceGroupsTaggingAPIResourcesResourceARNListConfig(rName), + Check: resource.ComposeTestCheckFunc( resource.TestCheckTypeSetElemNestedAttrs(dataSourceName, "resource_tag_mapping_list.*", map[string]string{ "tags.Key": rName, }), @@ -96,13 +116,9 @@ data "aws_resourcegroupstaggingapi_resources" "test" {} ` func testAccDataSourceAwsResourceGroupsTaggingAPIResourcesTagKeyFilterConfig(rName string) string { - return testAccDataSourceAWSLambdaFunctionConfigBase(rName) + fmt.Sprintf(` -resource "aws_lambda_function" "test" { - filename = "test-fixtures/lambdatest.zip" - function_name = %[1]q - handler = "exports.example" - role = aws_iam_role.lambda.arn - runtime = "nodejs12.x" + return fmt.Sprintf(` +resource "aws_api_gateway_rest_api" "test" { + name = %[1]q tags = { Key = %[1]q @@ -114,25 +130,41 @@ data "aws_resourcegroupstaggingapi_resources" "test" { key = "Key" } - depends_on = [aws_lambda_function.test] + depends_on = [aws_api_gateway_rest_api.test] } `, rName) } func testAccDataSourceAwsResourceGroupsTaggingAPIResourcesResourceTypeFiltersConfig(rName string) string { - return testAccDataSourceAWSLambdaFunctionConfigBase(rName) + fmt.Sprintf(` -resource "aws_lambda_function" "test" { - filename = "test-fixtures/lambdatest.zip" - function_name = %[1]q - handler = "exports.example" - role = aws_iam_role.lambda.arn - runtime = "nodejs12.x" + return fmt.Sprintf(` +resource "aws_api_gateway_rest_api" "test" { + name = %[1]q + + tags = { + Key = %[1]q + } } data "aws_resourcegroupstaggingapi_resources" "test" { - resource_type_filters = ["lambda"] + resource_type_filters = ["apigateway"] - depends_on = [aws_lambda_function.test] + depends_on = [aws_api_gateway_rest_api.test] +} +`, rName) +} + +func testAccDataSourceAwsResourceGroupsTaggingAPIResourcesResourceARNListConfig(rName string) string { + return fmt.Sprintf(` +resource "aws_api_gateway_rest_api" "test" { + name = %[1]q + + tags = { + Key = %[1]q + } +} + +data "aws_resourcegroupstaggingapi_resources" "test" { + resource_arn_list = [aws_api_gateway_rest_api.test.arn] } `, rName) } From bd95c600d56b217e01438aad40a2e57f25ada2b7 Mon Sep 17 00:00:00 2001 From: drfaust92 Date: Thu, 25 Feb 2021 00:36:28 +0200 Subject: [PATCH 03/17] docs --- ...cegroupstaggingapi_resources.html.markdown | 75 +++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 website/docs/d/resourcegroupstaggingapi_resources.html.markdown diff --git a/website/docs/d/resourcegroupstaggingapi_resources.html.markdown b/website/docs/d/resourcegroupstaggingapi_resources.html.markdown new file mode 100644 index 000000000000..506f66a14a4b --- /dev/null +++ b/website/docs/d/resourcegroupstaggingapi_resources.html.markdown @@ -0,0 +1,75 @@ +--- +subcategory: "Resource Groups Tagging API" +layout: "aws" +page_title: "AWS: aws_resourcegroupstaggingapi_resources" +description: |- + Provides details about resource tagging. +--- + +# Data Source: aws_resourcegroupstaggingapi_resources + +Provides details about resource tagging. + +## Example Usage + +### Get All Resource Tag Mappings + +```hcl +data "aws_resourcegroupstaggingapi_resources" "test" {} +``` + +### Filter By Tag Key and Value + +```hcl +data "aws_resourcegroupstaggingapi_resources" "test" { + tag_filters { + key = "tag-key" + values = ["tag-value-1", "tag-value-2"] + } +} +``` + +### Filter By Resource Type + +```hcl +data "aws_resourcegroupstaggingapi_resources" "test" { + resource_type_filter = ["ec2:instance"] +} +``` + + +## Argument Reference + +The following arguments are supported: + +* `exclude_compliant_resources` - (Optional) Specifies whether to exclude resources that are compliant with the tag policy. You can use this parameter only if the `include_compliance_details` argument is also set to `true`. +* `include_compliance_details` - (Optional) Specifies whether to include details regarding the compliance with the effective tag policy. +* `tag_filters` - (Optional) Specifies a list of Tag Filters (keys and values) to restrict the output to only those resources that have the specified tag and, if included, the specified value. See (Tag Filters)[#tag-filters] below. Conflicts with `resource_arn_list`. +* `resource_type_filter` - (Optional) The constraints on the resources that you want returned. The format of each resource type is `service:resourceType`. For example, specifying a resource type of ec2 returns all Amazon EC2 resources (which includes EC2 instances). Specifying a resource type of `ec2:instance` returns only EC2 instances. +* `resource_arn_list` - (Optional) Specifies a list of ARNs of resources for which you want to retrieve tag data. Conflicts with `tag_filters`. + +### Tag Filters + +A `tag_filters` block supports the following arguments: + +If you do specify `tag_filters`, the response returns only those resources that are currently associated with the specified tag. +If you don't specify a `tag_filters`, the response includes all resources that were ever associated with tags. Resources that currently don't have associated tags are shown with an empty tag set. + +* `key` - (Required) One part of a key-value pair that makes up a tag. +* `values` - (Optional) The optional part of a key-value pair that make up a tag. + +## Attributes Reference + +In addition to all arguments above, the following attributes are exported: + +* `resource_tag_mapping_list` - A [Resource Tag Mapping List](#resource-tag-mapping-list)`resource_tag_mapping_list` block. documented below. + +### Resource Tag Mapping List + +A `resource_tag_mapping_list` block supports the following attributes: + +* `resource_arn` - The ARN of the resource. +* `compliance_details` - Information that shows whether a resource is compliant with the effective tag policy, including details on any noncompliant tag keys. Documented below. +* `tags` - tags assigned to the resource. + + From 696e18a8eda1039715d49167e65aee6ea63b0402 Mon Sep 17 00:00:00 2001 From: drfaust92 Date: Thu, 25 Feb 2021 00:39:31 +0200 Subject: [PATCH 04/17] changelog --- .changelog/17804.txt | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .changelog/17804.txt diff --git a/.changelog/17804.txt b/.changelog/17804.txt new file mode 100644 index 000000000000..f35e0f2a3786 --- /dev/null +++ b/.changelog/17804.txt @@ -0,0 +1,3 @@ +```release-note:data-source +aws_resourcegroupstaggingapi_resources +``` \ No newline at end of file From ee739907b89429a1bdbaeb690a5f8b407b737c7f Mon Sep 17 00:00:00 2001 From: drfaust92 Date: Thu, 25 Feb 2021 00:43:42 +0200 Subject: [PATCH 05/17] docs --- .../docs/d/resourcegroupstaggingapi_resources.html.markdown | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/website/docs/d/resourcegroupstaggingapi_resources.html.markdown b/website/docs/d/resourcegroupstaggingapi_resources.html.markdown index 506f66a14a4b..1c3b8dd05759 100644 --- a/website/docs/d/resourcegroupstaggingapi_resources.html.markdown +++ b/website/docs/d/resourcegroupstaggingapi_resources.html.markdown @@ -44,7 +44,7 @@ The following arguments are supported: * `exclude_compliant_resources` - (Optional) Specifies whether to exclude resources that are compliant with the tag policy. You can use this parameter only if the `include_compliance_details` argument is also set to `true`. * `include_compliance_details` - (Optional) Specifies whether to include details regarding the compliance with the effective tag policy. -* `tag_filters` - (Optional) Specifies a list of Tag Filters (keys and values) to restrict the output to only those resources that have the specified tag and, if included, the specified value. See (Tag Filters)[#tag-filters] below. Conflicts with `resource_arn_list`. +* `tag_filters` - (Optional) Specifies a list of Tag Filters (keys and values) to restrict the output to only those resources that have the specified tag and, if included, the specified value. See [Tag Filters](#tag-filters) below. Conflicts with `resource_arn_list`. * `resource_type_filter` - (Optional) The constraints on the resources that you want returned. The format of each resource type is `service:resourceType`. For example, specifying a resource type of ec2 returns all Amazon EC2 resources (which includes EC2 instances). Specifying a resource type of `ec2:instance` returns only EC2 instances. * `resource_arn_list` - (Optional) Specifies a list of ARNs of resources for which you want to retrieve tag data. Conflicts with `tag_filters`. @@ -56,7 +56,7 @@ If you do specify `tag_filters`, the response returns only those resources that If you don't specify a `tag_filters`, the response includes all resources that were ever associated with tags. Resources that currently don't have associated tags are shown with an empty tag set. * `key` - (Required) One part of a key-value pair that makes up a tag. -* `values` - (Optional) The optional part of a key-value pair that make up a tag. +* `values` - (Optional) The optional part of a key-value pair that make up a tag. ## Attributes Reference From 8679651b83a931b78c270ce2eda7fa9a8131fd5f Mon Sep 17 00:00:00 2001 From: drfaust92 Date: Thu, 25 Feb 2021 12:29:18 +0200 Subject: [PATCH 06/17] lint --- ...ta_source_aws_resourcegroupstaggingapi_resources_test.go | 6 ------ 1 file changed, 6 deletions(-) diff --git a/aws/data_source_aws_resourcegroupstaggingapi_resources_test.go b/aws/data_source_aws_resourcegroupstaggingapi_resources_test.go index ba114202818c..a786321b0b43 100644 --- a/aws/data_source_aws_resourcegroupstaggingapi_resources_test.go +++ b/aws/data_source_aws_resourcegroupstaggingapi_resources_test.go @@ -175,9 +175,3 @@ data "aws_resourcegroupstaggingapi_resources" "test" { exclude_compliant_resources = false } ` - -const testAccDataSourceAwsResourceGroupsTaggingAPIResourcesResourceTypeConfig = ` -data "aws_resourcegroupstaggingapi_resources" "test" { - resource_type_filters = ["ec2:instance"] -} -` From 85128cb9e5453c2adea05147f4300de8e204e0c1 Mon Sep 17 00:00:00 2001 From: Ilia Lazebnik Date: Thu, 25 Feb 2021 20:00:47 +0200 Subject: [PATCH 07/17] Update website/docs/d/resourcegroupstaggingapi_resources.html.markdown Co-authored-by: Kit Ewbank --- .../docs/d/resourcegroupstaggingapi_resources.html.markdown | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/website/docs/d/resourcegroupstaggingapi_resources.html.markdown b/website/docs/d/resourcegroupstaggingapi_resources.html.markdown index 1c3b8dd05759..60071a9889ce 100644 --- a/website/docs/d/resourcegroupstaggingapi_resources.html.markdown +++ b/website/docs/d/resourcegroupstaggingapi_resources.html.markdown @@ -45,7 +45,7 @@ The following arguments are supported: * `exclude_compliant_resources` - (Optional) Specifies whether to exclude resources that are compliant with the tag policy. You can use this parameter only if the `include_compliance_details` argument is also set to `true`. * `include_compliance_details` - (Optional) Specifies whether to include details regarding the compliance with the effective tag policy. * `tag_filters` - (Optional) Specifies a list of Tag Filters (keys and values) to restrict the output to only those resources that have the specified tag and, if included, the specified value. See [Tag Filters](#tag-filters) below. Conflicts with `resource_arn_list`. -* `resource_type_filter` - (Optional) The constraints on the resources that you want returned. The format of each resource type is `service:resourceType`. For example, specifying a resource type of ec2 returns all Amazon EC2 resources (which includes EC2 instances). Specifying a resource type of `ec2:instance` returns only EC2 instances. +* `resource_type_filter` - (Optional) The constraints on the resources that you want returned. The format of each resource type is `service:resourceType`. For example, specifying a resource type of `ec2` returns all Amazon EC2 resources (which includes EC2 instances). Specifying a resource type of `ec2:instance` returns only EC2 instances. * `resource_arn_list` - (Optional) Specifies a list of ARNs of resources for which you want to retrieve tag data. Conflicts with `tag_filters`. ### Tag Filters @@ -72,4 +72,3 @@ A `resource_tag_mapping_list` block supports the following attributes: * `compliance_details` - Information that shows whether a resource is compliant with the effective tag policy, including details on any noncompliant tag keys. Documented below. * `tags` - tags assigned to the resource. - From aabf7d0699182780f58f0c9e2e50fb46360d3e20 Mon Sep 17 00:00:00 2001 From: drfaust92 Date: Thu, 25 Feb 2021 22:53:32 +0200 Subject: [PATCH 08/17] label --- infrastructure/repository/labels-service.tf | 1 + 1 file changed, 1 insertion(+) diff --git a/infrastructure/repository/labels-service.tf b/infrastructure/repository/labels-service.tf index acd17a275089..2c39a1150afc 100644 --- a/infrastructure/repository/labels-service.tf +++ b/infrastructure/repository/labels-service.tf @@ -161,6 +161,7 @@ variable "service_labels" { "rds", "redshift", "resourcegroups", + "resourcegroupstaggingapi", "robomaker", "route53", "route53domains", From 3e1561f2488b5722ad711c208f66e8d62392fb8b Mon Sep 17 00:00:00 2001 From: drfaust92 Date: Thu, 25 Feb 2021 22:55:03 +0200 Subject: [PATCH 09/17] rename to filters --- aws/data_source_aws_resourcegroupstaggingapi_resources.go | 6 +++--- ..._source_aws_resourcegroupstaggingapi_resources_test.go | 2 +- .../d/resourcegroupstaggingapi_resources.html.markdown | 8 ++++---- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/aws/data_source_aws_resourcegroupstaggingapi_resources.go b/aws/data_source_aws_resourcegroupstaggingapi_resources.go index aceb75c48c0b..05a34e8a873a 100644 --- a/aws/data_source_aws_resourcegroupstaggingapi_resources.go +++ b/aws/data_source_aws_resourcegroupstaggingapi_resources.go @@ -26,7 +26,7 @@ func dataSourceAwsResourceGroupsTaggingAPIResources() *schema.Resource { Type: schema.TypeSet, Optional: true, Elem: &schema.Schema{Type: schema.TypeString}, - ConflictsWith: []string{"tag_filters"}, + ConflictsWith: []string{"filter"}, }, "resource_type_filters": { Type: schema.TypeSet, @@ -35,7 +35,7 @@ func dataSourceAwsResourceGroupsTaggingAPIResources() *schema.Resource { Elem: &schema.Schema{Type: schema.TypeString}, ConflictsWith: []string{"resource_arn_list"}, }, - "tag_filters": { + "filter": { Type: schema.TypeList, Optional: true, MaxItems: 50, @@ -110,7 +110,7 @@ func dataSourceAwsResourceGroupsTaggingAPIResourcesRead(d *schema.ResourceData, input.ResourceARNList = expandStringSet(v.(*schema.Set)) } - if v, ok := d.GetOk("tag_filters"); ok { + if v, ok := d.GetOk("filter"); ok { input.TagFilters = expandAwsResourceGroupsTaggingAPITagFilters(v.([]interface{})) } diff --git a/aws/data_source_aws_resourcegroupstaggingapi_resources_test.go b/aws/data_source_aws_resourcegroupstaggingapi_resources_test.go index a786321b0b43..6546d29d627a 100644 --- a/aws/data_source_aws_resourcegroupstaggingapi_resources_test.go +++ b/aws/data_source_aws_resourcegroupstaggingapi_resources_test.go @@ -126,7 +126,7 @@ resource "aws_api_gateway_rest_api" "test" { } data "aws_resourcegroupstaggingapi_resources" "test" { - tag_filters { + filter { key = "Key" } diff --git a/website/docs/d/resourcegroupstaggingapi_resources.html.markdown b/website/docs/d/resourcegroupstaggingapi_resources.html.markdown index 60071a9889ce..43844ce5ab3a 100644 --- a/website/docs/d/resourcegroupstaggingapi_resources.html.markdown +++ b/website/docs/d/resourcegroupstaggingapi_resources.html.markdown @@ -22,7 +22,7 @@ data "aws_resourcegroupstaggingapi_resources" "test" {} ```hcl data "aws_resourcegroupstaggingapi_resources" "test" { - tag_filters { + filter { key = "tag-key" values = ["tag-value-1", "tag-value-2"] } @@ -50,10 +50,10 @@ The following arguments are supported: ### Tag Filters -A `tag_filters` block supports the following arguments: +A `filter` block supports the following arguments: -If you do specify `tag_filters`, the response returns only those resources that are currently associated with the specified tag. -If you don't specify a `tag_filters`, the response includes all resources that were ever associated with tags. Resources that currently don't have associated tags are shown with an empty tag set. +If you do specify `filter`, the response returns only those resources that are currently associated with the specified tag. +If you don't specify a `filter`, the response includes all resources that were ever associated with tags. Resources that currently don't have associated tags are shown with an empty tag set. * `key` - (Required) One part of a key-value pair that makes up a tag. * `values` - (Optional) The optional part of a key-value pair that make up a tag. From 411a3ca83b8dd73af1f1724bb3aba10c8f198fb8 Mon Sep 17 00:00:00 2001 From: drfaust92 Date: Thu, 25 Feb 2021 22:59:39 +0200 Subject: [PATCH 10/17] docs --- .../d/resourcegroupstaggingapi_resources.html.markdown | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/website/docs/d/resourcegroupstaggingapi_resources.html.markdown b/website/docs/d/resourcegroupstaggingapi_resources.html.markdown index 43844ce5ab3a..7c15f78d14c7 100644 --- a/website/docs/d/resourcegroupstaggingapi_resources.html.markdown +++ b/website/docs/d/resourcegroupstaggingapi_resources.html.markdown @@ -44,11 +44,17 @@ The following arguments are supported: * `exclude_compliant_resources` - (Optional) Specifies whether to exclude resources that are compliant with the tag policy. You can use this parameter only if the `include_compliance_details` argument is also set to `true`. * `include_compliance_details` - (Optional) Specifies whether to include details regarding the compliance with the effective tag policy. +<<<<<<< HEAD * `tag_filters` - (Optional) Specifies a list of Tag Filters (keys and values) to restrict the output to only those resources that have the specified tag and, if included, the specified value. See [Tag Filters](#tag-filters) below. Conflicts with `resource_arn_list`. * `resource_type_filter` - (Optional) The constraints on the resources that you want returned. The format of each resource type is `service:resourceType`. For example, specifying a resource type of `ec2` returns all Amazon EC2 resources (which includes EC2 instances). Specifying a resource type of `ec2:instance` returns only EC2 instances. * `resource_arn_list` - (Optional) Specifies a list of ARNs of resources for which you want to retrieve tag data. Conflicts with `tag_filters`. +======= +* `filter` - (Optional) Specifies a list of Tag Filters (keys and values) to restrict the output to only those resources that have the specified tag and, if included, the specified value. See [Filter](#filter) below. Conflicts with `resource_arn_list`. +* `resource_type_filter` - (Optional) The constraints on the resources that you want returned. The format of each resource type is `service:resourceType`. For example, specifying a resource type of ec2 returns all Amazon EC2 resources (which includes EC2 instances). Specifying a resource type of `ec2:instance` returns only EC2 instances. +* `resource_arn_list` - (Optional) Specifies a list of ARNs of resources for which you want to retrieve tag data. Conflicts with `filter`. +>>>>>>> a6eed3340 (docs) -### Tag Filters +### Filter A `filter` block supports the following arguments: From 3a306cf9af3704a02b4049adc0a90b6fb992e051 Mon Sep 17 00:00:00 2001 From: drfaust92 Date: Thu, 25 Feb 2021 22:59:46 +0200 Subject: [PATCH 11/17] ignore config --- aws/data_source_aws_resourcegroupstaggingapi_resources.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/aws/data_source_aws_resourcegroupstaggingapi_resources.go b/aws/data_source_aws_resourcegroupstaggingapi_resources.go index 05a34e8a873a..3241dbb42990 100644 --- a/aws/data_source_aws_resourcegroupstaggingapi_resources.go +++ b/aws/data_source_aws_resourcegroupstaggingapi_resources.go @@ -134,7 +134,7 @@ func dataSourceAwsResourceGroupsTaggingAPIResourcesRead(d *schema.ResourceData, d.SetId(meta.(*AWSClient).partition) - if err := d.Set("resource_tag_mapping_list", flattenAwsResourceGroupsTaggingAPIResourcesTagMappingList(taggings)); err != nil { + if err := d.Set("resource_tag_mapping_list", flattenAwsResourceGroupsTaggingAPIResourcesTagMappingList(taggings, meta)); err != nil { return fmt.Errorf("error setting resource tag mapping list: %w", err) } @@ -159,13 +159,14 @@ func expandAwsResourceGroupsTaggingAPITagFilters(filters []interface{}) []*resou return result } -func flattenAwsResourceGroupsTaggingAPIResourcesTagMappingList(list []*resourcegroupstaggingapi.ResourceTagMapping) []map[string]interface{} { +func flattenAwsResourceGroupsTaggingAPIResourcesTagMappingList(list []*resourcegroupstaggingapi.ResourceTagMapping, meta interface{}) []map[string]interface{} { result := make([]map[string]interface{}, 0, len(list)) + ignoreTagsConfig := meta.(*AWSClient).IgnoreTagsConfig for _, i := range list { l := map[string]interface{}{ "resource_arn": aws.StringValue(i.ResourceARN), - "tags": keyvaluetags.ResourcegroupstaggingapiKeyValueTags(i.Tags).IgnoreAws().Map(), + "tags": keyvaluetags.ResourcegroupstaggingapiKeyValueTags(i.Tags).IgnoreAws().IgnoreConfig(ignoreTagsConfig).Map(), } if i.ComplianceDetails != nil { From c601d0012c9e1e54d73a0cc5a29e145b645e3366 Mon Sep 17 00:00:00 2001 From: drfaust92 Date: Thu, 25 Feb 2021 23:02:26 +0200 Subject: [PATCH 12/17] docs --- .../d/resourcegroupstaggingapi_resources.html.markdown | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/website/docs/d/resourcegroupstaggingapi_resources.html.markdown b/website/docs/d/resourcegroupstaggingapi_resources.html.markdown index 7c15f78d14c7..1f43f2cf97ce 100644 --- a/website/docs/d/resourcegroupstaggingapi_resources.html.markdown +++ b/website/docs/d/resourcegroupstaggingapi_resources.html.markdown @@ -44,15 +44,9 @@ The following arguments are supported: * `exclude_compliant_resources` - (Optional) Specifies whether to exclude resources that are compliant with the tag policy. You can use this parameter only if the `include_compliance_details` argument is also set to `true`. * `include_compliance_details` - (Optional) Specifies whether to include details regarding the compliance with the effective tag policy. -<<<<<<< HEAD -* `tag_filters` - (Optional) Specifies a list of Tag Filters (keys and values) to restrict the output to only those resources that have the specified tag and, if included, the specified value. See [Tag Filters](#tag-filters) below. Conflicts with `resource_arn_list`. -* `resource_type_filter` - (Optional) The constraints on the resources that you want returned. The format of each resource type is `service:resourceType`. For example, specifying a resource type of `ec2` returns all Amazon EC2 resources (which includes EC2 instances). Specifying a resource type of `ec2:instance` returns only EC2 instances. -* `resource_arn_list` - (Optional) Specifies a list of ARNs of resources for which you want to retrieve tag data. Conflicts with `tag_filters`. -======= * `filter` - (Optional) Specifies a list of Tag Filters (keys and values) to restrict the output to only those resources that have the specified tag and, if included, the specified value. See [Filter](#filter) below. Conflicts with `resource_arn_list`. -* `resource_type_filter` - (Optional) The constraints on the resources that you want returned. The format of each resource type is `service:resourceType`. For example, specifying a resource type of ec2 returns all Amazon EC2 resources (which includes EC2 instances). Specifying a resource type of `ec2:instance` returns only EC2 instances. +* `resource_type_filter` - (Optional) The constraints on the resources that you want returned. The format of each resource type is `service:resourceType`. For example, specifying a resource type of `ec2` returns all Amazon EC2 resources (which includes EC2 instances). Specifying a resource type of `ec2:instance` returns only EC2 instances. * `resource_arn_list` - (Optional) Specifies a list of ARNs of resources for which you want to retrieve tag data. Conflicts with `filter`. ->>>>>>> a6eed3340 (docs) ### Filter From 6a611564b53d37a8bdd63d5a6632f07018704c02 Mon Sep 17 00:00:00 2001 From: drfaust92 Date: Sat, 27 Mar 2021 19:50:55 +0300 Subject: [PATCH 13/17] docs --- .../docs/d/resourcegroupstaggingapi_resources.html.markdown | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/website/docs/d/resourcegroupstaggingapi_resources.html.markdown b/website/docs/d/resourcegroupstaggingapi_resources.html.markdown index 1f43f2cf97ce..92e9a22807fc 100644 --- a/website/docs/d/resourcegroupstaggingapi_resources.html.markdown +++ b/website/docs/d/resourcegroupstaggingapi_resources.html.markdown @@ -14,13 +14,13 @@ Provides details about resource tagging. ### Get All Resource Tag Mappings -```hcl +```terraform data "aws_resourcegroupstaggingapi_resources" "test" {} ``` ### Filter By Tag Key and Value -```hcl +```terraform data "aws_resourcegroupstaggingapi_resources" "test" { filter { key = "tag-key" @@ -31,7 +31,7 @@ data "aws_resourcegroupstaggingapi_resources" "test" { ### Filter By Resource Type -```hcl +```terraform data "aws_resourcegroupstaggingapi_resources" "test" { resource_type_filter = ["ec2:instance"] } From 6a066b7a053c1b948f3be903a3711a91ada0ed2c Mon Sep 17 00:00:00 2001 From: drfaust92 Date: Sat, 27 Mar 2021 21:15:25 +0300 Subject: [PATCH 14/17] error check --- ...resourcegroupstaggingapi_resources_test.go | 26 ++++++++++++------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/aws/data_source_aws_resourcegroupstaggingapi_resources_test.go b/aws/data_source_aws_resourcegroupstaggingapi_resources_test.go index 6546d29d627a..b9ccc4311cde 100644 --- a/aws/data_source_aws_resourcegroupstaggingapi_resources_test.go +++ b/aws/data_source_aws_resourcegroupstaggingapi_resources_test.go @@ -4,6 +4,7 @@ import ( "fmt" "testing" + "github.com/aws/aws-sdk-go/service/resourcegroupstaggingapi" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" ) @@ -12,8 +13,9 @@ func TestAccDataSourceAwsResourceGroupsTaggingAPIResources_basic(t *testing.T) { dataSourceName := "data.aws_resourcegroupstaggingapi_resources.test" resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, + PreCheck: func() { testAccPreCheck(t) }, + ErrorCheck: testAccErrorCheck(t, resourcegroupstaggingapi.EndpointsID), + Providers: testAccProviders, Steps: []resource.TestStep{ { Config: testAccDataSourceAwsResourceGroupsTaggingAPIResourcesBasicConfig, @@ -32,8 +34,9 @@ func TestAccDataSourceAwsResourceGroupsTaggingAPIResources_tag_key_filter(t *tes rName := acctest.RandomWithPrefix("tf-acc-test") resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, + PreCheck: func() { testAccPreCheck(t) }, + ErrorCheck: testAccErrorCheck(t, resourcegroupstaggingapi.EndpointsID), + Providers: testAccProviders, Steps: []resource.TestStep{ { Config: testAccDataSourceAwsResourceGroupsTaggingAPIResourcesTagKeyFilterConfig(rName), @@ -52,8 +55,9 @@ func TestAccDataSourceAwsResourceGroupsTaggingAPIResources_compliance(t *testing dataSourceName := "data.aws_resourcegroupstaggingapi_resources.test" resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, + PreCheck: func() { testAccPreCheck(t) }, + ErrorCheck: testAccErrorCheck(t, resourcegroupstaggingapi.EndpointsID), + Providers: testAccProviders, Steps: []resource.TestStep{ { Config: testAccDataSourceAwsResourceGroupsTaggingAPIResourcesComplianceConfig, @@ -73,8 +77,9 @@ func TestAccDataSourceAwsResourceGroupsTaggingAPIResources_resource_type_filters rName := acctest.RandomWithPrefix("tf-acc-test") resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, + PreCheck: func() { testAccPreCheck(t) }, + ErrorCheck: testAccErrorCheck(t, resourcegroupstaggingapi.EndpointsID), + Providers: testAccProviders, Steps: []resource.TestStep{ { Config: testAccDataSourceAwsResourceGroupsTaggingAPIResourcesResourceTypeFiltersConfig(rName), @@ -95,8 +100,9 @@ func TestAccDataSourceAwsResourceGroupsTaggingAPIResources_resource_arn_list(t * rName := acctest.RandomWithPrefix("tf-acc-test") resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, + PreCheck: func() { testAccPreCheck(t) }, + ErrorCheck: testAccErrorCheck(t, resourcegroupstaggingapi.EndpointsID), + Providers: testAccProviders, Steps: []resource.TestStep{ { Config: testAccDataSourceAwsResourceGroupsTaggingAPIResourcesResourceARNListConfig(rName), From f1a4c070ce19fee5f5a7392ed5ee49e4f080b5c6 Mon Sep 17 00:00:00 2001 From: Brian Flad Date: Thu, 29 Apr 2021 15:00:21 -0400 Subject: [PATCH 15/17] Apply suggestions from code review --- ...source_aws_resourcegroupstaggingapi_resources.go | 13 ++++++------- ...e_aws_resourcegroupstaggingapi_resources_test.go | 2 +- ...resourcegroupstaggingapi_resources.html.markdown | 13 ++++++------- 3 files changed, 13 insertions(+), 15 deletions(-) diff --git a/aws/data_source_aws_resourcegroupstaggingapi_resources.go b/aws/data_source_aws_resourcegroupstaggingapi_resources.go index 3241dbb42990..710be0c80b1c 100644 --- a/aws/data_source_aws_resourcegroupstaggingapi_resources.go +++ b/aws/data_source_aws_resourcegroupstaggingapi_resources.go @@ -35,7 +35,7 @@ func dataSourceAwsResourceGroupsTaggingAPIResources() *schema.Resource { Elem: &schema.Schema{Type: schema.TypeString}, ConflictsWith: []string{"resource_arn_list"}, }, - "filter": { + "tag_filter": { Type: schema.TypeList, Optional: true, MaxItems: 50, @@ -110,7 +110,7 @@ func dataSourceAwsResourceGroupsTaggingAPIResourcesRead(d *schema.ResourceData, input.ResourceARNList = expandStringSet(v.(*schema.Set)) } - if v, ok := d.GetOk("filter"); ok { + if v, ok := d.GetOk("tag_filter"); ok { input.TagFilters = expandAwsResourceGroupsTaggingAPITagFilters(v.([]interface{})) } @@ -129,12 +129,12 @@ func dataSourceAwsResourceGroupsTaggingAPIResourcesRead(d *schema.ResourceData, return !lastPage }) if err != nil { - return err + return fmt.Errorf("error getting Resource Groups Tags API Resources: %w", err) } d.SetId(meta.(*AWSClient).partition) - if err := d.Set("resource_tag_mapping_list", flattenAwsResourceGroupsTaggingAPIResourcesTagMappingList(taggings, meta)); err != nil { + if err := d.Set("resource_tag_mapping_list", flattenAwsResourceGroupsTaggingAPIResourcesTagMappingList(taggings)); err != nil { return fmt.Errorf("error setting resource tag mapping list: %w", err) } @@ -159,14 +159,13 @@ func expandAwsResourceGroupsTaggingAPITagFilters(filters []interface{}) []*resou return result } -func flattenAwsResourceGroupsTaggingAPIResourcesTagMappingList(list []*resourcegroupstaggingapi.ResourceTagMapping, meta interface{}) []map[string]interface{} { +func flattenAwsResourceGroupsTaggingAPIResourcesTagMappingList(list []*resourcegroupstaggingapi.ResourceTagMapping) []map[string]interface{} { result := make([]map[string]interface{}, 0, len(list)) - ignoreTagsConfig := meta.(*AWSClient).IgnoreTagsConfig for _, i := range list { l := map[string]interface{}{ "resource_arn": aws.StringValue(i.ResourceARN), - "tags": keyvaluetags.ResourcegroupstaggingapiKeyValueTags(i.Tags).IgnoreAws().IgnoreConfig(ignoreTagsConfig).Map(), + "tags": keyvaluetags.ResourcegroupstaggingapiKeyValueTags(i.Tags).Map(), } if i.ComplianceDetails != nil { diff --git a/aws/data_source_aws_resourcegroupstaggingapi_resources_test.go b/aws/data_source_aws_resourcegroupstaggingapi_resources_test.go index b9ccc4311cde..8e207676c4c8 100644 --- a/aws/data_source_aws_resourcegroupstaggingapi_resources_test.go +++ b/aws/data_source_aws_resourcegroupstaggingapi_resources_test.go @@ -132,7 +132,7 @@ resource "aws_api_gateway_rest_api" "test" { } data "aws_resourcegroupstaggingapi_resources" "test" { - filter { + tag_filter { key = "Key" } diff --git a/website/docs/d/resourcegroupstaggingapi_resources.html.markdown b/website/docs/d/resourcegroupstaggingapi_resources.html.markdown index 92e9a22807fc..ba51ec4b61c3 100644 --- a/website/docs/d/resourcegroupstaggingapi_resources.html.markdown +++ b/website/docs/d/resourcegroupstaggingapi_resources.html.markdown @@ -22,7 +22,7 @@ data "aws_resourcegroupstaggingapi_resources" "test" {} ```terraform data "aws_resourcegroupstaggingapi_resources" "test" { - filter { + tag_filter { key = "tag-key" values = ["tag-value-1", "tag-value-2"] } @@ -44,16 +44,16 @@ The following arguments are supported: * `exclude_compliant_resources` - (Optional) Specifies whether to exclude resources that are compliant with the tag policy. You can use this parameter only if the `include_compliance_details` argument is also set to `true`. * `include_compliance_details` - (Optional) Specifies whether to include details regarding the compliance with the effective tag policy. -* `filter` - (Optional) Specifies a list of Tag Filters (keys and values) to restrict the output to only those resources that have the specified tag and, if included, the specified value. See [Filter](#filter) below. Conflicts with `resource_arn_list`. +* `tag_filter` - (Optional) Specifies a list of Tag Filters (keys and values) to restrict the output to only those resources that have the specified tag and, if included, the specified value. See [Tag Filter](#tag-filter) below. Conflicts with `resource_arn_list`. * `resource_type_filter` - (Optional) The constraints on the resources that you want returned. The format of each resource type is `service:resourceType`. For example, specifying a resource type of `ec2` returns all Amazon EC2 resources (which includes EC2 instances). Specifying a resource type of `ec2:instance` returns only EC2 instances. * `resource_arn_list` - (Optional) Specifies a list of ARNs of resources for which you want to retrieve tag data. Conflicts with `filter`. -### Filter +### Tag Filter -A `filter` block supports the following arguments: +A `tag_filter` block supports the following arguments: -If you do specify `filter`, the response returns only those resources that are currently associated with the specified tag. -If you don't specify a `filter`, the response includes all resources that were ever associated with tags. Resources that currently don't have associated tags are shown with an empty tag set. +If you do specify `tag_filter`, the response returns only those resources that are currently associated with the specified tag. +If you don't specify a `tag_filter`, the response includes all resources that were ever associated with tags. Resources that currently don't have associated tags are shown with an empty tag set. * `key` - (Required) One part of a key-value pair that makes up a tag. * `values` - (Optional) The optional part of a key-value pair that make up a tag. @@ -71,4 +71,3 @@ A `resource_tag_mapping_list` block supports the following attributes: * `resource_arn` - The ARN of the resource. * `compliance_details` - Information that shows whether a resource is compliant with the effective tag policy, including details on any noncompliant tag keys. Documented below. * `tags` - tags assigned to the resource. - From 974b36e303d63fc3cb59399e926fee524ab506de Mon Sep 17 00:00:00 2001 From: Brian Flad Date: Thu, 29 Apr 2021 15:06:50 -0400 Subject: [PATCH 16/17] Apply suggestions from code review --- .changelog/17804.txt | 4 ++-- ...ourcegroupstaggingapi_resources.html.markdown | 16 +++++++--------- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/.changelog/17804.txt b/.changelog/17804.txt index f35e0f2a3786..8efd4f8c8154 100644 --- a/.changelog/17804.txt +++ b/.changelog/17804.txt @@ -1,3 +1,3 @@ -```release-note:data-source +```release-note:new-data-source aws_resourcegroupstaggingapi_resources -``` \ No newline at end of file +``` diff --git a/website/docs/d/resourcegroupstaggingapi_resources.html.markdown b/website/docs/d/resourcegroupstaggingapi_resources.html.markdown index ba51ec4b61c3..f35daf96fdca 100644 --- a/website/docs/d/resourcegroupstaggingapi_resources.html.markdown +++ b/website/docs/d/resourcegroupstaggingapi_resources.html.markdown @@ -62,12 +62,10 @@ If you don't specify a `tag_filter`, the response includes all resources that we In addition to all arguments above, the following attributes are exported: -* `resource_tag_mapping_list` - A [Resource Tag Mapping List](#resource-tag-mapping-list)`resource_tag_mapping_list` block. documented below. - -### Resource Tag Mapping List - -A `resource_tag_mapping_list` block supports the following attributes: - -* `resource_arn` - The ARN of the resource. -* `compliance_details` - Information that shows whether a resource is compliant with the effective tag policy, including details on any noncompliant tag keys. Documented below. -* `tags` - tags assigned to the resource. +* `resource_tag_mapping_list` - List of objects matching the search criteria. + * `compliance_details` - List of objects with information that shows whether a resource is compliant with the effective tag policy, including details on any noncompliant tag keys. + * `compliance_status` - Whether the resource is compliant. + * `keys_with_noncompliant_values ` - Set of tag keys with non-compliant tag values. + * `non_compliant_keys ` - Set of non-compliant tag keys. + * `resource_arn` - ARN of the resource. + * `tags` - Map of tags assigned to the resource. From 9408f23a897dee576765e2eaba72d5776fd773a8 Mon Sep 17 00:00:00 2001 From: Brian Flad Date: Thu, 29 Apr 2021 15:11:13 -0400 Subject: [PATCH 17/17] Update aws/data_source_aws_resourcegroupstaggingapi_resources.go --- aws/data_source_aws_resourcegroupstaggingapi_resources.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aws/data_source_aws_resourcegroupstaggingapi_resources.go b/aws/data_source_aws_resourcegroupstaggingapi_resources.go index 710be0c80b1c..b1c1eebe723c 100644 --- a/aws/data_source_aws_resourcegroupstaggingapi_resources.go +++ b/aws/data_source_aws_resourcegroupstaggingapi_resources.go @@ -26,7 +26,7 @@ func dataSourceAwsResourceGroupsTaggingAPIResources() *schema.Resource { Type: schema.TypeSet, Optional: true, Elem: &schema.Schema{Type: schema.TypeString}, - ConflictsWith: []string{"filter"}, + ConflictsWith: []string{"tag_filter"}, }, "resource_type_filters": { Type: schema.TypeSet,