Documentation ¶
Overview ¶
Example (To_go) ¶
// Open a template from file (can be JSON or YAML) template, err := goformation.Open("example/yaml-to-go/template.yaml") if err != nil { fmt.Printf("There was an error processing the template: %s", err) return } // You can extract all resources of a certain type // Each AWS CloudFormation resource is a strongly typed struct topics := template.GetAllSNSTopicResources() for name, topic := range topics { // E.g. Found a AWS::SNS::Topic with Logical ID ExampleTopic and TopicName 'example' fmt.Printf("Found a %s with Logical ID %s and TopicName %s\n", topic.AWSCloudFormationType(), name, *topic.TopicName) } // You can also search for specific resources by their logicalId search := "ExampleTopic" topic, err := template.GetSNSTopicWithName(search) if err != nil { fmt.Printf("SNS topic with logical ID %s not found", search) return } // E.g. Found a AWS::Serverless::Function named GetHelloWorld (runtime: nodejs6.10) fmt.Printf("Found a %s with Logical ID %s and TopicName %s\n", topic.AWSCloudFormationType(), search, *topic.TopicName)
Output: Found a AWS::SNS::Topic with Logical ID ExampleTopic and TopicName example Found a AWS::SNS::Topic with Logical ID ExampleTopic and TopicName example
Example (To_json) ¶
// Create a new CloudFormation template template := cloudformation.NewTemplate() // Create an Amazon SNS topic, with a unique name based off the current timestamp template.Resources["MyTopic"] = &sns.Topic{ TopicName: cloudformation.String("my-topic-1575143839"), } // Create a subscription, connected to our topic, that forwards notifications to an email address template.Resources["MyTopicSubscription"] = &sns.Subscription{ TopicArn: cloudformation.Ref("MyTopic"), Protocol: "email", Endpoint: cloudformation.String("some.email@example.com"), } // Let's see the JSON AWS CloudFormation template j, err := template.JSON() if err != nil { fmt.Printf("Failed to generate JSON: %s\n", err) } else { fmt.Printf("%s\n", string(j)) }
Output: { "AWSTemplateFormatVersion": "2010-09-09", "Resources": { "MyTopic": { "Properties": { "TopicName": "my-topic-1575143839" }, "Type": "AWS::SNS::Topic" }, "MyTopicSubscription": { "Properties": { "Endpoint": "some.email@example.com", "Protocol": "email", "TopicArn": { "Ref": "MyTopic" } }, "Type": "AWS::SNS::Subscription" } } }
Example (To_yaml) ¶
// Create a new CloudFormation template template := cloudformation.NewTemplate() // Create an Amazon SNS topic, with a unique name based off the current timestamp template.Resources["MyTopic"] = &sns.Topic{ TopicName: cloudformation.String("my-topic-1575143970"), } // Create a subscription, connected to our topic, that forwards notifications to an email address template.Resources["MyTopicSubscription"] = &sns.Subscription{ TopicArn: cloudformation.Ref("MyTopic"), Protocol: "email", Endpoint: cloudformation.String("some.email@example.com"), } // Let's see the YAML AWS CloudFormation template y, err := template.YAML() if err != nil { fmt.Printf("Failed to generate YAML: %s\n", err) } else { fmt.Printf("%s\n", string(y)) }
Output: AWSTemplateFormatVersion: "2010-09-09" Resources: MyTopic: Properties: TopicName: my-topic-1575143970 Type: AWS::SNS::Topic MyTopicSubscription: Properties: Endpoint: some.email@example.com Protocol: email TopicArn: Ref: MyTopic Type: AWS::SNS::Subscription
Index ¶
- func Open(filename string) (*cloudformation.Template, error)
- func OpenWithOptions(filename string, options *intrinsics.ProcessorOptions) (*cloudformation.Template, error)
- func ParseJSON(data []byte) (*cloudformation.Template, error)
- func ParseJSONWithOptions(data []byte, options *intrinsics.ProcessorOptions) (*cloudformation.Template, error)
- func ParseYAML(data []byte) (*cloudformation.Template, error)
- func ParseYAMLWithOptions(data []byte, options *intrinsics.ProcessorOptions) (*cloudformation.Template, error)
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Open ¶
func Open(filename string) (*cloudformation.Template, error)
Open and parse a AWS CloudFormation template from file. Works with either JSON or YAML formatted templates.
func OpenWithOptions ¶
func OpenWithOptions(filename string, options *intrinsics.ProcessorOptions) (*cloudformation.Template, error)
OpenWithOptions opens and parse a AWS CloudFormation template from file. Works with either JSON or YAML formatted templates. Parsing can be tweaked via the specified options.
func ParseJSON ¶
func ParseJSON(data []byte) (*cloudformation.Template, error)
ParseJSON an AWS CloudFormation template (expects a []byte of valid JSON)
func ParseJSONWithOptions ¶
func ParseJSONWithOptions(data []byte, options *intrinsics.ProcessorOptions) (*cloudformation.Template, error)
ParseJSONWithOptions an AWS CloudFormation template (expects a []byte of valid JSON) Parsing can be tweaked via the specified options.
func ParseYAML ¶
func ParseYAML(data []byte) (*cloudformation.Template, error)
ParseYAML an AWS CloudFormation template (expects a []byte of valid YAML)
func ParseYAMLWithOptions ¶
func ParseYAMLWithOptions(data []byte, options *intrinsics.ProcessorOptions) (*cloudformation.Template, error)
ParseYAMLWithOptions an AWS CloudFormation template (expects a []byte of valid YAML) Parsing can be tweaked via the specified options.
Types ¶
This section is empty.