Module cannot apply unless VPC has a "Name" tag
sheax0r opened this issue · 1 comments
sheax0r commented
Problem Description
If the input vpc_id
variable refers to a VPC that does not have a Name
tag, terraform plan
and terraform apply
fail like this:
Error: Error refreshing state: 3 error(s) occurred:
* module.redis.aws_elasticache_parameter_group.redis_parameter_group: 1 error(s) occurred:
* module.redis.aws_elasticache_parameter_group.redis_parameter_group: At column 98, line 1: map "data.aws_vpc.vpc.tags" does not have any elements so cannot determine type. in:
${replace(format("%.255s", lower(replace("tf-redis-${var.name}-${var.env}-${data.aws_vpc.vpc.tags["Name"]}", "_", "-"))), "/\\s/", "-")}
* module.redis.aws_elasticache_subnet_group.redis_subnet_group: 1 error(s) occurred:
* module.redis.aws_elasticache_subnet_group.redis_subnet_group: At column 98, line 1: map "data.aws_vpc.vpc.tags" does not have any elements so cannot determine type. in:
${replace(format("%.255s", lower(replace("tf-redis-${var.name}-${var.env}-${data.aws_vpc.vpc.tags["Name"]}", "_", "-"))), "/\\s/", "-")}
* module.redis.aws_security_group.redis_security_group: 1 error(s) occurred:
* module.redis.aws_security_group.redis_security_group: At column 56, line 1: map "data.aws_vpc.vpc.tags" does not have any elements so cannot determine type. in:
tf-sg-ec-${var.name}-${var.env}-${data.aws_vpc.vpc.tags["Name"]}
Proposed Solution
Add a local variable, local.vpc_name
, and set the value of it using coalesce so that it uses the Name
tag of the VPC if it exists, or a hardcoded string like redis-vpc
otherwise.
antonbabenko commented
#21 Is related to this as well.