terraform-aws-terraform-state-output

AWS S3 Terraform State Output

Terraform module which creates an S3 Object containing terraform outputs.

These types of resources are supported:

Usage

locals {
  topics = ["aws", "s3", "terraform"]
  tags = {
    name        = "infraprints",
    description = "Infrastructure as Code."
  }
}

module "output_resources" {
  source = "git::https://gitlab.com/infraprints/modules/aws/terraform-state-output"

  bucket = "infraprints-terraform-state-output"
  key    = "aws/infraprints/project/outputs.tf"

  terraform_output = [
    {
      key   = "aws_account_id"
      value = "123412341234"
    },
    {
      key   = "topics"
      value = jsonencode(local.topics)
    },
    {
      key   = "tags"
      value = jsonencode(local.tags)
    },
  ]
}

With using the output of this module here:

module "example" {
  source = "s3::https://s3.amazonaws.com/infraprints-terraform-state-output/aws/infraprints/project"
}

output "aws_account_id" {
  value = module.example.aws_account_id
}

output "topics" {
  value = module.example.topics
}

output "tags" {
  value = module.example.tags
}

Examples

Notes

  • S3 Versioning should be enabled

Inputs

NameDescriptionTypeDefaultRequired
bucketThe name of the bucket to put the file in.stringn/ayes
keyThe name of the object once it is in the bucket. Should end with the .tf file extension.stringn/ayes
tagsA mapping of tags to assign to the object.map<map>no
terraform_outputA set of terraform outputs to make available.listn/ayes

Outputs

NameDescription
etagThe ETag generated for the object (an MD5 sum of the object content). For plaintext objects or objects encrypted with an AWS-managed key, the hash is an MD5 digest of the object data. For objects encrypted with a KMS key or objects created by either the Multipart Upload or Part Copy operation, the hash is not an MD5 digest, regardless of the method of encryption. More information on possible values can be found on Common Response Headers.
idThe key of the resource supplied above.
renderedThe final rendered template.
version_idA unique version ID value for the object, if bucket versioning is enabled.