Terraform: aws default_tag not supported in root_block_device?

I am trying to use the default_tag available for the aws terraform provider.

Documentation:

From the doc, it says:

This functionality is supported in all resources that implement tags, with the exception of the aws_autoscaling_group resource.

So, for all resources I have it works very well, except for aws_instance.root_block_device.

For example, I have:

provider "aws" {
  [...]
  default_tags {
    tags = {
      Env = prod
    }
  }
}

resource "aws_instance" "instance" {
  ami           = xxx
  instance_type = xxx
  
  root_block_device {
    volume_size           = xxx
    volume_type           = xxx
  }
}

The default tag Env = prod is correctly added to the instance itself, but not for the root_device_blockblock.

So I’m wondering if default_tag is supported for this. It’s true that the documentation says supported in all **resources** but root_block_device is only an argument of this resource, so maybe this is the problem?

I’m just looking for a kind of confirmation because the documentation is not very clear on this point.

Thank you

>Solution :

This is not supported yet. There are two issues are still open 1
2

but you can use this workaround solution

data "aws_default_tags" "example" {}
aws_instance {
  volume_tags = merge(aws_default_tags.example.default_tags, var.extra_tags)
}

Leave a Reply