Skip to content

Instantly share code, notes, and snippets.

@osule
Created June 3, 2022 03:08
Show Gist options
  • Save osule/0881e7d93569dcd4bc904540c900ae44 to your computer and use it in GitHub Desktop.
Save osule/0881e7d93569dcd4bc904540c900ae44 to your computer and use it in GitHub Desktop.
List S3 buckets in an account with Terraform
#!/bin/bash
# List the S3 buckets in an account
aws s3api list-buckets | jq '[.Buckets[]] | map({ (.Name): .Name }) | add'
data "external" "buckets" {
program = ["./list-buckets.sh"]
}
output "json" {
# List of bucket names
value = values(data.external.buckets.result)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment