Ignore Specific ASG Tag Using Terraform

159 Views Asked by At

I am creating ASG resources with terraform and adding tags using the latest syntax such as


    tag {
      key                 = "external-sync"
      value               = "false"
      propagate_at_launch = true
    }

    tag {
      key                 = "test"
      value               = "false"
      propagate_at_launch = true
    }

I need to be able to ignore any changes to the “external-sync” tag after its initial creation as another tool is interacting with that tag in AWS.

I can’t seem to get the syntax right in my ignore block.

I have tried tag["external-sync] but it throws a validation error.

“Block type “tag” is represented by a set of objects, and set elements do not have addressable keys. To find elements matching specific criteria, use a “for” expression with an “if” clause”

For loop syntax doesn’t work in an ignore_change = [] block

I can’t seem to find a way to make this work. Any pointers ,much appreciated.

I’m using the latest versions of terraform and the AWS provider.

1

There are 1 best solutions below

2
karim arous On

You need to add this "lifecycle" block and add "ignore_changes" block within the "lifecycle" block that will contain everything you want to ignore.

This is an example how to igonre this tag "external-sync" on a specific resource

resource "aws_autoscaling_group" "example" {
  availability_zones = ["us-east-1a"]
  desired_capacity   = 1
  max_size           = 1
  min_size           = 1
  .
  .
  .
  tag {
  key                 = "external-sync"
  value               = "false"   
  propagate_at_launch = true
  }

  lifecycle {
    ignore_changes = [
      tags["external-sync"]
    ]
  }
}