gpt4 book ai didi

terraform - 资源没有变量的属性 - Terraform 远程状态

转载 作者:行者123 更新时间:2023-12-04 12:45:23 24 4
gpt4 key购买 nike

在我的一个项目中使用 Terraform 远程状态时遇到问题。状态文件在 S3 中是远程的。我是这样导入的:

data "terraform_remote_state" "management" {
backend = "s3"

config {
bucket = "testbucket"
key = "subfolder/terraform.tfstate"
region = "us-west-2"
}
}

我可以在上述状态文件的根级别看到输出:
            "outputs": {
"cidr": {
"sensitive": false,
"type": "string",
"value": "10.90.0.0/16"
},

我正在使用远程状态,如下所示:
module "dev-alpha-application" {
source = "../../modules/application"
envname = "test-app"
baseami = "ami-a042f4d8"
key_name = "pb-smarsh-test"
clui_baseami = "ami-xxxxxxxx"
adui_baseami = "ami-xxxxxxxx"
cidr = "10.80.0.0/16"
management_cidr = "${data.terraform_remote_state.management.cidr}"

vpn_gateway_id = "cgw-xxxxxxxx"

cidrs = "${list("${data.terraform_remote_state.management.cidr}", "${module.dev-alpha-application.cidr}")}"

除非我忽略了一些愚蠢的事情,否则这应该有效,但是当我运行 terraform apply 时,我收到以下错误:
* module.dev-alpha-application.var.management_cidr: Resource 'data.terraform_remote_state.management' does not have attribute 'cidr' for variable 'data.terraform_remote_state.management.cidr'

Terraform init 按预期工作。任何帮助将不胜感激。我试图包含尽可能多的信息
.

编辑 -
在 Debug模式下,它似乎正在打开远程状态文件 ok
-----------------------------------------------------
2018/04/10 09:05:10 [DEBUG] [aws-sdk-go] <?xml version="1.0" encoding="UTF-8"?>
<ListBucketResult xmlns="http://s3.amazonaws.com/doc/2006-03-01/"><Name>testbucket</Name><Prefix>env:/</Prefix><Marker></Marker><MaxKeys>1000</MaxKeys><IsTruncated>false</IsTruncated></ListBucketResult>
2018/04/10 09:05:10 [DEBUG] [aws-sdk-go] DEBUG: Request s3/GetObject Details:
---[ REQUEST POST-SIGN ]-----------------------------
GET /subfolder/terraform.tfstate HTTP/1.1
Host: testbucket.s3.us-west-2.amazonaws.com
User-Agent: aws-sdk-go/1.12.59 (go1.9.1; linux; amd64) APN/1.0 HashiCorp/1.0 Terraform/0.11.3
Authorization: AWS4-HMAC-SHA256 Credential=AKIAI6X7Y3APAUTZZQOQ/20180410/us-west-2/s3/aws4_request, SignedHeaders=host;x-amz-content-sha256;x-amz-date, Signature=716689e2124dd2a689b528c0cb51b07aeaf791cf577fa1a4fd17a79fb401b957
X-Amz-Content-Sha256: e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
X-Amz-Date: 20180410T080510Z
Accept-Encoding: gzip


-----------------------------------------------------
2018/04/10 09:05:11 [DEBUG] [aws-sdk-go] DEBUG: Response s3/GetObject Details:
---[ RESPONSE ]--------------------------------------
HTTP/1.1 200 OK
Connection: close
Content-Length: 386104
Accept-Ranges: bytes
Content-Type: application/json
Date: Tue, 10 Apr 2018 08:05:12 GMT
Etag: "1df4aaad48451707a79306a8f6a1c51c"
Last-Modified: Mon, 09 Apr 2018 14:53:03 GMT
Server: AmazonS3
X-Amz-Id-2: 92XqUEj319Uq5KhYFWvrLQ3O7VooOMMQ4GxY0keRKYY72Q5mpOgjeZ78w20AzjCSFLuZZycfEqU=
X-Amz-Request-Id: 448DB8C5E4B70A9A
X-Amz-Server-Side-Encryption: AES256
X-Amz-Version-Id: GjI6glV8oa9_.eOFSc5GFGVtTJBnrEmL

但我也在调试日志中看到了这一点:
2018/04/10 09:02:17 [DEBUG] Resource state not found for "data.terraform_remote_state.management": data.terraform_remote_state.management

最佳答案

对于那些有类似问题的人。这主要是因为 terraform 的文档不是最新的。
对于 terraform <=0.11,您需要直接访问输出变量 没有 “输出”例如data.terraform_remote_state.management.cidr .

>=0.12 将是 “输出”例如data.terraform_remote_state.management.outputs.cidr .

网站上的文档也将得到修复,但目前尚未部署。

https://github.com/hashicorp/terraform/commit/142ecfefe063c8f78cdbcbaaa3b5bb963831a98e#diff-4b355b6363c6f1e57a6132decd8502e9

关于terraform - 资源没有变量的属性 - Terraform 远程状态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49732370/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com