We have 2 terraform configurations: one is for the infra where we define such resources like VPC, subnets, security groups, ... another one for the application, which will consume output from the infrastate.
Here's output from infra state, place at my-terraform-states/infra on S3
ubuntu@ip-172-31-29-175:/vagrant/provision/terraform/configurations/infra$ terraform output
db_subnet_group_name = my-db-subnet
domain_name =
hosted_zone_id = Z3R9O56WXH4E9G
hosted_zone_name = int.my-cloud.com.
logs_bucket = my-logs-int-ap-southeast-1
main_availability_zone = ap-southeast-1a
main_subnet_id = subnet-04c29a60
private_hosted_zone_id = Z2QHMZ01S47GN0
private_hosted_zone_name = my-cloud.internal.
sg_now_default_id = sg-ceadd8a9
sg_now_ldap_id = sg-87eabbe0
sg_now_loadbalancer_id = sg-a1771ec6
sg_now_log_centralized_id = sg-f6537c90
sg_now_platform_id = sg-c94821ae
sg_now_public_id = sg-35482152
subnet_cidr_blocks = [
172.31.0.0/20,
172.31.16.0/20,
172.31.32.0/20
]
subnet_ids = [
subnet-04c29a60,
subnet-d05915a6,
subnet-5fa4f319
]
vpc_cidr_block = 172.31.0.0/16
vpc_id = vpc-32c75856
In the TF configuration for application
data "aws_security_group" "main_loadbalancer" {
filter {
name = "group-name"
values = ["MAIN-LOADBALANCER"]
}
vpc_id = "${data.terraform_remote_state.infra.vpc_id}"
}
data "terraform_remote_state" "infra" {
backend = "s3"
config {
bucket = "my-terraform-states"
key = "infra"
region = "${var.aws_region}"
}
}
...
but when we run terraform apply for the application tf
data.terraform_remote_state.infra: Refreshing state...
Error running plan: 2 error(s) occurred:
* data.aws_security_group.main_loadbalancer: 1 error(s) occurred:
* data.aws_security_group.main_loadbalancer: Resource 'data.terraform_remote_state.infra' does not have attribute 'vpc_id' for variable 'data.terraform_remote_state.infra.vpc_id'
* aws_security_group.loadbalancer_sg: 1 error(s) occurred:
* aws_security_group.loadbalancer_sg: Resource 'data.terraform_remote_state.infra' does not have attribute 'vpc_id' for variable 'data.terraform_remote_state.infra.vpc_id'
Why data.terraform_remote_state.infra is refreshed but Terraform still cannot read the vpc_id from its output? I checked state of application TF and still see the vpc_id in terraform_remote_state.infra data
facade@ip-172-31-2-131:/var/provision/terraform-workspace/application$ terraform state show terraform_remote_state.infra
id = 2018-05-24 04:00:45.51332172 +0000 UTC
backend = s3
config.% = 3
config.bucket = my-terraform-states
config.key = infra
config.region = ap-southeast-1
environment = default
...
...
subnet_cidr_blocks.# = 3
subnet_cidr_blocks.0 = 172.31.0.0/20
subnet_cidr_blocks.1 = 172.31.16.0/20
subnet_cidr_blocks.2 = 172.31.32.0/20
subnet_ids.# = 3
subnet_ids.0 = subnet-04c29a60
subnet_ids.1 = subnet-d05915a6
subnet_ids.2 = subnet-5fa4f319
vpc_cidr_block = 172.31.0.0/16
vpc_id = vpc-32c75856
Terraform v0.10.7
closed as it turned out due to missing variable when running terraform
@dohoangkhiem what missing variable?
@anub1s187 Probably the same thing that brought me on this page. When the key is specified incorrect, the terraform does not inform about missing file, instead shows this message.
Example:
I had:
key = "vpc"
I SHOULD have had:
key = "vpc/terraform.tfstate"
I'm going to lock this issue because it has been closed for _30 days_ โณ. This helps our maintainers find and focus on the active issues.
If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.
Most helpful comment
@dohoangkhiem what missing variable?