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

terraform控制台-如何获取模块属性值,terraform,Terraform,正在尝试使用terraform控制台这一新功能。 我使用tfstate将chdir转换到我的项目,并运行“terraform console”。 我能够使用正则插值systax获得变量值、数据和资源。但是,模块很难破解,我无法将其正确使用-我尝试了:module.name.attribute,但它不知道,在web上使用console的示例不多:-/ 非常感谢。尽管文档中没有明确说明,但我们似乎无法在模块中引用局部变量,只能看到模块的输出 以下是一个例子: $ tree . ├── foo │  

正在尝试使用terraform控制台这一新功能。 我使用tfstate将chdir转换到我的项目,并运行“terraform console”。 我能够使用正则插值systax获得变量值、数据和资源。但是,模块很难破解,我无法将其正确使用-我尝试了:module.name.attribute,但它不知道,在web上使用console的示例不多:-/


非常感谢。

尽管文档中没有明确说明,但我们似乎无法在模块中引用局部变量,只能看到模块的输出

以下是一个例子:

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

1 directory, 3 files
main.tf

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\u 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