Skip to content

Commit

Permalink
Allow overrides when parameter key is not present elsewhere
Browse files Browse the repository at this point in the history
  • Loading branch information
Nathan Dines committed May 6, 2018
1 parent adebb4a commit 6234bd1
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 17 deletions.
34 changes: 18 additions & 16 deletions forgelib/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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, &param)
} 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, &param)
continue TEMPLATE_PARAMETERS
}
for j := 0; j < len(parsedParameters); j++ {
if *parsedParameters[j].ParameterKey == parameterKey {
inputParams = append(inputParams, parsedParameters[j])
continue TEMPLATE_PARAMETERS
}
}
}
Expand Down
42 changes: 41 additions & 1 deletion forgelib/deploy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"}`},
Expand All @@ -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
Expand Down

0 comments on commit 6234bd1

Please sign in to comment.