Skip to content

Commit

Permalink
refactor(generator): moving resources and policies into their own pac…
Browse files Browse the repository at this point in the history
…kages (awslabs#161)

BREAKING CHANGE: this PR refactors the auto-generated CloudFormation resources out of the cloudformation package and into a dedicated package (resources). This helps keep the auto generated files separate from others.

E.g. cloudformation.AWSSnsTopic{} becomes resources.AWSSnsTopic{}
  • Loading branch information
Graham Jenson authored and PaulMaddox committed Mar 10, 2019
1 parent 651d072 commit 03a0123
Show file tree
Hide file tree
Showing 1,184 changed files with 8,887 additions and 6,991 deletions.
27 changes: 14 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# AWS GoFormation

[![Build Status](https://travis-ci.org/awslabs/goformation.svg?branch=0.1.0)](https://travis-ci.org/awslabs/goformation) [![GoDoc Reference](https://godoc.org/gopkg.in/awslabs/goformation.v1?status.svg)](http://godoc.org/github.com/awslabs/goformation) ![Apache-2.0](https://img.shields.io/badge/Licence-Apache%202.0-blue.svg)
[![Build Status](https://travis-ci.org/awslabs/goformation.svg?branch=0.1.0)](https://travis-ci.org/awslabs/goformation) [![GoDoc Reference](https://godoc.org/gopkg.in/awslabs/goformation.v1?status.svg)](http://godoc.org/github.com/awslabs/goformation) ![Apache-2.0](https://img.shields.io/badge/Licence-Apache%202.0-blue.svg)

`GoFormation` is a Go library for working with AWS CloudFormation / AWS Serverless Application Model (SAM) templates.
`GoFormation` is a Go library for working with AWS CloudFormation / AWS Serverless Application Model (SAM) templates.
- [Main features](#main-features)
- [Installation](#installation)
- [Usage](#usage)
Expand Down Expand Up @@ -45,6 +45,7 @@ import (
"time"

"github.com/awslabs/goformation/cloudformation"
"github.com/awslabs/goformation/cloudformation/resources"
)

func main() {
Expand All @@ -53,12 +54,12 @@ func main() {
template := cloudformation.NewTemplate()

// Create an Amazon SNS topic, with a unique name based off the current timestamp
template.Resources["MyTopic"] = &cloudformation.AWSSNSTopic{
template.Resources["MyTopic"] = &resources.AWSSNSTopic{
TopicName: "my-topic-" + strconv.FormatInt(time.Now().Unix(), 10),
}

// Create a subscription, connected to our topic, that forwards notifications to an email address
template.Resources["MyTopicSubscription"] = &cloudformation.AWSSNSSubscription{
template.Resources["MyTopicSubscription"] = &resources.AWSSNSSubscription{
TopicArn: cloudformation.Ref("MyTopic"),
Protocol: "email",
Endpoint: "some.email@example.com",
Expand Down Expand Up @@ -146,7 +147,7 @@ When creating templates, you can use the following convenience functions to use
- `Not(conditions []string)`
- `Or(conditions []string)`

### Unmarshalling CloudFormation YAML/JSON into Go structs
### Unmarshalling CloudFormation YAML/JSON into Go structs

GoFormation also works the other way - parsing JSON/YAML CloudFormation/SAM templates into Go structs.

Expand Down Expand Up @@ -191,7 +192,7 @@ func main() {
```

## Updating CloudFormation / SAM Resources in GoFormation

AWS GoFormation contains automatically generated Go structs for every CloudFormation/SAM resource, located in the [cloudformation/](cloudformation/) directory. These can be generated, from the latest [AWS CloudFormation Resource Specification](http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/cfn-resource-specification.html) published for `us-east-1` by just running `go generate`:

```
Expand All @@ -216,13 +217,13 @@ The following [AWS CloudFormation Intrinsic Functions](http://docs.aws.amazon.co
- [x] [Fn::Select](intrinsics/fnselect.go)
- [x] [Fn::Split](intrinsics/fnsplit.go)
- [x] [Fn::Sub](intrinsics/fnsub.go)
- [x] [Ref](intrinsics/ref.go)
- [x] [Fn::And](intrinsics/fnand.go)
- [x] [Fn::Equals](intrinsics/fnequals.go)
- [x] [Fn::If](intrinsics/fnif.go)
- [x] [Fn::Not](intrinsics/fnnot.go)
- [x] [Fn::Or](intrinsics/fnor.go)
- [ ] Fn::GetAtt
- [x] [Ref](intrinsics/ref.go)
- [x] [Fn::And](intrinsics/fnand.go)
- [x] [Fn::Equals](intrinsics/fnequals.go)
- [x] [Fn::If](intrinsics/fnif.go)
- [x] [Fn::Not](intrinsics/fnnot.go)
- [x] [Fn::Or](intrinsics/fnor.go)
- [ ] Fn::GetAtt
- [x] [Fn::GetAZs](intrinsics/fngetazs.go)
- [ ] Fn::ImportValue

Expand Down
4,417 changes: 2,209 additions & 2,208 deletions cloudformation/all.go

Large diffs are not rendered by default.

36 changes: 0 additions & 36 deletions cloudformation/aws-cloudfront-distribution_legacycustomorigin.go

This file was deleted.

21 changes: 0 additions & 21 deletions cloudformation/aws-cloudfront-distribution_legacys3origin.go

This file was deleted.

11 changes: 0 additions & 11 deletions cloudformation/aws-ssm-patchbaseline_patchgroup.go

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package cloudformation
package policies

// CreationPolicy prevents a resource status from reaching create complete until AWS CloudFormation receives a specified number of success signals or the timeout period is exceeded. To signal a resource, you can use the cfn-signal helper script or SignalResource API. AWS CloudFormation publishes valid signals to the stack events so that you track the number of signals sent.
type CreationPolicy struct {
Expand Down
36 changes: 19 additions & 17 deletions cloudformation/policies_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"github.com/sanathkr/yaml"

"github.com/awslabs/goformation/cloudformation"
"github.com/awslabs/goformation/cloudformation/policies"
"github.com/awslabs/goformation/cloudformation/resources"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
Expand All @@ -15,13 +17,13 @@ var _ = Describe("Goformation", func() {

tests := []struct {
Name string
Input *cloudformation.UpdatePolicy
Input *policies.UpdatePolicy
Expected interface{}
}{
{
Name: "AutoScalingReplacingUpdate",
Input: &cloudformation.UpdatePolicy{
AutoScalingReplacingUpdate: &cloudformation.AutoScalingReplacingUpdate{
Input: &policies.UpdatePolicy{
AutoScalingReplacingUpdate: &policies.AutoScalingReplacingUpdate{
WillReplace: true,
},
},
Expand All @@ -33,8 +35,8 @@ var _ = Describe("Goformation", func() {
},
{
Name: "AutoScalingReplacingUpdate",
Input: &cloudformation.UpdatePolicy{
AutoScalingRollingUpdate: &cloudformation.AutoScalingRollingUpdate{
Input: &policies.UpdatePolicy{
AutoScalingRollingUpdate: &policies.AutoScalingRollingUpdate{
MaxBatchSize: 10,
MinInstancesInService: 11,
MinSuccessfulInstancesPercent: 12,
Expand All @@ -56,8 +58,8 @@ var _ = Describe("Goformation", func() {
},
{
Name: "AutoScalingScheduledAction",
Input: &cloudformation.UpdatePolicy{
AutoScalingScheduledAction: &cloudformation.AutoScalingScheduledAction{
Input: &policies.UpdatePolicy{
AutoScalingScheduledAction: &policies.AutoScalingScheduledAction{
IgnoreUnmodifiedGroupSizeProperties: true,
},
},
Expand All @@ -69,8 +71,8 @@ var _ = Describe("Goformation", func() {
},
{
Name: "CodeDeployLambdaAliasUpdate",
Input: &cloudformation.UpdatePolicy{
CodeDeployLambdaAliasUpdate: &cloudformation.CodeDeployLambdaAliasUpdate{
Input: &policies.UpdatePolicy{
CodeDeployLambdaAliasUpdate: &policies.CodeDeployLambdaAliasUpdate{
ApplicationName: "test-application-name",
DeploymentGroupName: "test-deployment-group-name",
AfterAllowTrafficHook: "test-after-allow-traffic-hook",
Expand All @@ -93,7 +95,7 @@ var _ = Describe("Goformation", func() {

It("should have the correct values for "+test.Name, func() {

asg := cloudformation.AWSAutoScalingAutoScalingGroup{}
asg := resources.AWSAutoScalingAutoScalingGroup{}
asg.SetUpdatePolicy(test.Input)

template := &cloudformation.Template{
Expand Down Expand Up @@ -128,16 +130,16 @@ var _ = Describe("Goformation", func() {

tests := []struct {
Name string
Input *cloudformation.CreationPolicy
Input *policies.CreationPolicy
Expected interface{}
}{
{
Name: "CreationPolicy",
Input: &cloudformation.CreationPolicy{
AutoScalingCreationPolicy: &cloudformation.AutoScalingCreationPolicy{
Input: &policies.CreationPolicy{
AutoScalingCreationPolicy: &policies.AutoScalingCreationPolicy{
MinSuccessfulInstancesPercent: 10,
},
ResourceSignal: &cloudformation.ResourceSignal{
ResourceSignal: &policies.ResourceSignal{
Count: 11,
Timeout: "test-timeout",
},
Expand All @@ -159,7 +161,7 @@ var _ = Describe("Goformation", func() {

It("should have the correct values for "+test.Name, func() {

asg := cloudformation.AWSAutoScalingAutoScalingGroup{}
asg := resources.AWSAutoScalingAutoScalingGroup{}
asg.SetCreationPolicy(test.Input)

template := &cloudformation.Template{
Expand Down Expand Up @@ -194,7 +196,7 @@ var _ = Describe("Goformation", func() {

tests := []struct {
Name string
Input cloudformation.DeletionPolicy
Input policies.DeletionPolicy
Expected interface{}
}{
{
Expand All @@ -219,7 +221,7 @@ var _ = Describe("Goformation", func() {

It("should have the correct values for "+test.Name, func() {

asg := cloudformation.AWSAutoScalingAutoScalingGroup{}
asg := resources.AWSAutoScalingAutoScalingGroup{}
asg.SetDeletionPolicy(test.Input)

template := &cloudformation.Template{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package cloudformation
package resources

import (
"bytes"
"encoding/json"
"fmt"
"github.com/awslabs/goformation/cloudformation/policies"
)

// AlexaASKSkill AWS CloudFormation Resource (Alexa::ASK::Skill)
Expand All @@ -26,7 +27,7 @@ type AlexaASKSkill struct {
VendorId string `json:"VendorId,omitempty"`

// _deletionPolicy represents a CloudFormation DeletionPolicy
_deletionPolicy DeletionPolicy
_deletionPolicy policies.DeletionPolicy

// _dependsOn stores the logical ID of the resources to be created before this resource
_dependsOn []string
Expand Down Expand Up @@ -66,7 +67,7 @@ func (r *AlexaASKSkill) SetMetadata(metadata map[string]interface{}) {

// SetDeletionPolicy applies an AWS CloudFormation DeletionPolicy to this resource
// see: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-attribute-deletionpolicy.html
func (r *AlexaASKSkill) SetDeletionPolicy(policy DeletionPolicy) {
func (r *AlexaASKSkill) SetDeletionPolicy(policy policies.DeletionPolicy) {
r._deletionPolicy = policy
}

Expand All @@ -77,9 +78,9 @@ func (r AlexaASKSkill) MarshalJSON() ([]byte, error) {
return json.Marshal(&struct {
Type string
Properties Properties
DependsOn []string `json:"DependsOn,omitempty"`
Metadata map[string]interface{} `json:"Metadata,omitempty"`
DeletionPolicy DeletionPolicy `json:"DeletionPolicy,omitempty"`
DependsOn []string `json:"DependsOn,omitempty"`
Metadata map[string]interface{} `json:"Metadata,omitempty"`
DeletionPolicy policies.DeletionPolicy `json:"DeletionPolicy,omitempty"`
}{
Type: r.AWSCloudFormationType(),
Properties: (Properties)(r),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
package cloudformation
package resources

import "github.com/awslabs/goformation/cloudformation/policies"

// AlexaASKSkill_AuthenticationConfiguration AWS CloudFormation Resource (Alexa::ASK::Skill.AuthenticationConfiguration)
// See: http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-ask-skill-authenticationconfiguration.html
Expand All @@ -20,7 +22,7 @@ type AlexaASKSkill_AuthenticationConfiguration struct {
RefreshToken string `json:"RefreshToken,omitempty"`

// _deletionPolicy represents a CloudFormation DeletionPolicy
_deletionPolicy DeletionPolicy
_deletionPolicy policies.DeletionPolicy

// _dependsOn stores the logical ID of the resources to be created before this resource
_dependsOn []string
Expand Down Expand Up @@ -60,6 +62,6 @@ func (r *AlexaASKSkill_AuthenticationConfiguration) SetMetadata(metadata map[str

// SetDeletionPolicy applies an AWS CloudFormation DeletionPolicy to this resource
// see: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-attribute-deletionpolicy.html
func (r *AlexaASKSkill_AuthenticationConfiguration) SetDeletionPolicy(policy DeletionPolicy) {
func (r *AlexaASKSkill_AuthenticationConfiguration) SetDeletionPolicy(policy policies.DeletionPolicy) {
r._deletionPolicy = policy
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
package cloudformation
package resources

import "github.com/awslabs/goformation/cloudformation/policies"

// AlexaASKSkill_Overrides AWS CloudFormation Resource (Alexa::ASK::Skill.Overrides)
// See: http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-ask-skill-overrides.html
Expand All @@ -10,7 +12,7 @@ type AlexaASKSkill_Overrides struct {
Manifest interface{} `json:"Manifest,omitempty"`

// _deletionPolicy represents a CloudFormation DeletionPolicy
_deletionPolicy DeletionPolicy
_deletionPolicy policies.DeletionPolicy

// _dependsOn stores the logical ID of the resources to be created before this resource
_dependsOn []string
Expand Down Expand Up @@ -50,6 +52,6 @@ func (r *AlexaASKSkill_Overrides) SetMetadata(metadata map[string]interface{}) {

// SetDeletionPolicy applies an AWS CloudFormation DeletionPolicy to this resource
// see: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-attribute-deletionpolicy.html
func (r *AlexaASKSkill_Overrides) SetDeletionPolicy(policy DeletionPolicy) {
func (r *AlexaASKSkill_Overrides) SetDeletionPolicy(policy policies.DeletionPolicy) {
r._deletionPolicy = policy
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
package cloudformation
package resources

import "github.com/awslabs/goformation/cloudformation/policies"

// AlexaASKSkill_SkillPackage AWS CloudFormation Resource (Alexa::ASK::Skill.SkillPackage)
// See: http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-ask-skill-skillpackage.html
Expand Down Expand Up @@ -30,7 +32,7 @@ type AlexaASKSkill_SkillPackage struct {
S3ObjectVersion string `json:"S3ObjectVersion,omitempty"`

// _deletionPolicy represents a CloudFormation DeletionPolicy
_deletionPolicy DeletionPolicy
_deletionPolicy policies.DeletionPolicy

// _dependsOn stores the logical ID of the resources to be created before this resource
_dependsOn []string
Expand Down Expand Up @@ -70,6 +72,6 @@ func (r *AlexaASKSkill_SkillPackage) SetMetadata(metadata map[string]interface{}

// SetDeletionPolicy applies an AWS CloudFormation DeletionPolicy to this resource
// see: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-attribute-deletionpolicy.html
func (r *AlexaASKSkill_SkillPackage) SetDeletionPolicy(policy DeletionPolicy) {
func (r *AlexaASKSkill_SkillPackage) SetDeletionPolicy(policy policies.DeletionPolicy) {
r._deletionPolicy = policy
}
Loading

0 comments on commit 03a0123

Please sign in to comment.