terraform-linters / tflint-ruleset-aws

TFLint ruleset for terraform-provider-aws
Mozilla Public License 2.0
336 stars 72 forks source link

tflint-ruleset-aws - aws_route_not_specified_target #200

Closed pfilourenco closed 1 year ago

pfilourenco commented 2 years ago

Hi,

I have an egress_only_gateway_id and it says that I don't have: "Error: The routing target is not specified, each aws_route must contain either egress_only_gateway_id, gateway_id, instance_id, nat_gateway_id, network_interface_id, transit_gateway_id, vpc_peering_connection_id or vpc_endpoint_id. (aws_route_not_specified_target)"

code:

resource "aws_route" "public_egress_only_internet_gateway" {
  count = var.ipv6_enable && (length(var.public_subnets) > 0) && (var.egress_only_gateway != null) ? 1 : 0

  route_table_id              = aws_route_table.public[0].id
  destination_ipv6_cidr_block = "::/0"
  egress_only_gateway_id      = var.egress_only_gateway

  timeouts {
    create = "5m"
  }
}
wata727 commented 2 years ago

Isn't the value of var.egress_only_gateway null? In Terraform, if null is given, the attribute will be treated as unspecified: https://www.terraform.io/docs/language/expressions/types.html#null

pfilourenco commented 2 years ago

Isn't the value of var.egress_only_gateway null? In Terraform, if null is given, the attribute will be treated as unspecified: https://www.terraform.io/docs/language/expressions/types.html#null

Ok maybe that's it, I have the default value of null, as you can see I have a check if it's null to not create the resource.

wata727 commented 2 years ago

Unfortunately, this rule doesn't consider the count attribute, so even if count = 0, it's supposed to create a resource, and checks if the progress_only_gateway_id is set. This behavior seems to be a bug.

wata727 commented 1 year ago

This rule currently respects the count and for_each meta-arguments, so this bug should not occur. Closing.