From fbd0424f1433b0d3888c4129a9cbc6406b46f54e Mon Sep 17 00:00:00 2001 From: Will May Date: Sat, 15 May 2021 16:37:05 +0100 Subject: [PATCH 01/12] Expose the default tags configured on a provider as a data source Allow the provider `default_tags` to be exposed as a data source so that the tags can be added to other areas where they are not automatically applied, like the `volume_tags` of a `aws_instance` or the `tag_specifications` of a `aws_launch_template`. Closes #19370 --- aws/data_source_aws_default_tags.go | 23 +++++++++++ aws/data_source_aws_default_tags_test.go | 38 +++++++++++++++++ aws/provider.go | 1 + website/docs/d/default_tags.markdown | 52 ++++++++++++++++++++++++ 4 files changed, 114 insertions(+) create mode 100644 aws/data_source_aws_default_tags.go create mode 100644 aws/data_source_aws_default_tags_test.go create mode 100644 website/docs/d/default_tags.markdown diff --git a/aws/data_source_aws_default_tags.go b/aws/data_source_aws_default_tags.go new file mode 100644 index 00000000000..3c851879230 --- /dev/null +++ b/aws/data_source_aws_default_tags.go @@ -0,0 +1,23 @@ +package aws + +import "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + +func dataSourceAwsDefaultTags() *schema.Resource { + return &schema.Resource{ + Read: dataSourceAwsDefaultTagsRead, + + Schema: map[string]*schema.Schema{ + "tags": tagsSchemaComputed(), + }, + } +} + +func dataSourceAwsDefaultTagsRead(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*AWSClient).DefaultTagsConfig + if err := d.Set("tags", conn.Tags.Map()); err != nil { + return err + } + d.SetId(meta.(*AWSClient).partition) + + return nil +} diff --git a/aws/data_source_aws_default_tags_test.go b/aws/data_source_aws_default_tags_test.go new file mode 100644 index 00000000000..cb8b6ddb930 --- /dev/null +++ b/aws/data_source_aws_default_tags_test.go @@ -0,0 +1,38 @@ +package aws + +import ( + "testing" + + "github.com/aws/aws-sdk-go/service/ec2" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" +) + +func TestAWSDefaultTagsDataSource_basic(t *testing.T) { + var providers []*schema.Provider + + dataSourceName := "data.aws_default_tags.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ErrorCheck: testAccErrorCheck(t, ec2.EndpointsID), + ProviderFactories: testAccProviderFactoriesInternal(&providers), + CheckDestroy: nil, + Steps: []resource.TestStep{ + { + Config: composeConfig( + testAccAWSProviderConfigDefaultTags_Tags1("first", "value"), + testAccAWSDefaultTagsDataSource(), + ), + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr(dataSourceName, "tags.%", "1"), + resource.TestCheckResourceAttr(dataSourceName, "tags.first", "value"), + ), + }, + }, + }) +} + +func testAccAWSDefaultTagsDataSource() string { + return `data "aws_default_tags" "test" {}` +} diff --git a/aws/provider.go b/aws/provider.go index b0cc423bedc..c58c5523273 100644 --- a/aws/provider.go +++ b/aws/provider.go @@ -226,6 +226,7 @@ func Provider() *schema.Provider { "aws_codecommit_repository": dataSourceAwsCodeCommitRepository(), "aws_codestarconnections_connection": dataSourceAwsCodeStarConnectionsConnection(), "aws_cur_report_definition": dataSourceAwsCurReportDefinition(), + "aws_default_tags": dataSourceAwsDefaultTags(), "aws_db_cluster_snapshot": dataSourceAwsDbClusterSnapshot(), "aws_db_event_categories": dataSourceAwsDbEventCategories(), "aws_db_instance": dataSourceAwsDbInstance(), diff --git a/website/docs/d/default_tags.markdown b/website/docs/d/default_tags.markdown new file mode 100644 index 00000000000..e92f80d1c57 --- /dev/null +++ b/website/docs/d/default_tags.markdown @@ -0,0 +1,52 @@ +--- +subcategory: "" +layout: "aws" +page_title: "AWS: aws_default_tags" +description: |- +Expose the default tags configured on the provider. +--- + +# Data Source: aws_default_Tags + +Use this data source to get the default tags configured on the provider. + +It is intended to be used to optionally add the default tags to resources not _directly_ managed by the Terraform +resource - such as the instances underneath an autoscaling group or the volumes created for an instance. + +## Example Usage + +```terraform +provider "aws" { + default_tags { + tags = { + Environment = "Test" + Name = "Provider Tag" + } + } +} +data "aws_default_tags" "tags" {} + +resource "aws_autoscaling_group" "group" { + # ... + dynamic "tag" { + for_each = data.aws_default_tags.tags.tags + content { + key = tag.key + value = tag.value + propagate_at_launch = true + } + } +} +``` + +## Argument Reference + +There are no arguments available for this data source. + +## Attributes Reference + +In addition to all arguments above, the following attributes are exported: + +* `tags` - Any default tags set on the provider. + * `tags.#.key` - The key name of the tag. + * `tags.#.value` - The value of the tag. From b0098e52d8ba09584fc6fea58be6619c150ba392 Mon Sep 17 00:00:00 2001 From: Will May Date: Sat, 15 May 2021 16:46:33 +0100 Subject: [PATCH 02/12] Add CHANGELOG --- .changelog/19391.txt | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .changelog/19391.txt diff --git a/.changelog/19391.txt b/.changelog/19391.txt new file mode 100644 index 00000000000..d6ba5a475fd --- /dev/null +++ b/.changelog/19391.txt @@ -0,0 +1,3 @@ +```release-notes:enhancement +data-source/aws_default_tags: Add `aws_default_tags` data source to expose the `default_tags` configured on the provider +``` \ No newline at end of file From faa36ad5ff2cd68aa203fe4e6a91ec5fbb73f04c Mon Sep 17 00:00:00 2001 From: Will May Date: Sat, 15 May 2021 16:54:18 +0100 Subject: [PATCH 03/12] Changes from automated code review * Fix documentation indentation * Fix test naming * Include `IgnoreConfig` in tags --- aws/data_source_aws_default_tags.go | 3 ++- aws/data_source_aws_default_tags_test.go | 2 +- website/docs/d/default_tags.markdown | 8 ++++---- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/aws/data_source_aws_default_tags.go b/aws/data_source_aws_default_tags.go index 3c851879230..1d7a5271b03 100644 --- a/aws/data_source_aws_default_tags.go +++ b/aws/data_source_aws_default_tags.go @@ -14,7 +14,8 @@ func dataSourceAwsDefaultTags() *schema.Resource { func dataSourceAwsDefaultTagsRead(d *schema.ResourceData, meta interface{}) error { conn := meta.(*AWSClient).DefaultTagsConfig - if err := d.Set("tags", conn.Tags.Map()); err != nil { + ignoreTagsConfig := meta.(*AWSClient).IgnoreTagsConfig + if err := d.Set("tags", conn.Tags.IgnoreConfig(ignoreTagsConfig).Map()); err != nil { return err } d.SetId(meta.(*AWSClient).partition) diff --git a/aws/data_source_aws_default_tags_test.go b/aws/data_source_aws_default_tags_test.go index cb8b6ddb930..3e6a96fb156 100644 --- a/aws/data_source_aws_default_tags_test.go +++ b/aws/data_source_aws_default_tags_test.go @@ -8,7 +8,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) -func TestAWSDefaultTagsDataSource_basic(t *testing.T) { +func TestAccAWSDefaultTagsDataSource_basic(t *testing.T) { var providers []*schema.Provider dataSourceName := "data.aws_default_tags.test" diff --git a/website/docs/d/default_tags.markdown b/website/docs/d/default_tags.markdown index e92f80d1c57..17893879240 100644 --- a/website/docs/d/default_tags.markdown +++ b/website/docs/d/default_tags.markdown @@ -3,7 +3,7 @@ subcategory: "" layout: "aws" page_title: "AWS: aws_default_tags" description: |- -Expose the default tags configured on the provider. + Expose the default tags configured on the provider. --- # Data Source: aws_default_Tags @@ -20,7 +20,7 @@ provider "aws" { default_tags { tags = { Environment = "Test" - Name = "Provider Tag" + Name = "Provider Tag" } } } @@ -31,8 +31,8 @@ resource "aws_autoscaling_group" "group" { dynamic "tag" { for_each = data.aws_default_tags.tags.tags content { - key = tag.key - value = tag.value + key = tag.key + value = tag.value propagate_at_launch = true } } From 1aaf9875dccff42316f669fd4cea4089ccddd738 Mon Sep 17 00:00:00 2001 From: Will May Date: Sat, 15 May 2021 17:02:19 +0100 Subject: [PATCH 04/12] Placate semgrep Ignore AWS tags that may have been set in the providers default tags --- aws/data_source_aws_default_tags.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aws/data_source_aws_default_tags.go b/aws/data_source_aws_default_tags.go index 1d7a5271b03..86d4c842b09 100644 --- a/aws/data_source_aws_default_tags.go +++ b/aws/data_source_aws_default_tags.go @@ -15,7 +15,7 @@ func dataSourceAwsDefaultTags() *schema.Resource { func dataSourceAwsDefaultTagsRead(d *schema.ResourceData, meta interface{}) error { conn := meta.(*AWSClient).DefaultTagsConfig ignoreTagsConfig := meta.(*AWSClient).IgnoreTagsConfig - if err := d.Set("tags", conn.Tags.IgnoreConfig(ignoreTagsConfig).Map()); err != nil { + if err := d.Set("tags", conn.Tags.IgnoreAws().IgnoreConfig(ignoreTagsConfig).Map()); err != nil { return err } d.SetId(meta.(*AWSClient).partition) From 31730091a05172681dfbcdc61dee8f3994e22fec Mon Sep 17 00:00:00 2001 From: Dirk Avery Date: Fri, 21 May 2021 12:58:49 -0400 Subject: [PATCH 05/12] docs/ds/default_tags: Minor tweaks --- website/docs/d/default_tags.markdown | 31 +++++++++++++++++++--------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/website/docs/d/default_tags.markdown b/website/docs/d/default_tags.markdown index 17893879240..c6fd19de038 100644 --- a/website/docs/d/default_tags.markdown +++ b/website/docs/d/default_tags.markdown @@ -3,18 +3,25 @@ subcategory: "" layout: "aws" page_title: "AWS: aws_default_tags" description: |- - Expose the default tags configured on the provider. + Access the default tags configured on the provider. --- # Data Source: aws_default_Tags Use this data source to get the default tags configured on the provider. -It is intended to be used to optionally add the default tags to resources not _directly_ managed by the Terraform -resource - such as the instances underneath an autoscaling group or the volumes created for an instance. +With this data source, you can apply default tags to resources not _directly_ managed by a Terraform resource, such as the instances underneath an Auto Scaling group or the volumes created for an instance. ## Example Usage +### Basic Usage + +```terraform +data "aws_default_tags" "example" {} +``` + +### Dynamically Apply Default Tags to Auto Scaling Group + ```terraform provider "aws" { default_tags { @@ -24,12 +31,13 @@ provider "aws" { } } } -data "aws_default_tags" "tags" {} -resource "aws_autoscaling_group" "group" { +data "aws_default_tags" "example" {} + +resource "aws_autoscaling_group" "example" { # ... dynamic "tag" { - for_each = data.aws_default_tags.tags.tags + for_each = data.aws_default_tags.example.tags content { key = tag.key value = tag.value @@ -41,12 +49,15 @@ resource "aws_autoscaling_group" "group" { ## Argument Reference -There are no arguments available for this data source. +This data source has no arguments. ## Attributes Reference In addition to all arguments above, the following attributes are exported: -* `tags` - Any default tags set on the provider. - * `tags.#.key` - The key name of the tag. - * `tags.#.value` - The value of the tag. +* `tags` - Blocks of default tags set on the provider. See details below. + +### tags + +* `key` - Key name of the tag (i.e., `tags.#.key`). +* `value` - Value of the tag (i.e., `tags.#.value`). From f7bef0baf3e7b8ce958740f39d7a4019b8b01509 Mon Sep 17 00:00:00 2001 From: Dirk Avery Date: Fri, 21 May 2021 12:59:52 -0400 Subject: [PATCH 06/12] docs/ds/default_tags: Minor tweak --- website/docs/d/default_tags.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/docs/d/default_tags.markdown b/website/docs/d/default_tags.markdown index c6fd19de038..ea38cfcafaf 100644 --- a/website/docs/d/default_tags.markdown +++ b/website/docs/d/default_tags.markdown @@ -10,7 +10,7 @@ description: |- Use this data source to get the default tags configured on the provider. -With this data source, you can apply default tags to resources not _directly_ managed by a Terraform resource, such as the instances underneath an Auto Scaling group or the volumes created for an instance. +With this data source, you can apply default tags to resources not _directly_ managed by a Terraform resource, such as the instances underneath an Auto Scaling group or the volumes created for an EC2 instance. ## Example Usage From d11ef97f44c704ebc7b8208680ffbda2d33d99c6 Mon Sep 17 00:00:00 2001 From: Dirk Avery Date: Fri, 21 May 2021 13:02:36 -0400 Subject: [PATCH 07/12] ds/default_tags: Clean up changelog --- .changelog/19391.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.changelog/19391.txt b/.changelog/19391.txt index d6ba5a475fd..113f81bf3fc 100644 --- a/.changelog/19391.txt +++ b/.changelog/19391.txt @@ -1,3 +1,3 @@ -```release-notes:enhancement -data-source/aws_default_tags: Add `aws_default_tags` data source to expose the `default_tags` configured on the provider +```release-notes:new-data-source +aws_default_tags ``` \ No newline at end of file From 49b4ca9d2566ff1c06f298825f08b108fe17ff7e Mon Sep 17 00:00:00 2001 From: Dirk Avery Date: Fri, 21 May 2021 13:27:01 -0400 Subject: [PATCH 08/12] ds/default_tags: Fix nil pointer panic --- aws/data_source_aws_default_tags.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/aws/data_source_aws_default_tags.go b/aws/data_source_aws_default_tags.go index 86d4c842b09..7f8cbf81087 100644 --- a/aws/data_source_aws_default_tags.go +++ b/aws/data_source_aws_default_tags.go @@ -13,12 +13,18 @@ func dataSourceAwsDefaultTags() *schema.Resource { } func dataSourceAwsDefaultTagsRead(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*AWSClient).DefaultTagsConfig + defaultTagsConfig := meta.(*AWSClient).DefaultTagsConfig ignoreTagsConfig := meta.(*AWSClient).IgnoreTagsConfig - if err := d.Set("tags", conn.Tags.IgnoreAws().IgnoreConfig(ignoreTagsConfig).Map()); err != nil { + + d.SetId(meta.(*AWSClient).partition) + + if defaultTagsConfig == nil || defaultTagsConfig.Tags == nil { + return nil + } + + if err := d.Set("tags", defaultTagsConfig.Tags.IgnoreAws().IgnoreConfig(ignoreTagsConfig).Map()); err != nil { return err } - d.SetId(meta.(*AWSClient).partition) return nil } From a7f8304c13305e699c00b27011212a705aa89d9a Mon Sep 17 00:00:00 2001 From: Dirk Avery Date: Fri, 21 May 2021 13:27:22 -0400 Subject: [PATCH 09/12] tests/ds/default_tags: Test a bit more --- aws/data_source_aws_default_tags_test.go | 50 ++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/aws/data_source_aws_default_tags_test.go b/aws/data_source_aws_default_tags_test.go index 3e6a96fb156..7f14c7a4e7a 100644 --- a/aws/data_source_aws_default_tags_test.go +++ b/aws/data_source_aws_default_tags_test.go @@ -33,6 +33,56 @@ func TestAccAWSDefaultTagsDataSource_basic(t *testing.T) { }) } +func TestAccAWSDefaultTagsDataSource_empty(t *testing.T) { + var providers []*schema.Provider + + dataSourceName := "data.aws_default_tags.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ErrorCheck: testAccErrorCheck(t, ec2.EndpointsID), + ProviderFactories: testAccProviderFactoriesInternal(&providers), + CheckDestroy: nil, + Steps: []resource.TestStep{ + { + Config: composeConfig( + testAccAWSProviderConfigDefaultTags_Tags0(), + testAccAWSDefaultTagsDataSource(), + ), + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr(dataSourceName, "tags.%", "0"), + ), + }, + }, + }) +} + +func TestAccAWSDefaultTagsDataSource_multiple(t *testing.T) { + var providers []*schema.Provider + + dataSourceName := "data.aws_default_tags.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ErrorCheck: testAccErrorCheck(t, ec2.EndpointsID), + ProviderFactories: testAccProviderFactoriesInternal(&providers), + CheckDestroy: nil, + Steps: []resource.TestStep{ + { + Config: composeConfig( + testAccAWSProviderConfigDefaultTags_Tags2("nuera", "hijo", "escalofrios", "calambres"), + testAccAWSDefaultTagsDataSource(), + ), + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr(dataSourceName, "tags.%", "2"), + resource.TestCheckResourceAttr(dataSourceName, "tags.nuera", "hijo"), + resource.TestCheckResourceAttr(dataSourceName, "tags.escalofrios", "calambres"), + ), + }, + }, + }) +} + func testAccAWSDefaultTagsDataSource() string { return `data "aws_default_tags" "test" {}` } From 53f65ffb6d4ea1c1434c8799a5468247baf74732 Mon Sep 17 00:00:00 2001 From: Dirk Avery Date: Fri, 21 May 2021 16:36:39 -0400 Subject: [PATCH 10/12] ds/default_tags: Refine empty logic --- aws/data_source_aws_default_tags.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/aws/data_source_aws_default_tags.go b/aws/data_source_aws_default_tags.go index 7f8cbf81087..f4f96f0e8cd 100644 --- a/aws/data_source_aws_default_tags.go +++ b/aws/data_source_aws_default_tags.go @@ -18,12 +18,12 @@ func dataSourceAwsDefaultTagsRead(d *schema.ResourceData, meta interface{}) erro d.SetId(meta.(*AWSClient).partition) - if defaultTagsConfig == nil || defaultTagsConfig.Tags == nil { - return nil - } - - if err := d.Set("tags", defaultTagsConfig.Tags.IgnoreAws().IgnoreConfig(ignoreTagsConfig).Map()); err != nil { - return err + if defaultTagsConfig != nil && defaultTagsConfig.Tags != nil { + if err := d.Set("tags", defaultTagsConfig.Tags.IgnoreAws().IgnoreConfig(ignoreTagsConfig).Map()); err != nil { + return err + } + } else { + d.Set("tags", nil) } return nil From 390dcadd951bc37488cbd05b6a189208697cd80e Mon Sep 17 00:00:00 2001 From: Dirk Avery Date: Fri, 21 May 2021 17:02:33 -0400 Subject: [PATCH 11/12] ds/default_tags: Clean up logic, add test --- aws/data_source_aws_default_tags.go | 20 +++++++++----- aws/data_source_aws_default_tags_test.go | 34 ++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 7 deletions(-) diff --git a/aws/data_source_aws_default_tags.go b/aws/data_source_aws_default_tags.go index f4f96f0e8cd..2b2f9e323c6 100644 --- a/aws/data_source_aws_default_tags.go +++ b/aws/data_source_aws_default_tags.go @@ -1,6 +1,10 @@ package aws -import "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" +import ( + "fmt" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" +) func dataSourceAwsDefaultTags() *schema.Resource { return &schema.Resource{ @@ -18,12 +22,14 @@ func dataSourceAwsDefaultTagsRead(d *schema.ResourceData, meta interface{}) erro d.SetId(meta.(*AWSClient).partition) - if defaultTagsConfig != nil && defaultTagsConfig.Tags != nil { - if err := d.Set("tags", defaultTagsConfig.Tags.IgnoreAws().IgnoreConfig(ignoreTagsConfig).Map()); err != nil { - return err - } - } else { - d.Set("tags", nil) + tags := defaultTagsConfig.GetTags() + + if len(tags) > 0 { + tags = tags.IgnoreAws().IgnoreConfig(ignoreTagsConfig) + } + + if err := d.Set("tags", tags.Map()); err != nil { + return fmt.Errorf("error setting tags: %w", err) } return nil diff --git a/aws/data_source_aws_default_tags_test.go b/aws/data_source_aws_default_tags_test.go index 7f14c7a4e7a..f7d1a0625b3 100644 --- a/aws/data_source_aws_default_tags_test.go +++ b/aws/data_source_aws_default_tags_test.go @@ -83,6 +83,40 @@ func TestAccAWSDefaultTagsDataSource_multiple(t *testing.T) { }) } +func TestAccAWSDefaultTagsDataSource_ignore(t *testing.T) { + var providers []*schema.Provider + + dataSourceName := "data.aws_default_tags.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ErrorCheck: testAccErrorCheck(t, ec2.EndpointsID), + ProviderFactories: testAccProviderFactoriesInternal(&providers), + CheckDestroy: nil, + Steps: []resource.TestStep{ + { + Config: composeConfig( + testAccAWSProviderConfigDefaultTags_Tags1("Tabac", "Louis Chiron"), + testAccAWSDefaultTagsDataSource(), + ), + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr(dataSourceName, "tags.%", "1"), + resource.TestCheckResourceAttr(dataSourceName, "tags.Tabac", "Louis Chiron"), + ), + }, + { + Config: composeConfig( + testAccProviderConfigDefaultAndIgnoreTagsKeys1("Tabac", "Louis Chiron"), + testAccAWSDefaultTagsDataSource(), + ), + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr(dataSourceName, "tags.%", "0"), + ), + }, + }, + }) +} + func testAccAWSDefaultTagsDataSource() string { return `data "aws_default_tags" "test" {}` } From 0051a610b230cfa85ea1a6cd983ee640a2578527 Mon Sep 17 00:00:00 2001 From: Dirk Avery Date: Fri, 21 May 2021 17:12:38 -0400 Subject: [PATCH 12/12] ds/default_tags: Placate semgrep --- aws/data_source_aws_default_tags.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/aws/data_source_aws_default_tags.go b/aws/data_source_aws_default_tags.go index 2b2f9e323c6..750359f41ed 100644 --- a/aws/data_source_aws_default_tags.go +++ b/aws/data_source_aws_default_tags.go @@ -24,12 +24,12 @@ func dataSourceAwsDefaultTagsRead(d *schema.ResourceData, meta interface{}) erro tags := defaultTagsConfig.GetTags() - if len(tags) > 0 { - tags = tags.IgnoreAws().IgnoreConfig(ignoreTagsConfig) - } - - if err := d.Set("tags", tags.Map()); err != nil { - return fmt.Errorf("error setting tags: %w", err) + if tags != nil { + if err := d.Set("tags", tags.IgnoreAws().IgnoreConfig(ignoreTagsConfig).Map()); err != nil { + return fmt.Errorf("error setting tags: %w", err) + } + } else { + d.Set("tags", nil) } return nil