简体   繁体   English

如何打印/调试数据源资源的所有可用字段?

[英]How can I print / debug all available fields of a data source resource?

Let's say I have the following Terraform script:假设我有以下 Terraform 脚本:

locals {
  provisioned_product_vpc_name = "provision-vpc-product"
}

resource "aws_cloudformation_stack" "provisioned_product_vpc" {
  name = local.provisioned_product_vpc_name

  template_body = "<foobar>"
}

data "aws_cloudformation_stack" "product_vpc" {
  name = local.provisioned_product_vpc_name
  depends_on = [aws_cloudformation_stack.provisioned_product_vpc]
}

How can I interactively see all the fields that aws_cloudformation_stack.product_vpc has including the values.我如何以交互方式查看aws_cloudformation_stack.product_vpc包含值的所有字段。 At the moment I have to manually open the AWS console and look for the correct values there.目前我必须手动打开 AWS 控制台并在那里查找正确的值。

Or is this not possible或者这是不可能的

There are few ways.有几种方法。 You can just output when you deploy:部署时只需output

output "product_vpc" {
  value = data.aws_cloudformation_stack.product_vpc
}

You can also use TF console .您也可以使用 TF控制台 Once you enter the console you just type:进入控制台后,您只需键入:

data.aws_cloudformation_stack.product_vpc

You can also query the sate directly using sate show , though this will provide a bit different info then the other ones:您也可以使用sate show直接查询状态,尽管这将提供与其他信息稍有不同的信息:

terraform state show data.aws_cloudformation_stack.product_vpc

But its not clear why would you use data source for that if you can directly access your resource aws_cloudformation_stack.provisioned_product_vpc in the same way.但是,如果您可以以相同的方式直接访问您的资源aws_cloudformation_stack.provisioned_product_vpc ,则尚不清楚为什么要使用数据源。 No need for data source.无需数据源。

I'd like to add when making changes to the data sources, to also run terrafrom refresh to pull the latest info before running terraform console .我想在对数据源进行更改时添加,以便在运行terraform console之前运行terrafrom refresh以获取最新信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM