diff --git a/aws/resource_aws_backup_plan.go b/aws/resource_aws_backup_plan.go index f333e0f8a1c..7d19d21b9db 100644 --- a/aws/resource_aws_backup_plan.go +++ b/aws/resource_aws_backup_plan.go @@ -154,11 +154,15 @@ func resourceAwsBackupPlan() *schema.Resource { }, "tags": tagsSchema(), }, + + CustomizeDiff: SetTagsDiff, } } func resourceAwsBackupPlanCreate(d *schema.ResourceData, meta interface{}) error { conn := meta.(*AWSClient).backupconn + defaultTagsConfig := meta.(*AWSClient).DefaultTagsConfig + tags := defaultTagsConfig.MergeTags(keyvaluetags.New(d.Get("tags").(map[string]interface{}))) input := &backup.CreateBackupPlanInput{ BackupPlan: &backup.PlanInput{ @@ -166,7 +170,7 @@ func resourceAwsBackupPlanCreate(d *schema.ResourceData, meta interface{}) error Rules: expandBackupPlanRules(d.Get("rule").(*schema.Set)), AdvancedBackupSettings: expandBackupPlanAdvancedBackupSettings(d.Get("advanced_backup_setting").(*schema.Set)), }, - BackupPlanTags: keyvaluetags.New(d.Get("tags").(map[string]interface{})).IgnoreAws().BackupTags(), + BackupPlanTags: tags.IgnoreAws().BackupTags(), } log.Printf("[DEBUG] Creating Backup Plan: %#v", input) @@ -182,6 +186,7 @@ func resourceAwsBackupPlanCreate(d *schema.ResourceData, meta interface{}) error func resourceAwsBackupPlanRead(d *schema.ResourceData, meta interface{}) error { conn := meta.(*AWSClient).backupconn + defaultTagsConfig := meta.(*AWSClient).DefaultTagsConfig ignoreTagsConfig := meta.(*AWSClient).IgnoreTagsConfig resp, err := conn.GetBackupPlan(&backup.GetBackupPlanInput{ @@ -214,10 +219,17 @@ func resourceAwsBackupPlanRead(d *schema.ResourceData, meta interface{}) error { if err != nil { return fmt.Errorf("error listing tags for Backup Plan (%s): %w", d.Id(), err) } - if err := d.Set("tags", tags.IgnoreAws().IgnoreConfig(ignoreTagsConfig).Map()); err != nil { + tags = tags.IgnoreAws().IgnoreConfig(ignoreTagsConfig) + + //lintignore:AWSR002 + if err := d.Set("tags", tags.RemoveDefaultConfig(defaultTagsConfig).Map()); err != nil { return fmt.Errorf("error setting tags: %w", err) } + if err := d.Set("tags_all", tags.Map()); err != nil { + return fmt.Errorf("error setting tags_all: %w", err) + } + return nil } @@ -241,8 +253,8 @@ func resourceAwsBackupPlanUpdate(d *schema.ResourceData, meta interface{}) error } } - if d.HasChange("tags") { - o, n := d.GetChange("tags") + if d.HasChange("tags_all") { + o, n := d.GetChange("tags_all") if err := keyvaluetags.BackupUpdateTags(conn, d.Get("arn").(string), o, n); err != nil { return fmt.Errorf("error updating tags for Backup Plan (%s): %w", d.Id(), err) } diff --git a/aws/resource_aws_backup_vault.go b/aws/resource_aws_backup_vault.go index 1f4a4fa31f2..381ff2df3ee 100644 --- a/aws/resource_aws_backup_vault.go +++ b/aws/resource_aws_backup_vault.go @@ -29,7 +29,8 @@ func resourceAwsBackupVault() *schema.Resource { ForceNew: true, ValidateFunc: validation.StringMatch(regexp.MustCompile(`^[a-zA-Z0-9\-\_\.]{1,50}$`), "must consist of lowercase letters, numbers, and hyphens."), }, - "tags": tagsSchema(), + "tags": tagsSchema(), + "tags_all": tagsSchemaComputed(), "kms_key_arn": { Type: schema.TypeString, Optional: true, @@ -46,15 +47,19 @@ func resourceAwsBackupVault() *schema.Resource { Computed: true, }, }, + + CustomizeDiff: SetTagsDiff, } } func resourceAwsBackupVaultCreate(d *schema.ResourceData, meta interface{}) error { conn := meta.(*AWSClient).backupconn + defaultTagsConfig := meta.(*AWSClient).DefaultTagsConfig + tags := defaultTagsConfig.MergeTags(keyvaluetags.New(d.Get("tags").(map[string]interface{}))) input := &backup.CreateBackupVaultInput{ BackupVaultName: aws.String(d.Get("name").(string)), - BackupVaultTags: keyvaluetags.New(d.Get("tags").(map[string]interface{})).IgnoreAws().BackupTags(), + BackupVaultTags: tags.IgnoreAws().BackupTags(), } if v, ok := d.GetOk("kms_key_arn"); ok { @@ -73,6 +78,7 @@ func resourceAwsBackupVaultCreate(d *schema.ResourceData, meta interface{}) erro func resourceAwsBackupVaultRead(d *schema.ResourceData, meta interface{}) error { conn := meta.(*AWSClient).backupconn + defaultTagsConfig := meta.(*AWSClient).DefaultTagsConfig ignoreTagsConfig := meta.(*AWSClient).IgnoreTagsConfig input := &backup.DescribeBackupVaultInput{ @@ -103,8 +109,15 @@ func resourceAwsBackupVaultRead(d *schema.ResourceData, meta interface{}) error if err != nil { return fmt.Errorf("error listing tags for Backup Vault (%s): %s", d.Id(), err) } - if err := d.Set("tags", tags.IgnoreAws().IgnoreConfig(ignoreTagsConfig).Map()); err != nil { - return fmt.Errorf("error setting tags: %s", err) + tags = tags.IgnoreAws().IgnoreConfig(ignoreTagsConfig) + + //lintignore:AWSR002 + if err := d.Set("tags", tags.RemoveDefaultConfig(defaultTagsConfig).Map()); err != nil { + return fmt.Errorf("error setting tags: %w", err) + } + + if err := d.Set("tags_all", tags.Map()); err != nil { + return fmt.Errorf("error setting tags_all: %w", err) } return nil @@ -113,8 +126,8 @@ func resourceAwsBackupVaultRead(d *schema.ResourceData, meta interface{}) error func resourceAwsBackupVaultUpdate(d *schema.ResourceData, meta interface{}) error { conn := meta.(*AWSClient).backupconn - if d.HasChange("tags") { - o, n := d.GetChange("tags") + if d.HasChange("tags_all") { + o, n := d.GetChange("tags_all") if err := keyvaluetags.BackupUpdateTags(conn, d.Get("arn").(string), o, n); err != nil { return fmt.Errorf("error updating tags for Backup Vault (%s): %s", d.Id(), err) } diff --git a/aws/resource_aws_batch_compute_environment.go b/aws/resource_aws_batch_compute_environment.go index 74945d95a12..31214767fcc 100644 --- a/aws/resource_aws_batch_compute_environment.go +++ b/aws/resource_aws_batch_compute_environment.go @@ -164,7 +164,8 @@ func resourceAwsBatchComputeEnvironment() *schema.Resource { ValidateFunc: validation.StringInSlice([]string{batch.CEStateEnabled, batch.CEStateDisabled}, true), Default: batch.CEStateEnabled, }, - "tags": tagsSchema(), + "tags": tagsSchema(), + "tags_all": tagsSchemaComputed(), "type": { Type: schema.TypeString, Required: true, @@ -188,11 +189,15 @@ func resourceAwsBatchComputeEnvironment() *schema.Resource { Computed: true, }, }, + + CustomizeDiff: SetTagsDiff, } } func resourceAwsBatchComputeEnvironmentCreate(d *schema.ResourceData, meta interface{}) error { conn := meta.(*AWSClient).batchconn + defaultTagsConfig := meta.(*AWSClient).DefaultTagsConfig + tags := defaultTagsConfig.MergeTags(keyvaluetags.New(d.Get("tags").(map[string]interface{}))) // Build the compute environment name. var computeEnvironmentName string @@ -218,8 +223,8 @@ func resourceAwsBatchComputeEnvironmentCreate(d *schema.ResourceData, meta inter input.State = aws.String(v.(string)) } - if v := d.Get("tags").(map[string]interface{}); len(v) > 0 { - input.Tags = keyvaluetags.New(v).IgnoreAws().BatchTags() + if len(tags) > 0 { + input.Tags = tags.IgnoreAws().BatchTags() } if computeEnvironmentType == batch.CETypeManaged { @@ -320,6 +325,7 @@ func resourceAwsBatchComputeEnvironmentCreate(d *schema.ResourceData, meta inter func resourceAwsBatchComputeEnvironmentRead(d *schema.ResourceData, meta interface{}) error { conn := meta.(*AWSClient).batchconn + defaultTagsConfig := meta.(*AWSClient).DefaultTagsConfig ignoreTagsConfig := meta.(*AWSClient).IgnoreTagsConfig computeEnvironmentName := d.Get("compute_environment_name").(string) @@ -349,8 +355,15 @@ func resourceAwsBatchComputeEnvironmentRead(d *schema.ResourceData, meta interfa d.Set("service_role", computeEnvironment.ServiceRole) d.Set("state", computeEnvironment.State) - if err := d.Set("tags", keyvaluetags.BatchKeyValueTags(computeEnvironment.Tags).IgnoreAws().IgnoreConfig(ignoreTagsConfig).Map()); err != nil { - return fmt.Errorf("error setting tags: %s", err) + tags := keyvaluetags.BatchKeyValueTags(computeEnvironment.Tags).IgnoreAws().IgnoreConfig(ignoreTagsConfig) + + //lintignore:AWSR002 + if err := d.Set("tags", tags.RemoveDefaultConfig(defaultTagsConfig).Map()); err != nil { + return fmt.Errorf("error setting tags: %w", err) + } + + if err := d.Set("tags_all", tags.Map()); err != nil { + return fmt.Errorf("error setting tags_all: %w", err) } d.Set("type", computeEnvironment.Type) @@ -471,8 +484,8 @@ func resourceAwsBatchComputeEnvironmentUpdate(d *schema.ResourceData, meta inter } } - if d.HasChange("tags") { - o, n := d.GetChange("tags") + if d.HasChange("tags_all") { + o, n := d.GetChange("tags_all") if err := keyvaluetags.BatchUpdateTags(conn, d.Get("arn").(string), o, n); err != nil { return fmt.Errorf("error updating tags: %s", err) diff --git a/aws/resource_aws_batch_job_definition.go b/aws/resource_aws_batch_job_definition.go index 41339477bb9..8f583ad83de 100644 --- a/aws/resource_aws_batch_job_definition.go +++ b/aws/resource_aws_batch_job_definition.go @@ -129,7 +129,8 @@ func resourceAwsBatchJobDefinition() *schema.Resource { }, }, }, - "tags": tagsSchema(), + "tags": tagsSchema(), + "tags_all": tagsSchemaComputed(), "propagate_tags": { Type: schema.TypeBool, Optional: true, @@ -167,11 +168,15 @@ func resourceAwsBatchJobDefinition() *schema.Resource { Computed: true, }, }, + + CustomizeDiff: SetTagsDiff, } } func resourceAwsBatchJobDefinitionCreate(d *schema.ResourceData, meta interface{}) error { conn := meta.(*AWSClient).batchconn + defaultTagsConfig := meta.(*AWSClient).DefaultTagsConfig + tags := defaultTagsConfig.MergeTags(keyvaluetags.New(d.Get("tags").(map[string]interface{}))) name := d.Get("name").(string) input := &batch.RegisterJobDefinitionInput{ @@ -201,8 +206,8 @@ func resourceAwsBatchJobDefinitionCreate(d *schema.ResourceData, meta interface{ input.RetryStrategy = expandBatchRetryStrategy(v.([]interface{})[0].(map[string]interface{})) } - if v := d.Get("tags").(map[string]interface{}); len(v) > 0 { - input.Tags = keyvaluetags.New(v).IgnoreAws().BatchTags() + if len(tags) > 0 { + input.Tags = tags.IgnoreAws().BatchTags() } if v, ok := d.GetOk("timeout"); ok { @@ -222,6 +227,7 @@ func resourceAwsBatchJobDefinitionCreate(d *schema.ResourceData, meta interface{ func resourceAwsBatchJobDefinitionRead(d *schema.ResourceData, meta interface{}) error { conn := meta.(*AWSClient).batchconn + defaultTagsConfig := meta.(*AWSClient).DefaultTagsConfig ignoreTagsConfig := meta.(*AWSClient).IgnoreTagsConfig jobDefinition, err := finder.JobDefinitionByARN(conn, d.Id()) @@ -261,10 +267,17 @@ func resourceAwsBatchJobDefinitionRead(d *schema.ResourceData, meta interface{}) d.Set("retry_strategy", nil) } - if err := d.Set("tags", keyvaluetags.BatchKeyValueTags(jobDefinition.Tags).IgnoreAws().IgnoreConfig(ignoreTagsConfig).Map()); err != nil { + tags := keyvaluetags.BatchKeyValueTags(jobDefinition.Tags).IgnoreAws().IgnoreConfig(ignoreTagsConfig) + + //lintignore:AWSR002 + if err := d.Set("tags", tags.RemoveDefaultConfig(defaultTagsConfig).Map()); err != nil { return fmt.Errorf("error setting tags: %w", err) } + if err := d.Set("tags_all", tags.Map()); err != nil { + return fmt.Errorf("error setting tags_all: %w", err) + } + if err := d.Set("timeout", flattenBatchJobTimeout(jobDefinition.Timeout)); err != nil { return fmt.Errorf("error setting timeout: %w", err) } @@ -278,8 +291,8 @@ func resourceAwsBatchJobDefinitionRead(d *schema.ResourceData, meta interface{}) func resourceAwsBatchJobDefinitionUpdate(d *schema.ResourceData, meta interface{}) error { conn := meta.(*AWSClient).batchconn - if d.HasChange("tags") { - o, n := d.GetChange("tags") + if d.HasChange("tags_all") { + o, n := d.GetChange("tags_all") if err := keyvaluetags.BatchUpdateTags(conn, d.Id(), o, n); err != nil { return fmt.Errorf("error updating tags: %w", err) diff --git a/aws/resource_aws_batch_job_queue.go b/aws/resource_aws_batch_job_queue.go index 924c74404bc..59b7a4a5ea1 100644 --- a/aws/resource_aws_batch_job_queue.go +++ b/aws/resource_aws_batch_job_queue.go @@ -49,17 +49,22 @@ func resourceAwsBatchJobQueue() *schema.Resource { Required: true, ValidateFunc: validation.StringInSlice([]string{batch.JQStateDisabled, batch.JQStateEnabled}, true), }, - "tags": tagsSchema(), + "tags": tagsSchema(), + "tags_all": tagsSchemaComputed(), "arn": { Type: schema.TypeString, Computed: true, }, }, + + CustomizeDiff: SetTagsDiff, } } func resourceAwsBatchJobQueueCreate(d *schema.ResourceData, meta interface{}) error { conn := meta.(*AWSClient).batchconn + defaultTagsConfig := meta.(*AWSClient).DefaultTagsConfig + tags := defaultTagsConfig.MergeTags(keyvaluetags.New(d.Get("tags").(map[string]interface{}))) input := batch.CreateJobQueueInput{ ComputeEnvironmentOrder: createComputeEnvironmentOrder(d.Get("compute_environments").([]interface{})), JobQueueName: aws.String(d.Get("name").(string)), @@ -67,8 +72,8 @@ func resourceAwsBatchJobQueueCreate(d *schema.ResourceData, meta interface{}) er State: aws.String(d.Get("state").(string)), } - if v := d.Get("tags").(map[string]interface{}); len(v) > 0 { - input.Tags = keyvaluetags.New(v).IgnoreAws().BatchTags() + if len(tags) > 0 { + input.Tags = tags.IgnoreAws().BatchTags() } name := d.Get("name").(string) @@ -100,6 +105,7 @@ func resourceAwsBatchJobQueueCreate(d *schema.ResourceData, meta interface{}) er func resourceAwsBatchJobQueueRead(d *schema.ResourceData, meta interface{}) error { conn := meta.(*AWSClient).batchconn + defaultTagsConfig := meta.(*AWSClient).DefaultTagsConfig ignoreTagsConfig := meta.(*AWSClient).IgnoreTagsConfig jq, err := getJobQueue(conn, d.Id()) @@ -132,8 +138,15 @@ func resourceAwsBatchJobQueueRead(d *schema.ResourceData, meta interface{}) erro d.Set("priority", jq.Priority) d.Set("state", jq.State) - if err := d.Set("tags", keyvaluetags.BatchKeyValueTags(jq.Tags).IgnoreAws().IgnoreConfig(ignoreTagsConfig).Map()); err != nil { - return fmt.Errorf("error setting tags: %s", err) + tags := keyvaluetags.BatchKeyValueTags(jq.Tags).IgnoreAws().IgnoreConfig(ignoreTagsConfig) + + //lintignore:AWSR002 + if err := d.Set("tags", tags.RemoveDefaultConfig(defaultTagsConfig).Map()); err != nil { + return fmt.Errorf("error setting tags: %w", err) + } + + if err := d.Set("tags_all", tags.Map()); err != nil { + return fmt.Errorf("error setting tags_all: %w", err) } return nil @@ -169,8 +182,8 @@ func resourceAwsBatchJobQueueUpdate(d *schema.ResourceData, meta interface{}) er } } - if d.HasChange("tags") { - o, n := d.GetChange("tags") + if d.HasChange("tags_all") { + o, n := d.GetChange("tags_all") if err := keyvaluetags.BatchUpdateTags(conn, d.Get("arn").(string), o, n); err != nil { return fmt.Errorf("error updating tags: %s", err) diff --git a/website/docs/r/backup_plan.html.markdown b/website/docs/r/backup_plan.html.markdown index 5bb7c3e652f..c8e28fcb4d0 100644 --- a/website/docs/r/backup_plan.html.markdown +++ b/website/docs/r/backup_plan.html.markdown @@ -38,7 +38,7 @@ The following arguments are supported: * `name` - (Required) The display name of a backup plan. * `rule` - (Required) A rule object that specifies a scheduled task that is used to back up a selection of resources. * `advanced_backup_setting` - (Optional) An object that specifies backup options for each resource type. -* `tags` - (Optional) Metadata that you can assign to help organize the plans you create. +* `tags` - (Optional) Metadata that you can assign to help organize the plans you create. If configured with a provider [`default_tags` configuration block](/docs/providers/aws/index.html#default_tags-configuration-block) present, tags with matching keys will overwrite those defined at the provider-level. ### Rule Arguments For **rule** the following attributes are supported: @@ -77,6 +77,7 @@ In addition to all arguments above, the following attributes are exported: * `id` - The id of the backup plan. * `arn` - The ARN of the backup plan. +* `tags_all` - A map of tags assigned to the resource, including those inherited from the provider [`default_tags` configuration block](/docs/providers/aws/index.html#default_tags-configuration-block). * `version` - Unique, randomly generated, Unicode, UTF-8 encoded string that serves as the version ID of the backup plan. ## Import diff --git a/website/docs/r/backup_vault.html.markdown b/website/docs/r/backup_vault.html.markdown index 17577e850eb..5b6a4f9e47e 100644 --- a/website/docs/r/backup_vault.html.markdown +++ b/website/docs/r/backup_vault.html.markdown @@ -24,7 +24,7 @@ resource "aws_backup_vault" "example" { The following arguments are supported: * `name` - (Required) Name of the backup vault to create. -* `tags` - (Optional) Metadata that you can assign to help organize the resources that you create. +* `tags` - (Optional) Metadata that you can assign to help organize the resources that you create. If configured with a provider [`default_tags` configuration block](/docs/providers/aws/index.html#default_tags-configuration-block) present, tags with matching keys will overwrite those defined at the provider-level. * `kms_key_arn` - (Optional) The server-side encryption key that is used to protect your backups. ## Attributes Reference @@ -34,6 +34,7 @@ In addition to all arguments above, the following attributes are exported: * `id` - The name of the vault. * `arn` - The ARN of the vault. * `recovery_points` - The number of recovery points that are stored in a backup vault. +* `tags_all` - A map of tags assigned to the resource, including those inherited from the provider [`default_tags` configuration block](/docs/providers/aws/index.html#default_tags-configuration-block). ## Import diff --git a/website/docs/r/batch_compute_environment.html.markdown b/website/docs/r/batch_compute_environment.html.markdown index 8e4b1639294..04d1c8512a1 100644 --- a/website/docs/r/batch_compute_environment.html.markdown +++ b/website/docs/r/batch_compute_environment.html.markdown @@ -129,7 +129,7 @@ resource "aws_batch_compute_environment" "sample" { * `compute_resources` - (Optional) Details of the compute resources managed by the compute environment. This parameter is required for managed compute environments. See details below. * `service_role` - (Required) The full Amazon Resource Name (ARN) of the IAM role that allows AWS Batch to make calls to other AWS services on your behalf. * `state` - (Optional) The state of the compute environment. If the state is `ENABLED`, then the compute environment accepts jobs from a queue and can scale out automatically based on queues. Valid items are `ENABLED` or `DISABLED`. Defaults to `ENABLED`. -* `tags` - (Optional) Key-value map of resource tags +* `tags` - (Optional) Key-value map of resource tags. If configured with a provider [`default_tags` configuration block](/docs/providers/aws/index.html#default_tags-configuration-block) present, tags with matching keys will overwrite those defined at the provider-level. * `type` - (Required) The type of the compute environment. Valid items are `MANAGED` or `UNMANAGED`. **compute_resources** is a child block with a single argument: @@ -166,6 +166,7 @@ In addition to all arguments above, the following attributes are exported: * `ecs_cluster_arn` - The Amazon Resource Name (ARN) of the underlying Amazon ECS cluster used by the compute environment. * `status` - The current status of the compute environment (for example, CREATING or VALID). * `status_reason` - A short, human-readable string to provide additional details about the current status of the compute environment. +* `tags_all` - A map of tags assigned to the resource, including those inherited from the provider [`default_tags` configuration block](/docs/providers/aws/index.html#default_tags-configuration-block). ## Import diff --git a/website/docs/r/batch_job_definition.html.markdown b/website/docs/r/batch_job_definition.html.markdown index 6c0adf9f451..1c07deda713 100644 --- a/website/docs/r/batch_job_definition.html.markdown +++ b/website/docs/r/batch_job_definition.html.markdown @@ -113,7 +113,7 @@ The following arguments are supported: * `propagate_tags` - (Optional) Specifies whether to propagate the tags from the job definition to the corresponding Amazon ECS task. Default is `false`. * `retry_strategy` - (Optional) Specifies the retry strategy to use for failed jobs that are submitted with this job definition. Maximum number of `retry_strategy` is `1`. Defined below. -* `tags` - (Optional) Key-value map of resource tags. +* `tags` - (Optional) Key-value map of resource tags. If configured with a provider [`default_tags` configuration block](/docs/providers/aws/index.html#default_tags-configuration-block) present, tags with matching keys will overwrite those defined at the provider-level. * `timeout` - (Optional) Specifies the timeout for jobs so that if a job runs longer, AWS Batch terminates the job. Maximum number of `timeout` is `1`. Defined below. * `type` - (Required) The type of job definition. Must be `container`. @@ -143,6 +143,7 @@ In addition to all arguments above, the following attributes are exported: * `arn` - The Amazon Resource Name of the job definition. * `revision` - The revision of the job definition. +* `tags_all` - A map of tags assigned to the resource, including those inherited from the provider [`default_tags` configuration block](/docs/providers/aws/index.html#default_tags-configuration-block). ## Import diff --git a/website/docs/r/batch_job_queue.html.markdown b/website/docs/r/batch_job_queue.html.markdown index 29e6406202f..2d8f4540f65 100644 --- a/website/docs/r/batch_job_queue.html.markdown +++ b/website/docs/r/batch_job_queue.html.markdown @@ -36,13 +36,14 @@ The following arguments are supported: * `priority` - (Required) The priority of the job queue. Job queues with a higher priority are evaluated first when associated with the same compute environment. * `state` - (Required) The state of the job queue. Must be one of: `ENABLED` or `DISABLED` -* `tags` - (Optional) Key-value map of resource tags +* `tags` - (Optional) Key-value map of resource tags. If configured with a provider [`default_tags` configuration block](/docs/providers/aws/index.html#default_tags-configuration-block) present, tags with matching keys will overwrite those defined at the provider-level. ## Attributes Reference In addition to all arguments above, the following attributes are exported: * `arn` - The Amazon Resource Name of the job queue. +* `tags_all` - A map of tags assigned to the resource, including those inherited from the provider [`default_tags` configuration block](/docs/providers/aws/index.html#default_tags-configuration-block). ## Import