Skip to content

Instantly share code, notes, and snippets.

Last active November 13, 2020 17:51
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Pass metadata between Terraform modules using S3. Much faster than remote state.

Save outputs from a resource to a YAML file:

# Module Alpha
resource "aws_s3_bucket_object" "outputs" {
  bucket = local.metadata_bucket
  key    = "${local.key_path}/organization.yml"
  content = yamlencode({
    "organization_arn" : aws_organizations_organization.default.arn
    "organization_id" :
  acl                    = "bucket-owner-full-control"
  content_type           = "text/plain"
  server_side_encryption = "aws:kms"

Read the YAML file in the second module

# Module Bravo
data "aws_s3_bucket_object" "organization" {
  bucket = local.metadata_bucket
  key    = local.organization_root_metafile

Use data from the file as a value for other resources

organization_arn = yamldecode(data.aws_s3_bucket_object.organization.body).organization_arn
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment