I’m using an in house module to build aws ec2 instances, but I’m running into a weird issue with the aws provider’s default_tags feature. I can’t figure out if there’s a bug or I’m doing it wrong.
TL;DR: It looks as if the module must contain its own provider + default_tags configuration. It isn’t inheriting the default_tags from the caller/parent afaict.
The caller/parent has its provider configured thusly, and seems to work fine on resources defined directly in this project:
provider "aws" {
region = "us-west-2"
default_tags {
tags = {
created-by: "terraform"
owned-by: "dept_42"
terraform-source: "https://some.vcs_url"
}
}
}
As an example of the behavior in question, this project calls out to a module requesting to build a standardized ec2 instance:
module "green_instances" {
source = "/path/to/module/source"
instance_count = var.instance_count
ami = {owner: module.base_config.aws_account_owner, id: "ami-123456789a0"}
# ...a few other parameters here
}
The module appears to need to have its own provider block with the default_tags defined, or it won’t set the tags properly even though they’re defined in the caller’s provider. If the module is not configured as described, Terraform will remove these tags, despite them being declared in the caller’s provider config.
Is this expected behavior? thanks!