diff --git a/forgelib/deploy.go b/forgelib/deploy.go index 88d5e2a..fba2300 100644 --- a/forgelib/deploy.go +++ b/forgelib/deploy.go @@ -51,27 +51,29 @@ func (s *Stack) Deploy() (output DeployOut, err error) { } var inputParams []*cloudformation.Parameter + parsedParameters := []*cloudformation.Parameter{} if len(s.ParameterBodies) != 0 { - parameters, err := parseParameters(s.ParameterBodies) + parsedParameters, err = parseParameters(s.ParameterBodies) if err != nil { return output, err } + } - TEMPLATE_PARAMETERS: - for i := 0; i < len((*validationResult).Parameters); i++ { - for j := 0; j < len(parameters); j++ { - if *(*validationResult).Parameters[i].ParameterKey == *parameters[j].ParameterKey { - if v, ok := s.ParameterOverrides[*parameters[j].ParameterKey]; ok { - param := cloudformation.Parameter{ - ParameterKey: aws.String(*parameters[j].ParameterKey), - ParameterValue: aws.String(v), - } - inputParams = append(inputParams, ¶m) - } else { - inputParams = append(inputParams, parameters[j]) - } - continue TEMPLATE_PARAMETERS - } +TEMPLATE_PARAMETERS: + for i := 0; i < len((*validationResult).Parameters); i++ { + parameterKey := *(*validationResult).Parameters[i].ParameterKey + if v, ok := s.ParameterOverrides[parameterKey]; ok { + param := cloudformation.Parameter{ + ParameterKey: aws.String(parameterKey), + ParameterValue: aws.String(v), + } + inputParams = append(inputParams, ¶m) + continue TEMPLATE_PARAMETERS + } + for j := 0; j < len(parsedParameters); j++ { + if *parsedParameters[j].ParameterKey == parameterKey { + inputParams = append(inputParams, parsedParameters[j]) + continue TEMPLATE_PARAMETERS } } } diff --git a/forgelib/deploy_test.go b/forgelib/deploy_test.go index 3b5eeb2..acca069 100644 --- a/forgelib/deploy_test.go +++ b/forgelib/deploy_test.go @@ -868,7 +868,7 @@ func TestDeploy(t *testing.T) { }, }, }, - // Update stack with multiple parameter files + // Update stack with parameter overrides { newStackID: "test-stack/id0", parameterInput: []string{`{"One":"Foo","Two":"Foo"}`}, @@ -893,6 +893,46 @@ func TestDeploy(t *testing.T) { }, }, }, + // Create stack with only parameter overrides + { + newStackID: "test-stack/id0", + parameterOverrides: map[string]string{"Two": "Bar"}, + requiredParameters: []string{"Two"}, + stacks: []cloudformation.Stack{}, + expectStacks: []cloudformation.Stack{ + { + StackName: aws.String("test-stack"), + StackId: aws.String("test-stack/id0"), + StackStatus: aws.String(cloudformation.StackStatusCreateComplete), + Parameters: []*cloudformation.Parameter{ + {ParameterKey: aws.String("Two"), ParameterValue: aws.String("Bar")}, + }, + }, + }, + }, + // Update stack with parameter overrides + { + newStackID: "test-stack/id0", + parameterOverrides: map[string]string{"Two": "Bar"}, + requiredParameters: []string{"Two"}, + stacks: []cloudformation.Stack{ + { + StackName: aws.String("test-stack"), + StackId: aws.String("test-stack/id0"), + StackStatus: aws.String(cloudformation.StackStatusCreateComplete), + }, + }, + expectStacks: []cloudformation.Stack{ + { + StackName: aws.String("test-stack"), + StackId: aws.String("test-stack/id0"), + StackStatus: aws.String(cloudformation.StackStatusUpdateComplete), + Parameters: []*cloudformation.Parameter{ + {ParameterKey: aws.String("Two"), ParameterValue: aws.String("Bar")}, + }, + }, + }, + }, } oldCFNClient := cfnClient