Skip to content

Commit

Permalink
Group CloudFormation resources by AWS service name (awslabs#234)
Browse files Browse the repository at this point in the history
* fix(schema): Move resources to separate packages

BREAKING CHANGE: this change moves all Cloudformation resources to
packages based on the AWS service name. The main motivation for this is
that building goformation on some platforms (Windows) failed due to too
many files in the old cloudformation/resources package. This new package
style has a nice benefit of slightly nicer to use API, but is a breaking
change and will require refactoring existing codebases to update to v3.

Old usage:

```go
import "github.com/awslabs/goformation/v2/cloudformation/resources"

... snip ...

topic := &resources.AWSSNSTopic{}
```

New usage:

```go
import "github.com/awslabs/goformation/v3/cloudformation/sns"

...snip...

topic := &sns.Topic{}
```

Most tests are still failing at this point and need refactoring.

* fix(schema): Tag handling

Fixed tag handling for new grouped resources style (via new tags.Tag
struct).

* fix(schema): SAM specification

SAM Specification now generates nicely with new grouped resources
format. Also all tests are now passing \o/
  • Loading branch information
PaulMaddox authored Oct 27, 2019
1 parent 7914822 commit d0749e6
Show file tree
Hide file tree
Showing 2,427 changed files with 121,308 additions and 71,445 deletions.
14 changes: 8 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
As with other Go libraries, GoFormation can be installed with `go get`.

```
$ go get github.com/awslabs/goformation/v2
$ go get github.com/awslabs/goformation/v3
```

## Usage
Expand All @@ -44,8 +44,10 @@ import (
"strconv"
"time"

"github.com/awslabs/goformation/v2/cloudformation"
"github.com/awslabs/goformation/v2/cloudformation/resources"
"github.com/awslabs/goformation/v3/cloudformation"
"github.com/awslabs/goformation/v3/cloudformation/sns"


)

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

// Create an Amazon SNS topic, with a unique name based off the current timestamp
template.Resources["MyTopic"] = &resources.AWSSNSTopic{
template.Resources["MyTopic"] = &sns.Topic{
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"] = &resources.AWSSNSSubscription{
template.Resources["MyTopicSubscription"] = &sns.Subscription{
TopicArn: cloudformation.Ref("MyTopic"),
Protocol: "email",
Endpoint: "[email protected]",
Expand Down Expand Up @@ -157,7 +159,7 @@ package main
import (
"log"
"github.com/awslabs/goformation/v2"
"github.com/awslabs/goformation/v3"
)
func main() {
Expand Down
8,471 changes: 4,285 additions & 4,186 deletions cloudformation/all.go

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
package resources
package amazonmq

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

"github.com/awslabs/goformation/v3/cloudformation/policies"
)

// AWSAmazonMQBroker AWS CloudFormation Resource (AWS::AmazonMQ::Broker)
// Broker AWS CloudFormation Resource (AWS::AmazonMQ::Broker)
// See: http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-amazonmq-broker.html
type AWSAmazonMQBroker struct {
type Broker struct {

// AutoMinorVersionUpgrade AWS CloudFormation Property
// Required: true
Expand All @@ -24,7 +25,7 @@ type AWSAmazonMQBroker struct {
// Configuration AWS CloudFormation Property
// Required: false
// See: http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-amazonmq-broker.html#cfn-amazonmq-broker-configuration
Configuration *AWSAmazonMQBroker_ConfigurationId `json:"Configuration,omitempty"`
Configuration *Broker_ConfigurationId `json:"Configuration,omitempty"`

// DeploymentMode AWS CloudFormation Property
// Required: true
Expand All @@ -34,7 +35,7 @@ type AWSAmazonMQBroker struct {
// EncryptionOptions AWS CloudFormation Property
// Required: false
// See: http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-amazonmq-broker.html#cfn-amazonmq-broker-encryptionoptions
EncryptionOptions *AWSAmazonMQBroker_EncryptionOptions `json:"EncryptionOptions,omitempty"`
EncryptionOptions *Broker_EncryptionOptions `json:"EncryptionOptions,omitempty"`

// EngineType AWS CloudFormation Property
// Required: true
Expand All @@ -54,12 +55,12 @@ type AWSAmazonMQBroker struct {
// Logs AWS CloudFormation Property
// Required: false
// See: http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-amazonmq-broker.html#cfn-amazonmq-broker-logs
Logs *AWSAmazonMQBroker_LogList `json:"Logs,omitempty"`
Logs *Broker_LogList `json:"Logs,omitempty"`

// MaintenanceWindowStartTime AWS CloudFormation Property
// Required: false
// See: http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-amazonmq-broker.html#cfn-amazonmq-broker-maintenancewindowstarttime
MaintenanceWindowStartTime *AWSAmazonMQBroker_MaintenanceWindow `json:"MaintenanceWindowStartTime,omitempty"`
MaintenanceWindowStartTime *Broker_MaintenanceWindow `json:"MaintenanceWindowStartTime,omitempty"`

// PubliclyAccessible AWS CloudFormation Property
// Required: true
Expand All @@ -79,12 +80,12 @@ type AWSAmazonMQBroker struct {
// Tags AWS CloudFormation Property
// Required: false
// See: http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-amazonmq-broker.html#cfn-amazonmq-broker-tags
Tags []AWSAmazonMQBroker_TagsEntry `json:"Tags,omitempty"`
Tags []Broker_TagsEntry `json:"Tags,omitempty"`

// Users AWS CloudFormation Property
// Required: true
// See: http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-amazonmq-broker.html#cfn-amazonmq-broker-users
Users []AWSAmazonMQBroker_User `json:"Users,omitempty"`
Users []Broker_User `json:"Users,omitempty"`

// _deletionPolicy represents a CloudFormation DeletionPolicy
_deletionPolicy policies.DeletionPolicy
Expand All @@ -97,50 +98,50 @@ type AWSAmazonMQBroker struct {
}

// AWSCloudFormationType returns the AWS CloudFormation resource type
func (r *AWSAmazonMQBroker) AWSCloudFormationType() string {
func (r *Broker) AWSCloudFormationType() string {
return "AWS::AmazonMQ::Broker"
}

// DependsOn returns a slice of logical ID names this resource depends on.
// see: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-attribute-dependson.html
func (r *AWSAmazonMQBroker) DependsOn() []string {
func (r *Broker) DependsOn() []string {
return r._dependsOn
}

// SetDependsOn specify that the creation of this resource follows another.
// see: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-attribute-dependson.html
func (r *AWSAmazonMQBroker) SetDependsOn(dependencies []string) {
func (r *Broker) SetDependsOn(dependencies []string) {
r._dependsOn = dependencies
}

// Metadata returns the metadata associated with this resource.
// see: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-attribute-metadata.html
func (r *AWSAmazonMQBroker) Metadata() map[string]interface{} {
func (r *Broker) Metadata() map[string]interface{} {
return r._metadata
}

// SetMetadata enables you to associate structured data with this resource.
// see: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-attribute-metadata.html
func (r *AWSAmazonMQBroker) SetMetadata(metadata map[string]interface{}) {
func (r *Broker) SetMetadata(metadata map[string]interface{}) {
r._metadata = metadata
}

// DeletionPolicy returns the AWS CloudFormation DeletionPolicy to this resource
// see: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-attribute-deletionpolicy.html
func (r *AWSAmazonMQBroker) DeletionPolicy() policies.DeletionPolicy {
func (r *Broker) DeletionPolicy() policies.DeletionPolicy {
return r._deletionPolicy
}

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

// MarshalJSON is a custom JSON marshalling hook that embeds this object into
// an AWS CloudFormation JSON resource's 'Properties' field and adds a 'Type'.
func (r AWSAmazonMQBroker) MarshalJSON() ([]byte, error) {
type Properties AWSAmazonMQBroker
func (r Broker) MarshalJSON() ([]byte, error) {
type Properties Broker
return json.Marshal(&struct {
Type string
Properties Properties
Expand All @@ -158,8 +159,8 @@ func (r AWSAmazonMQBroker) MarshalJSON() ([]byte, error) {

// UnmarshalJSON is a custom JSON unmarshalling hook that strips the outer
// AWS CloudFormation resource object, and just keeps the 'Properties' field.
func (r *AWSAmazonMQBroker) UnmarshalJSON(b []byte) error {
type Properties AWSAmazonMQBroker
func (r *Broker) UnmarshalJSON(b []byte) error {
type Properties Broker
res := &struct {
Type string
Properties *Properties
Expand All @@ -178,7 +179,7 @@ func (r *AWSAmazonMQBroker) UnmarshalJSON(b []byte) error {

// If the resource has no Properties set, it could be nil
if res.Properties != nil {
*r = AWSAmazonMQBroker(*res.Properties)
*r = Broker(*res.Properties)
}
if res.DependsOn != nil {
r._dependsOn = res.DependsOn
Expand Down
70 changes: 70 additions & 0 deletions cloudformation/amazonmq/aws-amazonmq-broker_configurationid.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package amazonmq

import (
"github.com/awslabs/goformation/v3/cloudformation/policies"
)

// Broker_ConfigurationId AWS CloudFormation Resource (AWS::AmazonMQ::Broker.ConfigurationId)
// See: http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-amazonmq-broker-configurationid.html
type Broker_ConfigurationId struct {

// Id AWS CloudFormation Property
// Required: true
// See: http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-amazonmq-broker-configurationid.html#cfn-amazonmq-broker-configurationid-id
Id string `json:"Id,omitempty"`

// Revision AWS CloudFormation Property
// Required: true
// See: http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-amazonmq-broker-configurationid.html#cfn-amazonmq-broker-configurationid-revision
Revision int `json:"Revision"`

// _deletionPolicy represents a CloudFormation DeletionPolicy
_deletionPolicy policies.DeletionPolicy

// _dependsOn stores the logical ID of the resources to be created before this resource
_dependsOn []string

// _metadata stores structured data associated with this resource
_metadata map[string]interface{}
}

// AWSCloudFormationType returns the AWS CloudFormation resource type
func (r *Broker_ConfigurationId) AWSCloudFormationType() string {
return "AWS::AmazonMQ::Broker.ConfigurationId"
}

// DependsOn returns a slice of logical ID names this resource depends on.
// see: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-attribute-dependson.html
func (r *Broker_ConfigurationId) DependsOn() []string {
return r._dependsOn
}

// SetDependsOn specify that the creation of this resource follows another.
// see: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-attribute-dependson.html
func (r *Broker_ConfigurationId) SetDependsOn(dependencies []string) {
r._dependsOn = dependencies
}

// Metadata returns the metadata associated with this resource.
// see: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-attribute-metadata.html
func (r *Broker_ConfigurationId) Metadata() map[string]interface{} {
return r._metadata
}

// SetMetadata enables you to associate structured data with this resource.
// see: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-attribute-metadata.html
func (r *Broker_ConfigurationId) SetMetadata(metadata map[string]interface{}) {
r._metadata = metadata
}

// DeletionPolicy returns the AWS CloudFormation DeletionPolicy to this resource
// see: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-attribute-deletionpolicy.html
func (r *Broker_ConfigurationId) DeletionPolicy() policies.DeletionPolicy {
return r._deletionPolicy
}

// SetDeletionPolicy applies an AWS CloudFormation DeletionPolicy to this resource
// see: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-attribute-deletionpolicy.html
func (r *Broker_ConfigurationId) SetDeletionPolicy(policy policies.DeletionPolicy) {
r._deletionPolicy = policy
}
70 changes: 70 additions & 0 deletions cloudformation/amazonmq/aws-amazonmq-broker_encryptionoptions.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package amazonmq

import (
"github.com/awslabs/goformation/v3/cloudformation/policies"
)

// Broker_EncryptionOptions AWS CloudFormation Resource (AWS::AmazonMQ::Broker.EncryptionOptions)
// See: http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-amazonmq-broker-encryptionoptions.html
type Broker_EncryptionOptions struct {

// KmsKeyId AWS CloudFormation Property
// Required: false
// See: http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-amazonmq-broker-encryptionoptions.html#cfn-amazonmq-broker-encryptionoptions-kmskeyid
KmsKeyId string `json:"KmsKeyId,omitempty"`

// UseAwsOwnedKey AWS CloudFormation Property
// Required: true
// See: http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-amazonmq-broker-encryptionoptions.html#cfn-amazonmq-broker-encryptionoptions-useawsownedkey
UseAwsOwnedKey bool `json:"UseAwsOwnedKey"`

// _deletionPolicy represents a CloudFormation DeletionPolicy
_deletionPolicy policies.DeletionPolicy

// _dependsOn stores the logical ID of the resources to be created before this resource
_dependsOn []string

// _metadata stores structured data associated with this resource
_metadata map[string]interface{}
}

// AWSCloudFormationType returns the AWS CloudFormation resource type
func (r *Broker_EncryptionOptions) AWSCloudFormationType() string {
return "AWS::AmazonMQ::Broker.EncryptionOptions"
}

// DependsOn returns a slice of logical ID names this resource depends on.
// see: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-attribute-dependson.html
func (r *Broker_EncryptionOptions) DependsOn() []string {
return r._dependsOn
}

// SetDependsOn specify that the creation of this resource follows another.
// see: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-attribute-dependson.html
func (r *Broker_EncryptionOptions) SetDependsOn(dependencies []string) {
r._dependsOn = dependencies
}

// Metadata returns the metadata associated with this resource.
// see: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-attribute-metadata.html
func (r *Broker_EncryptionOptions) Metadata() map[string]interface{} {
return r._metadata
}

// SetMetadata enables you to associate structured data with this resource.
// see: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-attribute-metadata.html
func (r *Broker_EncryptionOptions) SetMetadata(metadata map[string]interface{}) {
r._metadata = metadata
}

// DeletionPolicy returns the AWS CloudFormation DeletionPolicy to this resource
// see: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-attribute-deletionpolicy.html
func (r *Broker_EncryptionOptions) DeletionPolicy() policies.DeletionPolicy {
return r._deletionPolicy
}

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

0 comments on commit d0749e6

Please sign in to comment.