terratag icon indicating copy to clipboard operation
terratag copied to clipboard

Terratag does't apply tags to aws resources in nested blocks

Open indu-sharma1 opened this issue 2 years ago • 3 comments

Problem Statement: we've a resource "aws_instance" and corresponding tags in a terraform file already and a nested resources root_block_device with tags. When we apply terratag with extra_tags , it doesn't merge/apply to nested resource root_block_device.

Probably Solution:

Please implement an option in terratag cli to apply recursively so user has option to apply terratags in nested resources.

indu-sharma1 avatar May 06 '22 17:05 indu-sharma1

@indu-sharma1 can you please share an example?

yaronya avatar May 12 '22 21:05 yaronya

@yaronya Here you go. TAGS doesn't apply to "root_block_device" block.

resource "aws_instance" "controllers" {
  count         = ( var.is_runtime ? ( var.is_ha ? 3 : 1) : 0)
  ami           = data.aws_ami.ec2_centos7_ami.image_id
  instance_type = var.ctr_instance_type
  key_name      = aws_key_pair.main.key_name
  vpc_security_group_ids = flatten([
    aws_default_security_group.main.id,
    aws_security_group.main.id
  ])
  subnet_id = aws_subnet.main.id
  user_data = data.template_file.cloud_data.rendered

  root_block_device {
    volume_type = "gp2"
    volume_size = 400
    delete_on_termination = true
    tags = {
      Name            = "${var.project_id}-controller-${count.index + 1}-root-ebs"
      Project         = var.project_id
      user            = var.user
      deployment_uuid = random_uuid.deployment_uuid.result
    }
  }

  tags = {
    Name            = "${var.project_id}-controller-${count.index + 1}"
    Project         = var.project_id
    user            = var.user
    deployment_uuid = random_uuid.deployment_uuid.result
  }
}

indu-sharma1 avatar May 13 '22 02:05 indu-sharma1

Hi @indu-sharma1 So the expected behavior is for the root EBS volume to have both tags attributes? or just the one under root_block_device nested block?

yaronya avatar Jul 10 '22 17:07 yaronya

Closing due to inactivity

yaronya avatar Oct 13 '22 05:10 yaronya