From a6f60d5178ed7b16539e2da68afb3dec295a67e6 Mon Sep 17 00:00:00 2001 From: Owen Kelly Date: Wed, 13 Feb 2019 12:01:16 +1100 Subject: [PATCH] fix regression that caused outputs to stop generating (#140) * fix regression that caused outputs to stop generating * updated test --- internal/cloudformation/template.go | 9 +- .../cloudformation/template_parsers_test.go | 243 +++++++++++++++++- internal/tasks/upsert.go | 15 +- 3 files changed, 245 insertions(+), 22 deletions(-) diff --git a/internal/cloudformation/template.go b/internal/cloudformation/template.go index 8a6dff5a..6e76a6fa 100644 --- a/internal/cloudformation/template.go +++ b/internal/cloudformation/template.go @@ -177,14 +177,6 @@ func processParsers( resources, types.TemplateObject{templateResourceName: templateResource}, ) - } else if strings.HasPrefix(templateResource.Type, "AWS::") { - resources = mergeTemplatesWithError( - templateResourceName, - "aws-resource", - templateResource.Type, - resources, - types.TemplateObject{templateResourceName: templateResource}, - ) } else { // This is a resource // Check if there is a parser for this resource parser, ok := parserFuncs[templateResource.Type] @@ -198,6 +190,7 @@ func processParsers( resources, types.TemplateObject{templateResourceName: templateResource}, ) + continue } diff --git a/internal/cloudformation/template_parsers_test.go b/internal/cloudformation/template_parsers_test.go index 24b3dd07..47936168 100644 --- a/internal/cloudformation/template_parsers_test.go +++ b/internal/cloudformation/template_parsers_test.go @@ -14,12 +14,10 @@ import ( var testYaml = `AWSTemplateFormatVersion: "2010-09-09" Description: A Demo Template for testing Kombustion - Parameters: Environment: Type: String Default: UnknownEnvironment - Resources: MyDemoLogGroup: Type: "AWS::Logs::LogGroup" @@ -60,8 +58,96 @@ func TestGenerateYamlTemplate(t *testing.T) { ObjectStore: objectStore, Filename: "test.yaml", }, - output: YamlCloudformation{AWSTemplateFormatVersion: "2010-09-09", Description: "A Demo Template for testing Kombustion", Metadata: types.TemplateObject{}, Parameters: types.TemplateObject{"Environment": map[interface{}]interface{}{"Type": "String", "Default": "UnknownEnvironment"}}, Mappings: types.TemplateObject{}, Conditions: types.TemplateObject{}, Transform: types.TemplateObject{}, Resources: types.TemplateObject{"MyDemoLogGroup4": types.CfResource{Type: "AWS::Logs::LogGroup", Properties: map[interface{}]interface{}{"LogGroupName": map[string]interface{}{"Fn::Join": []interface{}{"-", []interface{}{"MyDemoLogGroup4", map[string]interface{}{"Ref": "Environment"}}}}, "RetentionInDays": 1}, Condition: interface{}(nil), Metadata: interface{}(nil), DependsOn: interface{}(nil), CreationPolicy: interface{}(nil), UpdatePolicy: interface{}(nil), DeletionPolicy: interface{}(nil)}, "MyDemoLogGroup": types.CfResource{Type: "AWS::Logs::LogGroup", Properties: map[interface{}]interface{}{"LogGroupName": map[string]interface{}{"Fn::Join": []interface{}{"-", []interface{}{"MyDemoLogGroup1", map[string]interface{}{"Ref": "Environment"}}}}, "RetentionInDays": 1}, Condition: interface{}(nil), Metadata: interface{}(nil), DependsOn: interface{}(nil), CreationPolicy: interface{}(nil), UpdatePolicy: interface{}(nil), DeletionPolicy: interface{}(nil)}, "MyDemoLogGroup2": types.CfResource{Type: "AWS::Logs::LogGroup", Properties: map[interface{}]interface{}{"RetentionInDays": 1, "LogGroupName": map[string]interface{}{"Fn::Join": []interface{}{"-", []interface{}{"MyDemoLogGroup2", map[string]interface{}{"Ref": "Environment"}}}}}, Condition: interface{}(nil), Metadata: interface{}(nil), DependsOn: interface{}(nil), CreationPolicy: interface{}(nil), UpdatePolicy: interface{}(nil), DeletionPolicy: interface{}(nil)}, "MyDemoLogGroup3": types.CfResource{Type: "AWS::Logs::LogGroup", Properties: map[interface{}]interface{}{"LogGroupName": map[string]interface{}{"Fn::Join": []interface{}{"-", []interface{}{"MyDemoLogGroup3", map[string]interface{}{"Ref": "Environment"}}}}, "RetentionInDays": 1}, Condition: interface{}(nil), Metadata: interface{}(nil), DependsOn: interface{}(nil), CreationPolicy: interface{}(nil), UpdatePolicy: interface{}(nil), DeletionPolicy: interface{}(nil)}}, Outputs: types.TemplateObject{}}, - err: nil, + output: YamlCloudformation{ + AWSTemplateFormatVersion: "2010-09-09", + Description: "A Demo Template for testing Kombustion", + Metadata: types.TemplateObject{}, + Parameters: types.TemplateObject{ + "Environment": map[interface{}]interface{}{ + "Type": "String", + "Default": "UnknownEnvironment", + }, + }, + Mappings: types.TemplateObject{}, + Conditions: types.TemplateObject{}, + Transform: types.TemplateObject{}, + Resources: types.TemplateObject{ + "MyDemoLogGroup4": resources.LogsLogGroup{ + Type: "AWS::Logs::LogGroup", + Properties: resources.LogsLogGroupProperties{ + LogGroupName: map[interface{}]interface{}{ + "Fn::Join": []interface{}{ + "-", + []interface{}{ + "MyDemoLogGroup4", + map[interface{}]interface{}{ + "Ref": "Environment", + }, + }, + }, + }, + RetentionInDays: 1, + }, + Condition: interface{}(nil), + Metadata: interface{}(nil), + DependsOn: interface{}(nil)}, + "MyDemoLogGroup": resources.LogsLogGroup{ + Type: "AWS::Logs::LogGroup", + Properties: resources.LogsLogGroupProperties{ + LogGroupName: map[interface{}]interface{}{ + "Fn::Join": []interface{}{ + "-", []interface{}{ + "MyDemoLogGroup1", + map[interface{}]interface{}{ + "Ref": "Environment", + }, + }, + }, + }, + RetentionInDays: 1, + }, + Condition: interface{}(nil), + Metadata: interface{}(nil), + DependsOn: interface{}(nil)}, "MyDemoLogGroup2": resources.LogsLogGroup{ + Type: "AWS::Logs::LogGroup", Properties: resources.LogsLogGroupProperties{ + LogGroupName: map[interface{}]interface{}{ + "Fn::Join": []interface{}{ + "-", []interface{}{ + "MyDemoLogGroup2", + map[interface{}]interface{}{ + "Ref": "Environment", + }, + }, + }, + }, + RetentionInDays: 1, + }, + Condition: interface{}(nil), + Metadata: interface{}(nil), + DependsOn: interface{}(nil)}, "MyDemoLogGroup3": resources.LogsLogGroup{ + Type: "AWS::Logs::LogGroup", + Properties: resources.LogsLogGroupProperties{ + LogGroupName: map[interface{}]interface{}{ + "Fn::Join": []interface{}{ + "-", + []interface{}{ + "MyDemoLogGroup3", + map[interface{}]interface{}{ + "Ref": "Environment", + }, + }, + }, + }, + RetentionInDays: 1, + }, + Condition: interface{}(nil), + Metadata: interface{}(nil), + DependsOn: interface{}(nil), + }, + }, + Outputs: types.TemplateObject{}, + }, + err: nil, }, { input: GenerateParams{ @@ -69,8 +155,135 @@ func TestGenerateYamlTemplate(t *testing.T) { Filename: "test.yaml", GenerateDefaultOutputs: true, }, - output: YamlCloudformation{AWSTemplateFormatVersion: "2010-09-09", Description: "A Demo Template for testing Kombustion", Metadata: types.TemplateObject{}, Parameters: types.TemplateObject{"Environment": map[interface{}]interface{}{"Default": "UnknownEnvironment", "Type": "String"}}, Mappings: types.TemplateObject{}, Conditions: types.TemplateObject{}, Transform: types.TemplateObject{}, Resources: types.TemplateObject{"MyDemoLogGroup4": types.CfResource{Type: "AWS::Logs::LogGroup", Properties: map[interface{}]interface{}{"LogGroupName": map[string]interface{}{"Fn::Join": []interface{}{"-", []interface{}{"MyDemoLogGroup4", map[string]interface{}{"Ref": "Environment"}}}}, "RetentionInDays": 1}, Condition: interface{}(nil), Metadata: interface{}(nil), DependsOn: interface{}(nil), CreationPolicy: interface{}(nil), UpdatePolicy: interface{}(nil), DeletionPolicy: interface{}(nil)}, "MyDemoLogGroup": types.CfResource{Type: "AWS::Logs::LogGroup", Properties: map[interface{}]interface{}{"LogGroupName": map[string]interface{}{"Fn::Join": []interface{}{"-", []interface{}{"MyDemoLogGroup1", map[string]interface{}{"Ref": "Environment"}}}}, "RetentionInDays": 1}, Condition: interface{}(nil), Metadata: interface{}(nil), DependsOn: interface{}(nil), CreationPolicy: interface{}(nil), UpdatePolicy: interface{}(nil), DeletionPolicy: interface{}(nil)}, "MyDemoLogGroup2": types.CfResource{Type: "AWS::Logs::LogGroup", Properties: map[interface{}]interface{}{"LogGroupName": map[string]interface{}{"Fn::Join": []interface{}{"-", []interface{}{"MyDemoLogGroup2", map[string]interface{}{"Ref": "Environment"}}}}, "RetentionInDays": 1}, Condition: interface{}(nil), Metadata: interface{}(nil), DependsOn: interface{}(nil), CreationPolicy: interface{}(nil), UpdatePolicy: interface{}(nil), DeletionPolicy: interface{}(nil)}, "MyDemoLogGroup3": types.CfResource{Type: "AWS::Logs::LogGroup", Properties: map[interface{}]interface{}{"LogGroupName": map[string]interface{}{"Fn::Join": []interface{}{"-", []interface{}{"MyDemoLogGroup3", map[string]interface{}{"Ref": "Environment"}}}}, "RetentionInDays": 1}, Condition: interface{}(nil), Metadata: interface{}(nil), DependsOn: interface{}(nil), CreationPolicy: interface{}(nil), UpdatePolicy: interface{}(nil), DeletionPolicy: interface{}(nil)}}, Outputs: types.TemplateObject{}}, - err: nil, + output: YamlCloudformation{ + AWSTemplateFormatVersion: "2010-09-09", + Description: "A Demo Template for testing Kombustion", + Metadata: types.TemplateObject{}, + Parameters: types.TemplateObject{ + "Environment": map[interface{}]interface{}{ + "Type": "String", "Default": "UnknownEnvironment", + }, + }, + Mappings: types.TemplateObject{}, + Conditions: types.TemplateObject{}, + Transform: types.TemplateObject{}, + Resources: types.TemplateObject{ + "MyDemoLogGroup2": resources.LogsLogGroup{ + Type: "AWS::Logs::LogGroup", + Properties: resources.LogsLogGroupProperties{ + LogGroupName: map[interface{}]interface{}{ + "Fn::Join": []interface{}{"-", []interface{}{ + "MyDemoLogGroup2", map[interface{}]interface{}{ + "Ref": "Environment", + }, + }, + }, + }, + RetentionInDays: 1, + }, + Condition: interface{}(nil), + Metadata: interface{}(nil), + DependsOn: interface{}(nil), + }, + "MyDemoLogGroup3": resources.LogsLogGroup{ + Type: "AWS::Logs::LogGroup", + Properties: resources.LogsLogGroupProperties{ + LogGroupName: map[interface{}]interface{}{ + "Fn::Join": []interface{}{"-", []interface{}{ + "MyDemoLogGroup3", + map[interface{}]interface{}{ + "Ref": "Environment", + }, + }, + }, + }, + RetentionInDays: 1, + }, + Condition: interface{}(nil), + Metadata: interface{}(nil), + DependsOn: interface{}(nil), + }, + "MyDemoLogGroup4": resources.LogsLogGroup{ + Type: "AWS::Logs::LogGroup", + Properties: resources.LogsLogGroupProperties{ + LogGroupName: map[interface{}]interface{}{ + "Fn::Join": []interface{}{ + "-", + []interface{}{ + "MyDemoLogGroup4", + map[interface{}]interface{}{"Ref": "Environment"}, + }, + }, + }, + RetentionInDays: 1, + }, + Condition: interface{}(nil), + Metadata: interface{}(nil), + DependsOn: interface{}(nil)}, + "MyDemoLogGroup": resources.LogsLogGroup{ + Type: "AWS::Logs::LogGroup", + Properties: resources.LogsLogGroupProperties{ + LogGroupName: map[interface{}]interface{}{ + "Fn::Join": []interface{}{"-", + []interface{}{"MyDemoLogGroup1", + map[interface{}]interface{}{"Ref": "Environment"}, + }, + }, + }, + RetentionInDays: 1, + }, + Condition: interface{}(nil), + Metadata: interface{}(nil), + DependsOn: interface{}(nil), + }, + }, + Outputs: types.TemplateObject{ + "MyDemoLogGroup2": types.TemplateObject{ + "Description": "MyDemoLogGroup2 Object", + "Value": map[string]interface{}{ + "Ref": "MyDemoLogGroup2", + }, + "Export": map[string]interface{}{ + "Name": map[string]interface{}{ + "Fn::Sub": "${AWS::StackName}-LogsLogGroup-MyDemoLogGroup2", + }, + }, + }, + "MyDemoLogGroup3": types.TemplateObject{ + "Description": "MyDemoLogGroup3 Object", + "Value": map[string]interface{}{ + "Ref": "MyDemoLogGroup3", + }, + "Export": map[string]interface{}{ + "Name": map[string]interface{}{ + "Fn::Sub": "${AWS::StackName}-LogsLogGroup-MyDemoLogGroup3", + }, + }, + }, + "MyDemoLogGroup4": types.TemplateObject{ + "Export": map[string]interface{}{ + "Name": map[string]interface{}{ + "Fn::Sub": "${AWS::StackName}-LogsLogGroup-MyDemoLogGroup4", + }, + }, "Description": "MyDemoLogGroup4 Object", + "Value": map[string]interface{}{ + "Ref": "MyDemoLogGroup4", + }, + }, + "MyDemoLogGroup": types.TemplateObject{ + "Description": "MyDemoLogGroup Object", + "Value": map[string]interface{}{ + "Ref": "MyDemoLogGroup", + }, + "Export": map[string]interface{}{ + "Name": map[string]interface{}{ + "Fn::Sub": "${AWS::StackName}-LogsLogGroup-MyDemoLogGroup", + }, + }, + }, + }, + }, + err: nil, }, } @@ -146,8 +359,22 @@ func TestProcessParsers(t *testing.T) { mappings: types.TemplateObject{}, outputs: types.TemplateObject{}, parameters: types.TemplateObject{}, - resources: types.TemplateObject{"Test": types.CfResource{Type: "AWS::Logs::LogsGroup", Properties: map[string]interface{}{"LogGroupName": "TestLogGroup"}, Condition: map[string]interface{}{"ConditionName": "ConditionValue"}, Metadata: map[string]interface{}{"MetadataName": "MetadataValue"}, DependsOn: []interface{}{"OtherResource"}, CreationPolicy: interface{}(nil), UpdatePolicy: interface{}(nil), DeletionPolicy: interface{}(nil)}}, - transform: types.TemplateObject{}, + resources: types.TemplateObject{ + "Test": resources.LogsLogGroup{ + Type: "AWS::Logs::LogsGroup", + Properties: resources.LogsLogGroupProperties{ + LogGroupName: "TestLogGroup", + RetentionInDays: interface{}(nil)}, + Condition: map[interface{}]interface{}{ + "ConditionName": "ConditionValue", + }, + Metadata: map[interface{}]interface{}{ + "MetadataName": "MetadataValue", + }, + DependsOn: []interface{}{"OtherResource"}, + }, + }, + transform: types.TemplateObject{}, }, }, { diff --git a/internal/tasks/upsert.go b/internal/tasks/upsert.go index 732fa7e0..870264d9 100644 --- a/internal/tasks/upsert.go +++ b/internal/tasks/upsert.go @@ -3,6 +3,10 @@ package tasks import ( "fmt" + "github.com/aws/aws-sdk-go/aws" + awsCF "github.com/aws/aws-sdk-go/service/cloudformation" + "github.com/urfave/cli" + printer "github.com/KablamoOSS/go-cli-printer" "github.com/KablamoOSS/kombustion/internal/cloudformation" "github.com/KablamoOSS/kombustion/internal/cloudformation/tasks" @@ -10,9 +14,6 @@ import ( "github.com/KablamoOSS/kombustion/internal/manifest" "github.com/KablamoOSS/kombustion/internal/plugins" "github.com/KablamoOSS/kombustion/internal/plugins/lock" - "github.com/aws/aws-sdk-go/aws" - awsCF "github.com/aws/aws-sdk-go/service/cloudformation" - "github.com/urfave/cli" ) // UpsertFlags for kombustion upsert @@ -192,14 +193,16 @@ func upsert( printer.Progress("Generating template") // Template generation parameters generateParams := cloudformation.GenerateParams{ - ObjectStore: objectStore, - Filename: templatePath, - Env: envName, + ObjectStore: objectStore, + Filename: templatePath, + Env: envName, GenerateDefaultOutputs: generateDefaultOutputs || manifestFile.GenerateDefaultOutputs, ParamMap: paramMap, Plugins: loadedPlugins, } + printer.Stepf("Generate Default Outputs: %t", generateParams.GenerateDefaultOutputs) + // CloudFormation Stack parameters var parameters []*awsCF.Parameter