Categorygithub.com/mweagle/go-cloudcondenser
modulepackage
0.0.0-20210927040427-ccf888fc5e58
Repository: https://github.com/mweagle/go-cloudcondenser.git
Documentation: pkg.go.dev

# README

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"
      }
    }
  }
}

# Packages

No description provided by the author
No description provided by the author

# Functions

Flatten takes a namePrefix and a generator and promotes the returned resources "up" one level so that they are at the normal level.
SafeMerge is a free function that merges src into dest, reporting back any conflicting merge operations.
Static returns a ResourceProvider for a static resource name.

# Constants

ContextKeyParams is the context key in the evaluation context that stores the map[string]string.

# Structs

CloudFormationCondenser is the root template type.

# Interfaces

ResourceProvider is the interface that CloudFormationCondenser Resources must satisfy.

# Type aliases

ProviderFunc is a wrapper around free functions that satisfies the ResourceProvider interface.