Open ThinkBriK opened 4 years ago
This works as a workaround:
data "external" "s3_buckets" {
program = ["${path.root}/get_buckets.sh"]
}
output "buckets" {
value = jsondecode(data.external.s3_buckets.result.buckets).Buckets[*].Name
}
get_buckets.sh:
#!/bin/bash
set -e
buckets=$(aws s3api list-buckets | jq . -r )
jq -n --arg buckets "$buckets" '{"buckets":$buckets}'
This creates a string list of bucket names if you use the value from the output or can be assigned to local
This data source could be very useful
Same for me 👍
Community Note
Description
We have a missing datasource form AWS S3 buckets : you cannot get a list of your account buckets via terraform at the moment. The only existing datasource is _aws_s3bucket and it does only support a single bucket by name.
We would need a filter to retrieve a bucket arns list, especially usefull to harden S3 VPC endpoints and prevent data exfiltration (using a policy for our account bucket only for example).
New or Affected Resource(s)
Potential Terraform Configuration
0000