Skip to content
This repository has been archived by the owner on Oct 17, 2024. It is now read-only.

Add SAM Global support #376

Merged
merged 23 commits into from
Jun 20, 2021
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
a8b0539
Initial commit--spec wired up
bryceitoc9 May 19, 2021
543a5c2
Globals?
bryceitoc9 May 21, 2021
d87213d
Codegen is working...need to figure out schemas
bryceitoc9 May 21, 2021
5398284
Valid Globals in SAM schema
bryceitoc9 May 21, 2021
6c447a4
Adding HttpApi to schema
bryceitoc9 May 24, 2021
532807f
Rebase Serverless
bryceitoc9 May 24, 2021
de02acb
Fixing existing test
bryceitoc9 May 24, 2021
067731a
Merge branch 'awslabs:master' into add-globals
bryceitoc9 May 25, 2021
6d4aafe
Globals test
bryceitoc9 May 26, 2021
24d5069
Merge branch 'add-globals' of https://github.com/bryceitoc9/goformati…
bryceitoc9 May 26, 2021
363aefa
Template parsing works
bryceitoc9 May 28, 2021
05a5750
Forgot to add template.go
bryceitoc9 Jun 1, 2021
970aedd
Error handling on global generation
bryceitoc9 Jun 3, 2021
b7590d7
Added cloudformation/global/*
PaulMaddox Jun 10, 2021
6cf6423
Updated template.Globals to be a value not pointer
PaulMaddox Jun 10, 2021
c19246a
cloudformation.NewTemplate() should instantiate globals
PaulMaddox Jun 10, 2021
bf7de1f
Added tests for Go->JSON and vice-versa to globals_test.go
PaulMaddox Jun 10, 2021
cece992
Removed test superceded by broader template based test
PaulMaddox Jun 10, 2021
0d2a333
Removed a test that would never fail
PaulMaddox Jun 10, 2021
420647e
BREAKING CHANGE: Removed previous globals impl
PaulMaddox Jun 10, 2021
a2f3094
Merging in CFN updates
PaulMaddox Jun 10, 2021
fcca193
Fixed conflicts in generated schemas
PaulMaddox Jun 10, 2021
546b099
Updated import paths to major version v5
PaulMaddox Jun 10, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ type CertificateAuthority_CrlConfiguration struct {
// See: http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-acmpca-certificateauthority-crlconfiguration.html#cfn-acmpca-certificateauthority-crlconfiguration-s3bucketname
S3BucketName string `json:"S3BucketName,omitempty"`

// S3ObjectAcl AWS CloudFormation Property
// Required: false
// See: http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-acmpca-certificateauthority-crlconfiguration.html#cfn-acmpca-certificateauthority-crlconfiguration-s3objectacl
S3ObjectAcl string `json:"S3ObjectAcl,omitempty"`

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

Expand Down
272 changes: 272 additions & 0 deletions cloudformation/all.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import (
"github.com/awslabs/goformation/v4/cloudformation/codestarnotifications"
"github.com/awslabs/goformation/v4/cloudformation/cognito"
"github.com/awslabs/goformation/v4/cloudformation/config"
"github.com/awslabs/goformation/v4/cloudformation/cur"
"github.com/awslabs/goformation/v4/cloudformation/customerprofiles"
"github.com/awslabs/goformation/v4/cloudformation/databrew"
"github.com/awslabs/goformation/v4/cloudformation/datapipeline"
Expand Down Expand Up @@ -106,6 +107,7 @@ import (
"github.com/awslabs/goformation/v4/cloudformation/lakeformation"
"github.com/awslabs/goformation/v4/cloudformation/lambda"
"github.com/awslabs/goformation/v4/cloudformation/licensemanager"
"github.com/awslabs/goformation/v4/cloudformation/location"
"github.com/awslabs/goformation/v4/cloudformation/logs"
"github.com/awslabs/goformation/v4/cloudformation/lookoutmetrics"
"github.com/awslabs/goformation/v4/cloudformation/lookoutvision"
Expand Down Expand Up @@ -163,6 +165,8 @@ import (
"github.com/awslabs/goformation/v4/cloudformation/wafv2"
"github.com/awslabs/goformation/v4/cloudformation/workspaces"
"github.com/awslabs/goformation/v4/cloudformation/xray"

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

// AllResources fetches an iterable map all CloudFormation and SAM resources
Expand Down Expand Up @@ -266,6 +270,7 @@ func AllResources() map[string]Resource {
"AWS::CE::AnomalyMonitor": &ce.AnomalyMonitor{},
"AWS::CE::AnomalySubscription": &ce.AnomalySubscription{},
"AWS::CE::CostCategory": &ce.CostCategory{},
"AWS::CUR::ReportDefinition": &cur.ReportDefinition{},
"AWS::Cassandra::Keyspace": &cassandra.Keyspace{},
"AWS::Cassandra::Table": &cassandra.Table{},
"AWS::CertificateManager::Account": &certificatemanager.Account{},
Expand Down Expand Up @@ -667,6 +672,12 @@ func AllResources() map[string]Resource {
"AWS::Lambda::Version": &lambda.Version{},
"AWS::LicenseManager::Grant": &licensemanager.Grant{},
"AWS::LicenseManager::License": &licensemanager.License{},
"AWS::Location::GeofenceCollection": &location.GeofenceCollection{},
"AWS::Location::Map": &location.Map{},
"AWS::Location::PlaceIndex": &location.PlaceIndex{},
"AWS::Location::RouteCalculator": &location.RouteCalculator{},
"AWS::Location::Tracker": &location.Tracker{},
"AWS::Location::TrackerConsumer": &location.TrackerConsumer{},
"AWS::Logs::Destination": &logs.Destination{},
"AWS::Logs::LogGroup": &logs.LogGroup{},
"AWS::Logs::LogStream": &logs.LogStream{},
Expand Down Expand Up @@ -869,6 +880,7 @@ func AllResources() map[string]Resource {
"AWS::Serverless::Api": &serverless.Api{},
"AWS::Serverless::Application": &serverless.Application{},
"AWS::Serverless::Function": &serverless.Function{},
"AWS::Serverless::HttpApi": &serverless.HttpApi{},
"AWS::Serverless::LayerVersion": &serverless.LayerVersion{},
"AWS::Serverless::SimpleTable": &serverless.SimpleTable{},
"AWS::Serverless::StateMachine": &serverless.StateMachine{},
Expand Down Expand Up @@ -934,6 +946,10 @@ func AllResources() map[string]Resource {
"AWS::XRay::Group": &xray.Group{},
"AWS::XRay::SamplingRule": &xray.SamplingRule{},
"Alexa::ASK::Skill": &ask.Skill{},
"Api": &global.Api{},
"Function": &global.Function{},
"HttpApi": &global.HttpApi{},
"SimpleTable": &global.SimpleTable{},
}
}

Expand Down Expand Up @@ -3289,6 +3305,30 @@ func (t *Template) GetCECostCategoryWithName(name string) (*ce.CostCategory, err
return nil, fmt.Errorf("resource %q of type ce.CostCategory not found", name)
}

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

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

// GetAllCassandraKeyspaceResources retrieves all cassandra.Keyspace items from an AWS CloudFormation template
func (t *Template) GetAllCassandraKeyspaceResources() map[string]*cassandra.Keyspace {
results := map[string]*cassandra.Keyspace{}
Expand Down Expand Up @@ -12913,6 +12953,150 @@ func (t *Template) GetLicenseManagerLicenseWithName(name string) (*licensemanage
return nil, fmt.Errorf("resource %q of type licensemanager.License not found", name)
}

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

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

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

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

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

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

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

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

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

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

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

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

// GetAllLogsDestinationResources retrieves all logs.Destination items from an AWS CloudFormation template
func (t *Template) GetAllLogsDestinationResources() map[string]*logs.Destination {
results := map[string]*logs.Destination{}
Expand Down Expand Up @@ -17761,6 +17945,30 @@ func (t *Template) GetServerlessFunctionWithName(name string) (*serverless.Funct
return nil, fmt.Errorf("resource %q of type serverless.Function not found", name)
}

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

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

// GetAllServerlessLayerVersionResources retrieves all serverless.LayerVersion items from an AWS CloudFormation template
func (t *Template) GetAllServerlessLayerVersionResources() map[string]*serverless.LayerVersion {
results := map[string]*serverless.LayerVersion{}
Expand Down Expand Up @@ -19320,3 +19528,67 @@ func (t *Template) GetASKSkillWithName(name string) (*ask.Skill, error) {
}
return nil, fmt.Errorf("resource %q of type ask.Skill not found", name)
}

// GetServerlessGlobalApiretrieves the template's Globals.Api items from an AWS SAM template.
// Returns an error if not found.
func (t *Template) GetServerlessGlobalApi() (*global.Api, error) {
globals := t.Globals
if globals == nil {
return nil, fmt.Errorf("globals not found")
}
if untyped, ok := globals["Api"]; ok {
switch resource := untyped.(type) {
case *global.Api:
return resource, nil
}
}
return nil, fmt.Errorf("resource of type global.Api not found")
}

// GetServerlessGlobalFunctionretrieves the template's Globals.Function items from an AWS SAM template.
// Returns an error if not found.
func (t *Template) GetServerlessGlobalFunction() (*global.Function, error) {
globals := t.Globals
if globals == nil {
return nil, fmt.Errorf("globals not found")
}
if untyped, ok := globals["Function"]; ok {
switch resource := untyped.(type) {
case *global.Function:
return resource, nil
}
}
return nil, fmt.Errorf("resource of type global.Function not found")
}

// GetServerlessGlobalHttpApiretrieves the template's Globals.HttpApi items from an AWS SAM template.
// Returns an error if not found.
func (t *Template) GetServerlessGlobalHttpApi() (*global.HttpApi, error) {
globals := t.Globals
if globals == nil {
return nil, fmt.Errorf("globals not found")
}
if untyped, ok := globals["HttpApi"]; ok {
switch resource := untyped.(type) {
case *global.HttpApi:
return resource, nil
}
}
return nil, fmt.Errorf("resource of type global.HttpApi not found")
}

// GetServerlessGlobalSimpleTableretrieves the template's Globals.SimpleTable items from an AWS SAM template.
// Returns an error if not found.
func (t *Template) GetServerlessGlobalSimpleTable() (*global.SimpleTable, error) {
globals := t.Globals
if globals == nil {
return nil, fmt.Errorf("globals not found")
}
if untyped, ok := globals["SimpleTable"]; ok {
switch resource := untyped.(type) {
case *global.SimpleTable:
return resource, nil
}
}
return nil, fmt.Errorf("resource of type global.SimpleTable not found")
}
2 changes: 1 addition & 1 deletion cloudformation/apigatewayv2/aws-apigatewayv2-authorizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ type Authorizer struct {
EnableSimpleResponses bool `json:"EnableSimpleResponses,omitempty"`

// IdentitySource AWS CloudFormation Property
// Required: true
// Required: false
// See: http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigatewayv2-authorizer.html#cfn-apigatewayv2-authorizer-identitysource
IdentitySource []string `json:"IdentitySource,omitempty"`

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ type Application_ComponentMonitoringSetting struct {
ComponentARN string `json:"ComponentARN,omitempty"`

// ComponentConfigurationMode AWS CloudFormation Property
// Required: false
// Required: true
// See: http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-applicationinsights-application-componentmonitoringsetting.html#cfn-applicationinsights-application-componentmonitoringsetting-componentconfigurationmode
ComponentConfigurationMode string `json:"ComponentConfigurationMode,omitempty"`

Expand All @@ -34,7 +34,7 @@ type Application_ComponentMonitoringSetting struct {
DefaultOverwriteComponentConfiguration *Application_ComponentConfiguration `json:"DefaultOverwriteComponentConfiguration,omitempty"`

// Tier AWS CloudFormation Property
// Required: false
// Required: true
// See: http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-applicationinsights-application-componentmonitoringsetting.html#cfn-applicationinsights-application-componentmonitoringsetting-tier
Tier string `json:"Tier,omitempty"`

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
type Function_FunctionMetadata struct {

// FunctionARN AWS CloudFormation Property
// Required: true
// Required: false
// See: http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-cloudfront-function-functionmetadata.html#cfn-cloudfront-function-functionmetadata-functionarn
FunctionARN string `json:"FunctionARN,omitempty"`

Expand Down
Loading