20
votes

I have my s3 resource in terraform with configuration:

locals {
    bucket_count = "${length(var.s3_config["bucket_names"])}"
}

resource "aws_s3_bucket" "s3_bucket" {
    count = "${local.bucket_count}"
    bucket = "${format("%s-%s", element(var.s3_config["bucket_names"], count.index), var.region)}"
    acl = "private"
    region = "${var.region}"

    tags {
        Name = "${format("%s-%s", element(var.s3_config["bucket_names"], count.index), var.region)}"
    }
}

and i want to set output variable for all created bucket so i created file names outputs.tf with content

output "buckets" {
  value = "${aws_s3_bucket.s3_bucket.*.bucket}"
}

output "buckets_arns" {
  value = "${aws_s3_bucket.s3_bucket.*.arn}"
}

when i apply configuration its ok i see outputs in terraform.tfstate file but when i call terraform output i see information that is no output or output is empty what i do wrong ?

1
Have you tried: output "buckets" { value = [ "${aws_s3_bucket.s3_bucket.*.bucket}" ] }KJH

1 Answers

33
votes

Try this:

output "buckets" {
  value = ["${aws_s3_bucket.s3_bucket.*.bucket}"]
}

output "buckets_arns" {
  value = ["${aws_s3_bucket.s3_bucket.*.arn}"]
}