Skip to content

Commit

Permalink
feat(parser): Add support for Conditions (awslabs#260)
Browse files Browse the repository at this point in the history
* Add support for Conditions

* Run 'go generate'

* Fix unit tests
  • Loading branch information
JerzyLa committed Jan 29, 2020
1 parent a7d5c92 commit 1b00f17
Show file tree
Hide file tree
Showing 1,813 changed files with 11,125 additions and 96 deletions.
9 changes: 9 additions & 0 deletions cloudformation/accessanalyzer/aws-accessanalyzer-analyzer.go
Expand Up @@ -41,6 +41,9 @@ type Analyzer struct {

// 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
Expand All @@ -58,12 +61,14 @@ func (r Analyzer) MarshalJSON() ([]byte, error) {
DependsOn []string `json:"DependsOn,omitempty"`
Metadata map[string]interface{} `json:"Metadata,omitempty"`
DeletionPolicy policies.DeletionPolicy `json:"DeletionPolicy,omitempty"`
Condition string `json:"Condition,omitempty"`
}{
Type: r.AWSCloudFormationType(),
Properties: (Properties)(r),
DependsOn: r.AWSCloudFormationDependsOn,
Metadata: r.AWSCloudFormationMetadata,
DeletionPolicy: r.AWSCloudFormationDeletionPolicy,
Condition: r.AWSCloudFormationCondition,
})
}

Expand All @@ -77,6 +82,7 @@ func (r *Analyzer) UnmarshalJSON(b []byte) error {
DependsOn []string
Metadata map[string]interface{}
DeletionPolicy string
Condition string
}{}

dec := json.NewDecoder(bytes.NewReader(b))
Expand All @@ -100,5 +106,8 @@ func (r *Analyzer) UnmarshalJSON(b []byte) error {
if res.DeletionPolicy != "" {
r.AWSCloudFormationDeletionPolicy = policies.DeletionPolicy(res.DeletionPolicy)
}
if res.Condition != "" {
r.AWSCloudFormationCondition = res.Condition
}
return nil
}
Expand Up @@ -26,6 +26,9 @@ type Analyzer_ArchiveRule struct {

// 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
Expand Down
Expand Up @@ -41,6 +41,9 @@ type Analyzer_Filter struct {

// 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
Expand Down
50 changes: 50 additions & 0 deletions cloudformation/all.go
Expand Up @@ -200,6 +200,7 @@ func AllResources() map[string]Resource {
"AWS::CloudWatch::Dashboard": &cloudwatch.Dashboard{},
"AWS::CloudWatch::InsightRule": &cloudwatch.InsightRule{},
"AWS::CodeBuild::Project": &codebuild.Project{},
"AWS::CodeBuild::ReportGroup": &codebuild.ReportGroup{},
"AWS::CodeBuild::SourceCredential": &codebuild.SourceCredential{},
"AWS::CodeCommit::Repository": &codecommit.Repository{},
"AWS::CodeDeploy::Application": &codedeploy.Application{},
Expand Down Expand Up @@ -259,6 +260,7 @@ func AllResources() map[string]Resource {
"AWS::EC2::EIPAssociation": &ec2.EIPAssociation{},
"AWS::EC2::EgressOnlyInternetGateway": &ec2.EgressOnlyInternetGateway{},
"AWS::EC2::FlowLog": &ec2.FlowLog{},
"AWS::EC2::GatewayRouteTableAssociation": &ec2.GatewayRouteTableAssociation{},
"AWS::EC2::Host": &ec2.Host{},
"AWS::EC2::Instance": &ec2.Instance{},
"AWS::EC2::InternetGateway": &ec2.InternetGateway{},
Expand Down Expand Up @@ -2718,6 +2720,30 @@ func (t *Template) GetCodeBuildProjectWithName(name string) (*codebuild.Project,
return nil, fmt.Errorf("resource %q of type codebuild.Project not found", name)
}

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

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

// GetAllCodeBuildSourceCredentialResources retrieves all codebuild.SourceCredential items from an AWS CloudFormation template
func (t *Template) GetAllCodeBuildSourceCredentialResources() map[string]*codebuild.SourceCredential {
results := map[string]*codebuild.SourceCredential{}
Expand Down Expand Up @@ -4134,6 +4160,30 @@ func (t *Template) GetEC2FlowLogWithName(name string) (*ec2.FlowLog, error) {
return nil, fmt.Errorf("resource %q of type ec2.FlowLog not found", name)
}

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

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

// GetAllEC2HostResources retrieves all ec2.Host items from an AWS CloudFormation template
func (t *Template) GetAllEC2HostResources() map[string]*ec2.Host {
results := map[string]*ec2.Host{}
Expand Down
9 changes: 9 additions & 0 deletions cloudformation/amazonmq/aws-amazonmq-broker.go
Expand Up @@ -100,6 +100,9 @@ type Broker struct {

// 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
Expand All @@ -117,12 +120,14 @@ func (r Broker) MarshalJSON() ([]byte, error) {
DependsOn []string `json:"DependsOn,omitempty"`
Metadata map[string]interface{} `json:"Metadata,omitempty"`
DeletionPolicy policies.DeletionPolicy `json:"DeletionPolicy,omitempty"`
Condition string `json:"Condition,omitempty"`
}{
Type: r.AWSCloudFormationType(),
Properties: (Properties)(r),
DependsOn: r.AWSCloudFormationDependsOn,
Metadata: r.AWSCloudFormationMetadata,
DeletionPolicy: r.AWSCloudFormationDeletionPolicy,
Condition: r.AWSCloudFormationCondition,
})
}

Expand All @@ -136,6 +141,7 @@ func (r *Broker) UnmarshalJSON(b []byte) error {
DependsOn []string
Metadata map[string]interface{}
DeletionPolicy string
Condition string
}{}

dec := json.NewDecoder(bytes.NewReader(b))
Expand All @@ -159,5 +165,8 @@ func (r *Broker) UnmarshalJSON(b []byte) error {
if res.DeletionPolicy != "" {
r.AWSCloudFormationDeletionPolicy = policies.DeletionPolicy(res.DeletionPolicy)
}
if res.Condition != "" {
r.AWSCloudFormationCondition = res.Condition
}
return nil
}
Expand Up @@ -26,6 +26,9 @@ type Broker_ConfigurationId struct {

// 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
Expand Down
Expand Up @@ -26,6 +26,9 @@ type Broker_EncryptionOptions struct {

// 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
Expand Down
3 changes: 3 additions & 0 deletions cloudformation/amazonmq/aws-amazonmq-broker_loglist.go
Expand Up @@ -26,6 +26,9 @@ type Broker_LogList struct {

// 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
Expand Down
Expand Up @@ -31,6 +31,9 @@ type Broker_MaintenanceWindow struct {

// 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
Expand Down
3 changes: 3 additions & 0 deletions cloudformation/amazonmq/aws-amazonmq-broker_tagsentry.go
Expand Up @@ -26,6 +26,9 @@ type Broker_TagsEntry struct {

// 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
Expand Down
3 changes: 3 additions & 0 deletions cloudformation/amazonmq/aws-amazonmq-broker_user.go
Expand Up @@ -36,6 +36,9 @@ type Broker_User struct {

// 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
Expand Down
9 changes: 9 additions & 0 deletions cloudformation/amazonmq/aws-amazonmq-configuration.go
Expand Up @@ -50,6 +50,9 @@ type Configuration struct {

// 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
Expand All @@ -67,12 +70,14 @@ func (r Configuration) MarshalJSON() ([]byte, error) {
DependsOn []string `json:"DependsOn,omitempty"`
Metadata map[string]interface{} `json:"Metadata,omitempty"`
DeletionPolicy policies.DeletionPolicy `json:"DeletionPolicy,omitempty"`
Condition string `json:"Condition,omitempty"`
}{
Type: r.AWSCloudFormationType(),
Properties: (Properties)(r),
DependsOn: r.AWSCloudFormationDependsOn,
Metadata: r.AWSCloudFormationMetadata,
DeletionPolicy: r.AWSCloudFormationDeletionPolicy,
Condition: r.AWSCloudFormationCondition,
})
}

Expand All @@ -86,6 +91,7 @@ func (r *Configuration) UnmarshalJSON(b []byte) error {
DependsOn []string
Metadata map[string]interface{}
DeletionPolicy string
Condition string
}{}

dec := json.NewDecoder(bytes.NewReader(b))
Expand All @@ -109,5 +115,8 @@ func (r *Configuration) UnmarshalJSON(b []byte) error {
if res.DeletionPolicy != "" {
r.AWSCloudFormationDeletionPolicy = policies.DeletionPolicy(res.DeletionPolicy)
}
if res.Condition != "" {
r.AWSCloudFormationCondition = res.Condition
}
return nil
}
Expand Up @@ -26,6 +26,9 @@ type Configuration_TagsEntry struct {

// 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
Expand Down
Expand Up @@ -30,6 +30,9 @@ type ConfigurationAssociation struct {

// 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
Expand All @@ -47,12 +50,14 @@ func (r ConfigurationAssociation) MarshalJSON() ([]byte, error) {
DependsOn []string `json:"DependsOn,omitempty"`
Metadata map[string]interface{} `json:"Metadata,omitempty"`
DeletionPolicy policies.DeletionPolicy `json:"DeletionPolicy,omitempty"`
Condition string `json:"Condition,omitempty"`
}{
Type: r.AWSCloudFormationType(),
Properties: (Properties)(r),
DependsOn: r.AWSCloudFormationDependsOn,
Metadata: r.AWSCloudFormationMetadata,
DeletionPolicy: r.AWSCloudFormationDeletionPolicy,
Condition: r.AWSCloudFormationCondition,
})
}

Expand All @@ -66,6 +71,7 @@ func (r *ConfigurationAssociation) UnmarshalJSON(b []byte) error {
DependsOn []string
Metadata map[string]interface{}
DeletionPolicy string
Condition string
}{}

dec := json.NewDecoder(bytes.NewReader(b))
Expand All @@ -89,5 +95,8 @@ func (r *ConfigurationAssociation) UnmarshalJSON(b []byte) error {
if res.DeletionPolicy != "" {
r.AWSCloudFormationDeletionPolicy = policies.DeletionPolicy(res.DeletionPolicy)
}
if res.Condition != "" {
r.AWSCloudFormationCondition = res.Condition
}
return nil
}
Expand Up @@ -26,6 +26,9 @@ type ConfigurationAssociation_ConfigurationId struct {

// 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
Expand Down
9 changes: 9 additions & 0 deletions cloudformation/amplify/aws-amplify-app.go
Expand Up @@ -81,6 +81,9 @@ type App struct {

// 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
Expand All @@ -98,12 +101,14 @@ func (r App) MarshalJSON() ([]byte, error) {
DependsOn []string `json:"DependsOn,omitempty"`
Metadata map[string]interface{} `json:"Metadata,omitempty"`
DeletionPolicy policies.DeletionPolicy `json:"DeletionPolicy,omitempty"`
Condition string `json:"Condition,omitempty"`
}{
Type: r.AWSCloudFormationType(),
Properties: (Properties)(r),
DependsOn: r.AWSCloudFormationDependsOn,
Metadata: r.AWSCloudFormationMetadata,
DeletionPolicy: r.AWSCloudFormationDeletionPolicy,
Condition: r.AWSCloudFormationCondition,
})
}

Expand All @@ -117,6 +122,7 @@ func (r *App) UnmarshalJSON(b []byte) error {
DependsOn []string
Metadata map[string]interface{}
DeletionPolicy string
Condition string
}{}

dec := json.NewDecoder(bytes.NewReader(b))
Expand All @@ -140,5 +146,8 @@ func (r *App) UnmarshalJSON(b []byte) error {
if res.DeletionPolicy != "" {
r.AWSCloudFormationDeletionPolicy = policies.DeletionPolicy(res.DeletionPolicy)
}
if res.Condition != "" {
r.AWSCloudFormationCondition = res.Condition
}
return nil
}
Expand Up @@ -61,6 +61,9 @@ type App_AutoBranchCreationConfig struct {

// 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
Expand Down

0 comments on commit 1b00f17

Please sign in to comment.