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 ?
count is a meta-argument defined by the Terraform language. It can be used with modules and with every resource type. The count meta-argument accepts a whole number, and creates that many instances of the resource or module.
What is count in Terraform? When you define a resource block in Terraform, by default, this specifies one resource that will be created. To manage several of the same resources, you can use either count or for_each , which removes the need to write a separate block of code for each one.
You can have multiple resources in a single output, but to make it work, you need to use some terraform function, or format the output depending on the type, if it is a list, string, map..
Try this:
output "buckets" { value = ["${aws_s3_bucket.s3_bucket.*.bucket}"] } output "buckets_arns" { value = ["${aws_s3_bucket.s3_bucket.*.arn}"] }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With