Library to produce CloudFormation templates from Go code
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
cmd
tests
.gitignore
.travis.yml
Gopkg.lock
Gopkg.toml
Makefile
README.md
cloudcondenser.go
doc.go

README.md

Build Status

go-cloudcondenser

Compose and compile CloudFormation templates written in Go.

Overview

Define Template

var DefaultTemplate = gocc.CloudFormationCondenser{
	Description: "My Stack",
	Resources: []interface{}{
		// Dynamically assigned resource name
		gocf.IAMRole{},
		// User defined resource name
		gocc.Static("MyResource", gocf.S3Bucket{
			BucketName: gocf.String("MyS3Bucket"),
		}),
		// Multiple resources "flattened" to WebsiteResourcesXXX
		// entries. Encapsulate logical sets of related
		// CloudFormation resources
		gocc.Flatten("WebsiteResources", MultipleResourceProvider()),
		// Include free functions to annotate the template
		gocc.ProviderFunc(freeProvider),
		// Providers can conditionally update the template
		gocc.ProviderFunc(emptyProvider),
	},
}

Evaluate Template

	ctx := context.Background()
	outputTemplate, outputErr := DefaultTemplate.Evaluate(ctx)

Convert to CLI

See ./cmd/main.go for a simple CLI app that produces JSON output from a gocc.CloudFormationCondenser instance:

Results

{
  "AWSTemplateFormatVersion": "2010-09-09",
  "Resources": {
    "CloudFormerAWSIAMRole0": {
      "Type": "AWS::IAM::Role",
      "Properties": {}
    },
    "FreeResource": {
      "Type": "AWS::S3::Bucket",
      "Properties": {
        "BucketName": "FreeBucket"
      }
    },
    "MyResource": {
      "Type": "AWS::S3::Bucket",
      "Properties": {
        "BucketName": "MyS3Bucket"
      }
    },
    "WebsiteResourcesMultiBucket": {
      "Type": "AWS::S3::Bucket",
      "Properties": {
        "BucketName": "CustomBucket"
      }
    },
    "WebsiteResourcesMultiRole": {
      "Type": "AWS::IAM::Role",
      "Properties": {
        "RoleName": "CustomRole"
      }
    }
  }
}