Skip to content

Instantly share code, notes, and snippets.

@devonartis
Created March 11, 2018 22:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save devonartis/26975cd3400c2e57dcd7b642dd648b35 to your computer and use it in GitHub Desktop.
Save devonartis/26975cd3400c2e57dcd7b642dd648b35 to your computer and use it in GitHub Desktop.
Example of using Paramaters with GoFormation
package main
import (
"fmt"
"github.com/awslabs/goformation/cloudformation"
)
func main() {
// Create a new CloudFormation template
template := cloudformation.NewTemplate()
instanceParam := map[string]string{
"Type": "String",
"Default": "t2.micro",
"Description": "Paramaters for EC2 Information",
}
template.Parameters["InstanceTypeParamater"] = instanceParam
// An an example SNS Topic
template.Resources["MySNSTopic"] = &cloudformation.AWSSNSTopic{
DisplayName: "test-sns-topic-display-name",
TopicName: "test-sns-topic-name",
Subscription: []cloudformation.AWSSNSTopic_Subscription{
cloudformation.AWSSNSTopic_Subscription{
Endpoint: "test-sns-topic-subscription-endpoint",
Protocol: "test-sns-topic-subscription-protocol",
},
},
}
// ...and a Route 53 Hosted Zone too
template.Resources["MyRoute53HostedZone"] = &cloudformation.AWSRoute53HostedZone{
Name: "example.com",
}
// Let's see the JSON
j, err := template.JSON()
if err != nil {
fmt.Printf("Failed to generate JSON: %s\n", err)
} else {
fmt.Printf("%s\n", string(j))
}
y, err := template.YAML()
if err != nil {
fmt.Printf("Failed to generate YAML: %s\n", err)
} else {
fmt.Printf("%s\n", string(y))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment