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

Viewed 1711

Let's say I have the following Terraform script:

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. At the moment I have to manually open the AWS console and look for the correct values there.

Or is this not possible

1 Answers

There are few ways. You can just output when you deploy:

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

You can also use TF console. 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:

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. No need for data source.

Related