hashicorp / terraform-provider-aws

The AWS Provider enables Terraform to manage AWS resources.
https://registry.terraform.io/providers/hashicorp/aws
Mozilla Public License 2.0
9.74k stars 9.1k forks source link

aws_dlm_lifecycle_policy multiple tags with the same key #8120

Open dmytroleonenko opened 5 years ago

dmytroleonenko commented 5 years ago
$ terraform -v
Terraform v0.11.11
+ provider.aws v1.54.0
+ provider.chef v0.1.0
+ provider.consul v2.2.0
+ provider.google v2.2.0
+ provider.google-beta v2.2.0
+ provider.template v2.1.0

Not the latest version but according to the code it hasn't changed

Affected Resource(s)

Terraform Configuration Files

resource "aws_dlm_lifecycle_policy" "example" {
  description        = "example DLM lifecycle policy"
  execution_role_arn = "${aws_iam_role.dlm_lifecycle_role.arn}"
  state              = "ENABLED"

  policy_details {
    resource_types = ["VOLUME"]

    schedule {
      name = "2 weeks of daily snapshots"

      create_rule {
        interval      = 24
        interval_unit = "HOURS"
        times         = ["23:45"]
      }

      retain_rule {
        count = 14
      }

      tags_to_add = {
        SnapshotCreator = "DLM"
      }

      copy_tags = false
    }

    target_tags = {
      Name = "MyName1"
      Name = "MyName2"
    }
  }
}

Expected Behavior

Terraform creates a policy with multiple tags that might legally contain the same key. https://docs.aws.amazon.com/dlm/latest/APIReference/API_PolicyDetails.html

Actual Behavior

schema.TypeMap is a dict with a unique tag Key. Multiple tags with the same key results in using only the last value of the repeated tag key.

Steps to Reproduce

  1. terraform apply

References

https://github.com/terraform-providers/terraform-provider-aws/blob/v2.1.0/aws/resource_aws_dlm_lifecycle_policy.go#L126

claydanford commented 5 years ago

Work around: Using a for_each to create a new policy per tag. Not pretty, but gets the job done. Not great for the Name tag, but if you have a standard backup tag, it works fine. I use it to hit UPPER, lower, and Camelcase tags.

resource "aws_dlm_lifecycle_policy" "example" {
  for_each = toset(var.target_tags)

  description        = "example DLM lifecycle policy - ${each.key}"
  execution_role_arn = aws_iam_role.dlm_lifecycle_role.arn
  state              = "ENABLED"

  policy_details {
    resource_types = ["VOLUME"]

    schedule {
      name = "2 weeks of daily snapshots"

      create_rule {
        interval      = 24
        interval_unit = "HOURS"
        times         = ["23:45"]
      }

      retain_rule {
        count = 14
      }

      tags_to_add = {
        SnapshotCreator = "DLM"
      }

      copy_tags = false
    }

    target_tags = {
      Backup = each.key
    }
  }
}

variable "target_tags" {
  default = ["TRUE", "true", "True"]
}
josephptata commented 4 years ago

This workaround only works for smaller use cases due to the limitation of 100 DLM policies per region. Is there any chance of this issue being fixed?

Arunkaliappan118 commented 3 years ago

I also face the same issue. Any help would be great!!

rhel commented 3 years ago

any news? blocked by the same issue.

Serhii-Sokolov-McK commented 3 years ago

Would be great to implement this functionality. Thanks

telmo-dazn commented 2 years ago

+1 getting the same issue

mgreene-gp commented 1 year ago

I am also encountering this issue - would it be possible to use a configuration block instead, like tag for aws_autoscaling_group?

clement94310 commented 1 year ago

same problem here

CoudPelle commented 12 months ago

Problem remains, no solution found except the workaround of @claydanford

MrHash commented 9 months ago

Old issue, needs resolving soon

tomoki-ono-vivion commented 4 months ago

same problem here

AutonomicMattRoy commented 2 months ago

Same problem here