在 AWS 中使用 Terraform (TF),在尝试使用 terraform_remote_state 调用 vpc_id 时遇到错误。我们分割了网络的不同部分,以减轻状态滑移。然而,它还需要与基础设施每个单独部分的状态文件(即 vpc、sgs、角色等的状态文件)进行交互。当我尝试从 S3 存储桶中保存的状态文件中获取 vpc_id 时,出现以下错误:
on main.tf line 78, in module "vpc_sg":
78: vpc_id = data.terraform_remote_state.vpc.vpc_id
This object has no argument, nested block, or exported attribute named
"vpc_id".
Run Code Online (Sandbox Code Playgroud)
这是我在 main.tf 文件中的 terraform_remote_state 调用:
backend = "s3"
workspace = var.workspace
config = {
bucket = "terraform-east"
key = "terraform-vpc.tfstate"
region ="us-east-1"
}
}
Run Code Online (Sandbox Code Playgroud)
这是同一个 main.tf 中的调用
// output "sg_id"
source = "git::https://url_to_sg.git/reference?
vpc_cidr = data.terraform_remote_state.vpc.vpc_cidr -- This line also doesn't work.. but …
Run Code Online (Sandbox Code Playgroud) amazon-s3 amazon-web-services terraform terraform-remote-state