gpt4 book ai didi

terraform 控制台 - 如何获取模块属性值

转载 作者:行者123 更新时间:2023-12-03 19:53:18 27 4
gpt4 key购买 nike

尝试使用 terraform 控制台,新功能。
我使用 tfstate 进入我的项目并运行“terraform 控制台”。
我可以使用常规插值系统获取变量值、数据和资源。但是,模块很难破解,我无法正确使用它 - 我试过:module.name.attribute,但它不知道,在网络上使用控制台的例子不多:-/

感谢期待。

最佳答案

虽然文档中没有明确说明,但是好像不能引用模块中的局部变量,只能看到模块的输出。

下面是一个例子:

$ tree
.
├── foo
│   └── bar.tf
├── main.tf
└── terraform.tfstate

1 directory, 3 files

主文件
provider "null" {}

module "foo" {
source = "./foo"
}

foo/bar.tf
resource "null_resource" "bar" {}

output "bar_id" {
value = "${null_resource.bar.id}"
}

terraform.tfstate
{
"version": 3,
"terraform_version": "0.8.4",
"serial": 4,
"lineage": "9e66cc40-5dfa-4c4e-929e-bc02fa7db57e",
"modules": [
{
"path": [
"root"
],
"outputs": {},
"resources": {},
"depends_on": []
},
{
"path": [
"root",
"foo"
],
"outputs": {
"bar_id": {
"sensitive": false,
"type": "string",
"value": "1810628649389143335"
}
},
"resources": {
"null_resource.bar": {
"type": "null_resource",
"depends_on": [],
"primary": {
"id": "1810628649389143335",
"attributes": {
"id": "1810628649389143335"
},
"meta": {},
"tainted": false
},
"deposed": [],
"provider": ""
}
},
"depends_on": []
},
{
"path": [
"root",
"hoge"
],
"outputs": {},
"resources": {},
"depends_on": []
}
]
}

可以引用 module.foo.bar_id :
$ terraform console
> module.foo.bar_id
1810628649389143335

其他不工作:
$ terraform console
> null_resource.bar.id
Resource 'null_resource.bar' not found for variable 'null_resource.bar.id'

> module.foo.null_resource.bar.id
Couldn't find output "null_resource.bar.id" for module var: module.foo.null_resource.bar.id

关于terraform 控制台 - 如何获取模块属性值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41940517/

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