Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
359 views
in Technique[技术] by (71.8m points)

amazon web services - In Terraform, how do you output a list from an array of objects?

I'm creating a series of s3 buckets with this definition:

resource "aws_s3_bucket" "map" {
  for_each = local.bucket_settings
  bucket = each.key
...
}

I'd like to output a list of the website endpoints:

 output "website_endpoints" {
    # value = aws_s3_bucket.map["example.com"].website_endpoint
    value = ["${keys(aws_s3_bucket.map)}"] 
 }

What's the syntax to pull out a list of the endpoints (rather than the full object properties)?

question from:https://stackoverflow.com/questions/65840607/in-terraform-how-do-you-output-a-list-from-an-array-of-objects

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

If you just want to get a list of website_endpoint, then you can do:

 output "website_endpoints" {
    value = values(aws_s3_bucket.map)[*].website_endpoint
 }

This uses splat expression.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...