How to display all the attributes of a data source without creating individual output variables?

9,482 views
Skip to first unread message

Tony Chia

unread,
Feb 16, 2018, 8:00:41 PM2/16/18
to Terraform
For example, the aws_ami data source (https://www.terraform.io/docs/providers/aws/d/ami.html)  has many attributes that is returned after you provided some arguments for search such as image_id, description, create_date, etc.

is it possible to display all the attributes without having to create an output variable for each one? 

Here is my tf file

data "aws_ami" "latest" {
  most_recent = true

  filter {
    name   = "owner-alias"
    values = ["amazon"]
  }

  filter {
    name   = "name"
    values = ["amzn-ami-hvm-*"]
  }

  filter {
    name   = "root-device-type"
    values = ["ebs"]
  }

  owners = ["amazon"]
}

output "latest_ami_name" {
  value = "${data.aws_ami.latest.name}"
}

output "latest_ami_id" {
  value = "${data.aws_ami.latest.id}"
}


After terraform apply, I ran "terraform console" and i wanted to display all the attributes using data.aws_ami.latest.* but I can't

> data.aws_ami.latest.*
Resource 'data.aws_ami.latest' does not have attribute '*' for variable 'data.aws_ami.latest.*'
>

Sometimes you can use * like in this example.  

> join(",",data.aws_ami_ids.all_ami_ebs_root.ids)
ami-03d7677b,ami-f2d3638a,ami-02c87c7a,ami-32cf7b4a,ami-864ce7fe,ami-a142e9d9,ami-bf4193c7,ami-694b9911,ami-32d8124a,ami-d4d913ac,ami-e689729e,ami-b6956ece,ami-bb9e6ec3,ami-7d837305,ami-215dbe59,ami-aa5ebdd2,ami-6df1e514,ami-5ff2e626,ami-96767cef,ami-a07379d9,ami-4836a428,ami-3234a652,ami-1f55c27f,ami-8ca83fec,ami-0074e160,ami-b275e0d2,ami-cc39b1ac,ami-463ab226,ami-9e73ccfe,ami-f173cc91,ami-1e299d7e,ami-3d2b9f5d,ami-22cb6d42,ami-5ec1673e,ami-b04e92d0,ami-204e9240,ami-7172b611,ami-f469ad94,ami-f303fb93,ami-39798159,ami-d0f506b0,ami-d8f704b8,ami-c229c0a2,ami-c928c1a9,ami-63b25203,ami-42b15122,ami-b03420d1,ami-f0091d91,ami-83f7e8b3,ami-9ff7e8af,ami-d5c5d1e5,ami-d1c5d1e1,ami-e9527ed9,ami-e7527ed7,ami-c1c39af1,ami-dfc39aef,ami-b5a7ea85,ami-b1a7ea81,ami-8786c6b7,ami-8586c6b5,ami-8f6815bf,ami-d13845e1,ami-383a5008,ami-60f69f50,ami-f8f297c8,ami-5a20b86a,ami-e43ea1d4,ami-d75bcde7,ami-f4be2ac4,ami-1627ad26,ami-2431bf14,ami-44da5574
>

Paddy Carver

unread,
Feb 20, 2018, 5:13:43 AM2/20/18
to terrafo...@googlegroups.com
Is the `terraform show`[1] command what you're looking for?


--
This mailing list is governed under the HashiCorp Community Guidelines - https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list.
 
GitHub Issues: https://github.com/hashicorp/terraform/issues
IRC: #terraform-tool on Freenode
---
You received this message because you are subscribed to the Google Groups "Terraform" group.
To unsubscribe from this group and stop receiving emails from it, send an email to terraform-tool+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/terraform-tool/ee2e9251-1d27-4d1c-b6ca-eeb6323988f1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Tony Chia

unread,
Feb 20, 2018, 2:52:06 PM2/20/18
to Terraform
Yes, that's it. Thank you.
To unsubscribe from this group and stop receiving emails from it, send an email to terraform-too...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages