Closed stahs closed 3 years ago
Good question.
As you say, this seems to be a problem with the listModuleVars
. In this case, var.tags["Name"]
, var.tags["Zone"]
, var.tags["Environment"]
, and var.tags["Service"]
are recognized as different variables, so EmitIssue
emits issues for each variable. However, it is right to think of this as a single variable.
listVarRefs
simply treat all parsed references as variables, but there may be a smarter way to determine it.
Hi and thank you for responding.
Writing all this up has helped me to understand I was overcomplicating things inside of the terraform module. I have verified that when I change my module to pass over the entire tags variable like so:
resource "aws_instance" "ss" {
ami = var.aws_amis[var.default_os]
associate_public_ip_address = var.public
disable_api_termination = var.disable_api_termination
iam_instance_profile = var.iam_instance_profile
instance_type = var.type
key_name = var.ssh_key_name
private_ip = var.private_ip
source_dest_check = var.source_dest_check
subnet_id = var.subnet
vpc_security_group_ids = split(",", var.security)
tags = var.tags
then tflint output is what I expect to see. I would like to be able to use the individual variables inside of the tags attribute, combined with try function, but this works OK for now.
Thanks for looking into this!
Hi! I have run into a problem I'm hoping you can help me solve. My situation is a little complex, so bear with me please :)
I have built a tflint plugin, which in an extension of the missing-tags rule. My custom "required-tags" rule allows me to specify allowed sets of tag values for certain tag keys, which fulfills a business need of ensuring that certain tags are populated and are correctly set.
For example, tag
Zone
must be set and the value must be in ["zone1", "zone2"].My Terraform code uses a custom module, which provides aws_server resources.
When I run tflint in a directory containing an instance of this aws_server module with a single non-compliant tag, tflint emits 4 issues instead of 1.
Example instance of the terraform module as it appears in my terraform reposiotry
tflint output shows 4 issues found instead of expected 1 issue
The number of emitted issues is equivalent to the number of variables evaluated in the tags attribute inside of the terraform module. I am getting 4 issues because my tags attribute contains 4 vars (Name, Zone, Environment, Service)
My environment
Version
required tags plugin main.go (built using SDK v0.8.1)
.tflint.hcl
terraform module
I have observed that if this module is edited to populate only 3 tags like so
then only 3 issues are emitted (instead of expected 1)
This appears to be related to the fact that EmitIssue emits one issue per output produced by listModuleVars.
Perhaps this is not a bug, but I am simply using the SDK incorrectly? Any help or tips will be very much appreciated! Thank you!!