user6826691
user6826691

Reputation: 2011

Ignore certain tags from terraform locals

How can I ignore a certain tag defined in the locals variable? For example: I would want to ignore the email tag for this dynamodb table resource.

Local definition

locals {
  global_tags = {
    email = "xxx.com"
    owner = "xxx"
  }
  common_tags = {
    Name = "live"
  }
}

 lifecycle {
    ignore_changes = [
      read_capacity,
      write_capacity,
      local.global_tags.email
    ]
  }

  tags = merge(local.global_tags,local.common_tags,var.received_nexgen_events_tags)

}

Details:

Terraform v0.12.0
+ provider.aws v2.30.0

I tried this but got an error

Error: Unsupported attribute

on ../../../../tf_module_dynamodb/events.tf line 22, in resource "aws_dynamodb_table" "events": 22: local.global_tags.email

This object has no argument, nested block, or exported attribute named "local".

2: I also tried like this, got static variable reference is required , what is static variable reference?

 lifecycle {
    ignore_changes = [
      read_capacity,
      write_capacity,
      local.global_tags["xxx.com"]
    ]
  }


error :
 22:       local.global_tags["xxx.com"]

A static variable reference is required.

Upvotes: 3

Views: 5943

Answers (1)

user6826691
user6826691

Reputation: 2011

Well, there is a bug in terraform > 0.12 version

The terraform plan and terraform apply will say that its going to add tag.email, however it will ignore the tag.email when terraform apply command has run.

I tested using terraform state rm --target=resource-name and did an import and then did terraform state show resource-name, the tag.email was not imported(was ignored) !

More details: https://github.com/hashicorp/terraform-plugin-sdk/issues/167

  lifecycle {
    ignore_changes = [
      read_capacity,
      write_capacity,
      tags.email  
    ]
  }

Upvotes: 4

Related Questions