v0.12.1
v2.16.0
我已经配置了Terraform工作区,因为现在我的工作区指向dev
,在这里我有一个用于VPC和子网的tfstate文件,另一个用于我的安全组的tfstate文件,但是当我尝试时将vpc_id
从我的vpc远程tfstate引用到我的安全组中,然后我得到以下错误消息
No stored state was found for the given workspace in the given backend.
我的s3存储桶如下所示
nonprod-us-east-1
|-- env
|-- dev
|-- vpc_subnet/tfstate
|-- security_group/tfstate
terraform {
backend "s3"{
# Configuration will be injected by environment variables.
}
}
provider "aws" {
region = "${var.region}"
}
data "terraform_remote_state" "vpc_subnet" {
backend = "s3"
config = {
bucket = "nonprod-us-east-1"
key = "vpc_subnet/tfstate"
region = "us-east-1"
}
}
vpc_id = "${data.terraform_remote_state.vpc_subnet.outputs.vpc_id}"
而且我已经验证我的vpc_subnet/tfstate
反对者有vpc_id
outputs": {
"private_subnet_cidr_blocks": {
"value": [
"10.0.3.0/24",
"10.0.4.0/24",
"10.0.5.0/24"
],
"type": [
"tuple",
[
"string",
"string",
"string"
]
]
},
"private_subnet_ids": {
"value": [
"subnet-042a16dd291e90add",
"subnet-02e8322d996968a3f",
"subnet-078f525c24015b364"
],
"type": [
"tuple",
[
"string",
"string",
"string"
]
]
},
"public_subnet_cidr_blocks": {
"value": [
"10.0.0.0/24",
"10.0.1.0/24",
"10.0.2.0/24"
],
"type": [
"tuple",
[
"string",
"string",
"string"
]
]
},
"public_subnet_ids": {
"value": [
"subnet-0ba92a28f6e8ddd95",
"subnet-08efcb80bed22f4e2",
"subnet-0b641797bfe207a0b"
],
"type": [
"tuple",
[
"string",
"string",
"string"
]
]
},
"vpc_id": {
"value": "vpc-0bb7595ff05fed581",
"type": "string"
}
}
它应该能够从远程tf状态位置读取vpc_id
。
无法从远程tf状态读取输出
答案 0 :(得分:0)
最后将其分类,这是存储桶密钥的一个问题,因为我使用的是Terraform工作区,所以tfstate文件创建在文件夹env:/dev/vpc_subnet/tfstate
下,更正了存储桶密钥之后,它可以解决tfstate文件。