Skip to content

Commit

Permalink
feat(schema): adding AWS::Serverless::StateMachine and FileSystemConf…
Browse files Browse the repository at this point in the history
…igs to Function (awslabs#284)

* [Feature] add Serverless FileSystemConfigs

* [Feature] adding step functions to SAM template

* working specs
  • Loading branch information
Graham Jenson committed Jul 26, 2020
1 parent ad54601 commit d2d23ca
Show file tree
Hide file tree
Showing 23 changed files with 2,085 additions and 0 deletions.
25 changes: 25 additions & 0 deletions cloudformation/all.go
Expand Up @@ -624,6 +624,7 @@ func AllResources() map[string]Resource {
"AWS::Serverless::Function": &serverless.Function{},
"AWS::Serverless::LayerVersion": &serverless.LayerVersion{},
"AWS::Serverless::SimpleTable": &serverless.SimpleTable{},
"AWS::Serverless::StateMachine": &serverless.StateMachine{},
"AWS::ServiceCatalog::AcceptedPortfolioShare": &servicecatalog.AcceptedPortfolioShare{},
"AWS::ServiceCatalog::CloudFormationProduct": &servicecatalog.CloudFormationProduct{},
"AWS::ServiceCatalog::CloudFormationProvisionedProduct": &servicecatalog.CloudFormationProvisionedProduct{},
Expand Down Expand Up @@ -12604,6 +12605,30 @@ func (t *Template) GetServerlessSimpleTableWithName(name string) (*serverless.Si
return nil, fmt.Errorf("resource %q of type serverless.SimpleTable not found", name)
}

// GetAllServerlessStateMachineResources retrieves all serverless.StateMachine items from an AWS CloudFormation template
func (t *Template) GetAllServerlessStateMachineResources() map[string]*serverless.StateMachine {
results := map[string]*serverless.StateMachine{}
for name, untyped := range t.Resources {
switch resource := untyped.(type) {
case *serverless.StateMachine:
results[name] = resource
}
}
return results
}

// GetServerlessStateMachineWithName retrieves all serverless.StateMachine items from an AWS CloudFormation template
// whose logical ID matches the provided name. Returns an error if not found.
func (t *Template) GetServerlessStateMachineWithName(name string) (*serverless.StateMachine, error) {
if untyped, ok := t.Resources[name]; ok {
switch resource := untyped.(type) {
case *serverless.StateMachine:
return resource, nil
}
}
return nil, fmt.Errorf("resource %q of type serverless.StateMachine not found", name)
}

// GetAllServiceCatalogAcceptedPortfolioShareResources retrieves all servicecatalog.AcceptedPortfolioShare items from an AWS CloudFormation template
func (t *Template) GetAllServiceCatalogAcceptedPortfolioShareResources() map[string]*servicecatalog.AcceptedPortfolioShare {
results := map[string]*servicecatalog.AcceptedPortfolioShare{}
Expand Down
5 changes: 5 additions & 0 deletions cloudformation/serverless/aws-serverless-function.go
Expand Up @@ -47,6 +47,11 @@ type Function struct {
// See: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction
Events map[string]Function_EventSource `json:"Events,omitempty"`

// FileSystemConfigs AWS CloudFormation Property
// Required: false
// See: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-resource-function.html
FileSystemConfigs []Function_FileSystemConfig `json:"FileSystemConfigs,omitempty"`

// FunctionName AWS CloudFormation Property
// Required: false
// See: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction
Expand Down
@@ -0,0 +1,40 @@
package serverless

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

// Function_FileSystemConfig AWS CloudFormation Resource (AWS::Serverless::Function.FileSystemConfig)
// See: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-lambda-function-filesystemconfig.html#cfn-lambda-function-filesystemconfig-localmountpath
type Function_FileSystemConfig struct {

// Arn AWS CloudFormation Property
// Required: false
// See: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-lambda-function-filesystemconfig.html#cfn-lambda-function-filesystemconfig-localmountpath
Arn string `json:"Arn,omitempty"`

// LocalMountPath AWS CloudFormation Property
// Required: false
// See: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-lambda-function-filesystemconfig.html#cfn-lambda-function-filesystemconfig-localmountpath
LocalMountPath string `json:"LocalMountPath,omitempty"`

// AWSCloudFormationDeletionPolicy represents a CloudFormation DeletionPolicy
AWSCloudFormationDeletionPolicy policies.DeletionPolicy `json:"-"`

// AWSCloudFormationUpdateReplacePolicy represents a CloudFormation UpdateReplacePolicy
AWSCloudFormationUpdateReplacePolicy policies.UpdateReplacePolicy `json:"-"`

// AWSCloudFormationDependsOn stores the logical ID of the resources to be created before this resource
AWSCloudFormationDependsOn []string `json:"-"`

// AWSCloudFormationMetadata stores structured data associated with this resource
AWSCloudFormationMetadata map[string]interface{} `json:"-"`

// AWSCloudFormationCondition stores the logical ID of the condition that must be satisfied for this resource to be created
AWSCloudFormationCondition string `json:"-"`
}

// AWSCloudFormationType returns the AWS CloudFormation resource type
func (r *Function_FileSystemConfig) AWSCloudFormationType() string {
return "AWS::Serverless::Function.FileSystemConfig"
}
151 changes: 151 additions & 0 deletions cloudformation/serverless/aws-serverless-statemachine.go
@@ -0,0 +1,151 @@
package serverless

import (
"bytes"
"encoding/json"
"fmt"

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

// StateMachine AWS CloudFormation Resource (AWS::Serverless::StateMachine)
// See: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-resource-statemachine.html
type StateMachine struct {

// Definition AWS CloudFormation Property
// Required: false
// See: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-resource-statemachine.html
Definition interface{} `json:"Definition,omitempty"`

// DefinitionSubstitutions AWS CloudFormation Property
// Required: false
// See: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-resource-statemachine.html
DefinitionSubstitutions map[string]string `json:"DefinitionSubstitutions,omitempty"`

// DefinitionUri AWS CloudFormation Property
// Required: false
// See: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-resource-statemachine.html
DefinitionUri *StateMachine_DefinitionUri `json:"DefinitionUri,omitempty"`

// Events AWS CloudFormation Property
// Required: false
// See: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-resource-statemachine.html
Events map[string]StateMachine_EventSource `json:"Events,omitempty"`

// Logging AWS CloudFormation Property
// Required: false
// See: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-resource-statemachine.html
Logging *StateMachine_LoggingConfiguration `json:"Logging,omitempty"`

// Name AWS CloudFormation Property
// Required: false
// See: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-resource-statemachine.html
Name string `json:"Name,omitempty"`

// Policies AWS CloudFormation Property
// Required: false
// See: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-resource-statemachine.html
Policies *StateMachine_Policies `json:"Policies,omitempty"`

// Role AWS CloudFormation Property
// Required: false
// See: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-resource-statemachine.html
Role string `json:"Role,omitempty"`

// Tags AWS CloudFormation Property
// Required: false
// See: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-resource-statemachine.html
Tags map[string]string `json:"Tags,omitempty"`

// Type AWS CloudFormation Property
// Required: false
// See: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-resource-statemachine.html
Type string `json:"Type,omitempty"`

// AWSCloudFormationDeletionPolicy represents a CloudFormation DeletionPolicy
AWSCloudFormationDeletionPolicy policies.DeletionPolicy `json:"-"`

// AWSCloudFormationUpdateReplacePolicy represents a CloudFormation UpdateReplacePolicy
AWSCloudFormationUpdateReplacePolicy policies.UpdateReplacePolicy `json:"-"`

// AWSCloudFormationDependsOn stores the logical ID of the resources to be created before this resource
AWSCloudFormationDependsOn []string `json:"-"`

// AWSCloudFormationMetadata stores structured data associated with this resource
AWSCloudFormationMetadata map[string]interface{} `json:"-"`

// AWSCloudFormationCondition stores the logical ID of the condition that must be satisfied for this resource to be created
AWSCloudFormationCondition string `json:"-"`
}

// AWSCloudFormationType returns the AWS CloudFormation resource type
func (r *StateMachine) AWSCloudFormationType() string {
return "AWS::Serverless::StateMachine"
}

// 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 StateMachine) MarshalJSON() ([]byte, error) {
type Properties StateMachine
return json.Marshal(&struct {
Type string
Properties Properties
DependsOn []string `json:"DependsOn,omitempty"`
Metadata map[string]interface{} `json:"Metadata,omitempty"`
DeletionPolicy policies.DeletionPolicy `json:"DeletionPolicy,omitempty"`
UpdateReplacePolicy policies.UpdateReplacePolicy `json:"UpdateReplacePolicy,omitempty"`
Condition string `json:"Condition,omitempty"`
}{
Type: r.AWSCloudFormationType(),
Properties: (Properties)(r),
DependsOn: r.AWSCloudFormationDependsOn,
Metadata: r.AWSCloudFormationMetadata,
DeletionPolicy: r.AWSCloudFormationDeletionPolicy,
UpdateReplacePolicy: r.AWSCloudFormationUpdateReplacePolicy,
Condition: r.AWSCloudFormationCondition,
})
}

// UnmarshalJSON is a custom JSON unmarshalling hook that strips the outer
// AWS CloudFormation resource object, and just keeps the 'Properties' field.
func (r *StateMachine) UnmarshalJSON(b []byte) error {
type Properties StateMachine
res := &struct {
Type string
Properties *Properties
DependsOn []string
Metadata map[string]interface{}
DeletionPolicy string
UpdateReplacePolicy string
Condition string
}{}

dec := json.NewDecoder(bytes.NewReader(b))
dec.DisallowUnknownFields() // Force error if unknown field is found

if err := dec.Decode(&res); err != nil {
fmt.Printf("ERROR: %s\n", err)
return err
}

// If the resource has no Properties set, it could be nil
if res.Properties != nil {
*r = StateMachine(*res.Properties)
}
if res.DependsOn != nil {
r.AWSCloudFormationDependsOn = res.DependsOn
}
if res.Metadata != nil {
r.AWSCloudFormationMetadata = res.Metadata
}
if res.DeletionPolicy != "" {
r.AWSCloudFormationDeletionPolicy = policies.DeletionPolicy(res.DeletionPolicy)
}
if res.UpdateReplacePolicy != "" {
r.AWSCloudFormationUpdateReplacePolicy = policies.UpdateReplacePolicy(res.UpdateReplacePolicy)
}
if res.Condition != "" {
r.AWSCloudFormationCondition = res.Condition
}
return nil
}
45 changes: 45 additions & 0 deletions cloudformation/serverless/aws-serverless-statemachine_apievent.go
@@ -0,0 +1,45 @@
package serverless

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

// StateMachine_ApiEvent AWS CloudFormation Resource (AWS::Serverless::StateMachine.ApiEvent)
// See: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#api
type StateMachine_ApiEvent struct {

// Method AWS CloudFormation Property
// Required: true
// See: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#api
Method string `json:"Method,omitempty"`

// Path AWS CloudFormation Property
// Required: true
// See: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#api
Path string `json:"Path,omitempty"`

// RestApiId AWS CloudFormation Property
// Required: false
// See: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#api
RestApiId string `json:"RestApiId,omitempty"`

// AWSCloudFormationDeletionPolicy represents a CloudFormation DeletionPolicy
AWSCloudFormationDeletionPolicy policies.DeletionPolicy `json:"-"`

// AWSCloudFormationUpdateReplacePolicy represents a CloudFormation UpdateReplacePolicy
AWSCloudFormationUpdateReplacePolicy policies.UpdateReplacePolicy `json:"-"`

// AWSCloudFormationDependsOn stores the logical ID of the resources to be created before this resource
AWSCloudFormationDependsOn []string `json:"-"`

// AWSCloudFormationMetadata stores structured data associated with this resource
AWSCloudFormationMetadata map[string]interface{} `json:"-"`

// AWSCloudFormationCondition stores the logical ID of the condition that must be satisfied for this resource to be created
AWSCloudFormationCondition string `json:"-"`
}

// AWSCloudFormationType returns the AWS CloudFormation resource type
func (r *StateMachine_ApiEvent) AWSCloudFormationType() string {
return "AWS::Serverless::StateMachine.ApiEvent"
}
@@ -0,0 +1,50 @@
package serverless

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

// StateMachine_CloudWatchEventEvent AWS CloudFormation Resource (AWS::Serverless::StateMachine.CloudWatchEventEvent)
// See: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-property-statemachine-cloudwatchevent.html
type StateMachine_CloudWatchEventEvent struct {

// EventBusName AWS CloudFormation Property
// Required: false
// See: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-property-statemachine-cloudwatchevent.html
EventBusName string `json:"EventBusName,omitempty"`

// Input AWS CloudFormation Property
// Required: false
// See: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-property-statemachine-cloudwatchevent.html
Input string `json:"Input,omitempty"`

// InputPath AWS CloudFormation Property
// Required: false
// See: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-property-statemachine-cloudwatchevent.html
InputPath string `json:"InputPath,omitempty"`

// Pattern AWS CloudFormation Property
// Required: true
// See: http://docs.aws.amazon.com/AmazonCloudWatch/latest/events/CloudWatchEventsandEventPatterns.html
Pattern interface{} `json:"Pattern,omitempty"`

// AWSCloudFormationDeletionPolicy represents a CloudFormation DeletionPolicy
AWSCloudFormationDeletionPolicy policies.DeletionPolicy `json:"-"`

// AWSCloudFormationUpdateReplacePolicy represents a CloudFormation UpdateReplacePolicy
AWSCloudFormationUpdateReplacePolicy policies.UpdateReplacePolicy `json:"-"`

// AWSCloudFormationDependsOn stores the logical ID of the resources to be created before this resource
AWSCloudFormationDependsOn []string `json:"-"`

// AWSCloudFormationMetadata stores structured data associated with this resource
AWSCloudFormationMetadata map[string]interface{} `json:"-"`

// AWSCloudFormationCondition stores the logical ID of the condition that must be satisfied for this resource to be created
AWSCloudFormationCondition string `json:"-"`
}

// AWSCloudFormationType returns the AWS CloudFormation resource type
func (r *StateMachine_CloudWatchEventEvent) AWSCloudFormationType() string {
return "AWS::Serverless::StateMachine.CloudWatchEventEvent"
}
@@ -0,0 +1,35 @@
package serverless

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

// StateMachine_CloudWatchLogsLogGroup AWS CloudFormation Resource (AWS::Serverless::StateMachine.CloudWatchLogsLogGroup)
// See: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-stepfunctions-statemachine-logdestination-cloudwatchlogsloggroup.html
type StateMachine_CloudWatchLogsLogGroup struct {

// LogGroupArn AWS CloudFormation Property
// Required: true
// See: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-stepfunctions-statemachine-logdestination-cloudwatchlogsloggroup.html
LogGroupArn string `json:"LogGroupArn,omitempty"`

// AWSCloudFormationDeletionPolicy represents a CloudFormation DeletionPolicy
AWSCloudFormationDeletionPolicy policies.DeletionPolicy `json:"-"`

// AWSCloudFormationUpdateReplacePolicy represents a CloudFormation UpdateReplacePolicy
AWSCloudFormationUpdateReplacePolicy policies.UpdateReplacePolicy `json:"-"`

// AWSCloudFormationDependsOn stores the logical ID of the resources to be created before this resource
AWSCloudFormationDependsOn []string `json:"-"`

// AWSCloudFormationMetadata stores structured data associated with this resource
AWSCloudFormationMetadata map[string]interface{} `json:"-"`

// AWSCloudFormationCondition stores the logical ID of the condition that must be satisfied for this resource to be created
AWSCloudFormationCondition string `json:"-"`
}

// AWSCloudFormationType returns the AWS CloudFormation resource type
func (r *StateMachine_CloudWatchLogsLogGroup) AWSCloudFormationType() string {
return "AWS::Serverless::StateMachine.CloudWatchLogsLogGroup"
}

0 comments on commit d2d23ca

Please sign in to comment.