From 61e39b26ba93765a0d4b359f7ff866ab1a35b4e5 Mon Sep 17 00:00:00 2001 From: Wanxian Yang Date: Thu, 25 Aug 2022 12:00:21 -0700 Subject: [PATCH 1/5] transform service discovery endpoint parameter --- .../pkg/deploy/cloudformation/stack/env.go | 69 ++- .../deploy/cloudformation/stack/env_test.go | 404 +++++++++++++++++- 2 files changed, 453 insertions(+), 20 deletions(-) diff --git a/internal/pkg/deploy/cloudformation/stack/env.go b/internal/pkg/deploy/cloudformation/stack/env.go index 6ad3264b3db..14efd64f1dd 100644 --- a/internal/pkg/deploy/cloudformation/stack/env.go +++ b/internal/pkg/deploy/cloudformation/stack/env.go @@ -199,7 +199,7 @@ func (e *EnvStackConfig) Parameters() ([]*cloudformation.Parameter, error) { } // If we're creating a stack configuration for an existing environment stack, ensure the previous env controller // managed parameters are using the previous value. - return e.transformParameters(currParams, e.prevParams, transformEnvControllerParameters) + return e.transformParameters(currParams, e.prevParams, transformEnvControllerParameters, e.transformServiceDiscoveryEndpoint) } // SerializedParameters returns the CloudFormation stack's parameters serialized to a JSON document. @@ -220,20 +220,24 @@ func (e *EnvStackConfig) StackName() string { return NameForEnv(e.in.App.Name, e.in.Name) } +type transformParameterFunc func(new *cloudformation.Parameter, old *cloudformation.Parameter) *cloudformation.Parameter + // transformParameters removes or transforms each of the current parameters and does not add any new parameters. // This means that parameters that exist only in the old template are left out. -// The parameter`transform` is a function that transform a parameter, given its value in the new template and the old template. -// If `old` is `nil`, the parameter does not exist in the old template. -// `transform` should return `nil` if caller intends to delete the parameter. +// The parameter`transformFunc` are functions that transform a parameter, given its value in the new template and the old template. +// Each transform functions should keep the following in mind: +// 1. It should return `nil` if the parameter should be removed. +// 2. The transform functions are applied in a convolutional manner. +// 3. If the parameter `old` is passed in as `nil`, the parameter does not exist in the old template. func (e *EnvStackConfig) transformParameters( currParams []*cloudformation.Parameter, oldParams []*cloudformation.Parameter, - transform func(new cloudformation.Parameter, old *cloudformation.Parameter) *cloudformation.Parameter) ([]*cloudformation.Parameter, error) { + transformFunc ...transformParameterFunc) ([]*cloudformation.Parameter, error) { // Make a map out of `currParams` and out of `oldParams`. - curr := make(map[string]cloudformation.Parameter) + curr := make(map[string]*cloudformation.Parameter) for _, p := range currParams { - curr[aws.StringValue(p.ParameterKey)] = *p + curr[aws.StringValue(p.ParameterKey)] = p } old := make(map[string]*cloudformation.Parameter) for _, p := range oldParams { @@ -243,22 +247,23 @@ func (e *EnvStackConfig) transformParameters( // Remove or transform each of the current parameters. var params []*cloudformation.Parameter for k, p := range curr { - if transformed := transform(p, old[k]); transformed != nil { - params = append(params, transformed) + var currP = p + for _, transform := range transformFunc { + currP = transform(currP, old[k]) + } + if currP != nil { + params = append(params, currP) } } return params, nil } -// transformEnvControllerParameters transforms a parameter such that it uses its previous value if: -// 1. The parameter exists in the old template. -// 2. The parameter is env-controller managed. -// Otherwise, it returns the parameter untouched. -func transformEnvControllerParameters(new cloudformation.Parameter, old *cloudformation.Parameter) *cloudformation.Parameter { - if old == nil { // The ParamKey doesn't exist in the old stack, use the new value. - return &new +// transformEnvControllerParameters transforms an env-controller managed parameter. +// If the parameter exists in the old template, it uses its previous value. Otherwise, it returns its new default value. +func transformEnvControllerParameters(new *cloudformation.Parameter, old *cloudformation.Parameter) *cloudformation.Parameter { + if new == nil { + return nil } - var ( isEnvControllerManaged = make(map[string]struct{}) exists = struct{}{} @@ -267,7 +272,35 @@ func transformEnvControllerParameters(new cloudformation.Parameter, old *cloudfo isEnvControllerManaged[f] = exists } if _, ok := isEnvControllerManaged[aws.StringValue(new.ParameterKey)]; !ok { - return &new + return new + } + if old == nil { // The EnvController-managed parameter doesn't exist in the old stack. Use the new value. + return new + } + return &cloudformation.Parameter{ + ParameterKey: new.ParameterKey, + + // Ideally, we would set `UsePreviousValue: true` unfortunately CodePipeline template config does not support it. + // https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/continuous-delivery-codepipeline-cfn-artifacts.html#w2ab1c21c15c15 + ParameterValue: old.ParameterValue, + } +} + +// transformServiceDiscoveryEndpoint transforms the service discovery endpoint parameter. +// If the parameter exists in the old template, it uses its previous value. +// Otherwise, it uses a default value of `.local`. +func (e *EnvStackConfig) transformServiceDiscoveryEndpoint(new *cloudformation.Parameter, old *cloudformation.Parameter) *cloudformation.Parameter { + if new == nil { + return nil + } + if aws.StringValue(new.ParameterKey) != EnvParamServiceDiscoveryEndpoint { + return new + } + if old == nil { + return &cloudformation.Parameter{ + ParameterKey: new.ParameterKey, + ParameterValue: aws.String(fmt.Sprintf(`%s.local`, e.in.App.Name)), + } } return &cloudformation.Parameter{ ParameterKey: new.ParameterKey, diff --git a/internal/pkg/deploy/cloudformation/stack/env_test.go b/internal/pkg/deploy/cloudformation/stack/env_test.go index d99a5ffef99..97c3680d701 100644 --- a/internal/pkg/deploy/cloudformation/stack/env_test.go +++ b/internal/pkg/deploy/cloudformation/stack/env_test.go @@ -279,6 +279,114 @@ func TestEnv_Parameters(t *testing.T) { }, }, }, + "should use default value for new EnvControllerParameters": { + input: deploymentInput, + oldParams: []*cloudformation.Parameter{ + { + ParameterKey: aws.String(EnvParamALBWorkloadsKey), + ParameterValue: aws.String("frontend,backend"), + }, + { + ParameterKey: aws.String(envParamNATWorkloadsKey), + ParameterValue: aws.String("backend"), + }, + { + ParameterKey: aws.String(EnvParamAliasesKey), + ParameterValue: aws.String(""), + }, + { + ParameterKey: aws.String(envParamEFSWorkloadsKey), + ParameterValue: aws.String(""), + }, + { + ParameterKey: aws.String(envParamAppNameKey), + ParameterValue: aws.String(deploymentInput.App.Name), + }, + { + ParameterKey: aws.String(envParamEnvNameKey), + ParameterValue: aws.String(deploymentInput.Name), + }, + { + ParameterKey: aws.String(envParamToolsAccountPrincipalKey), + ParameterValue: aws.String(deploymentInput.App.AccountPrincipalARN), + }, + { + ParameterKey: aws.String(envParamAppDNSKey), + ParameterValue: aws.String(""), + }, + { + ParameterKey: aws.String(envParamAppDNSDelegationRoleKey), + ParameterValue: aws.String(""), + }, + { + ParameterKey: aws.String(EnvParamServiceDiscoveryEndpoint), + ParameterValue: aws.String("mockenv.mockapp.local"), + }, + { + ParameterKey: aws.String(envParamCreateHTTPSListenerKey), + ParameterValue: aws.String("false"), + }, + { + ParameterKey: aws.String(envParamCreateInternalHTTPSListenerKey), + ParameterValue: aws.String("false"), + }, + }, + + want: []*cloudformation.Parameter{ + { + ParameterKey: aws.String(envParamAppNameKey), + ParameterValue: aws.String(deploymentInput.App.Name), + }, + { + ParameterKey: aws.String(envParamEnvNameKey), + ParameterValue: aws.String(deploymentInput.Name), + }, + { + ParameterKey: aws.String(envParamToolsAccountPrincipalKey), + ParameterValue: aws.String(deploymentInput.App.AccountPrincipalARN), + }, + { + ParameterKey: aws.String(envParamAppDNSKey), + ParameterValue: aws.String(""), + }, + { + ParameterKey: aws.String(envParamAppDNSDelegationRoleKey), + ParameterValue: aws.String(""), + }, + { + ParameterKey: aws.String(EnvParamAliasesKey), + ParameterValue: aws.String(""), + }, + { + ParameterKey: aws.String(EnvParamALBWorkloadsKey), + ParameterValue: aws.String("frontend,backend"), + }, + { + ParameterKey: aws.String(envParamInternalALBWorkloadsKey), + ParameterValue: aws.String(""), + }, + { + ParameterKey: aws.String(envParamEFSWorkloadsKey), + ParameterValue: aws.String(""), + }, + { + ParameterKey: aws.String(envParamNATWorkloadsKey), + ParameterValue: aws.String("backend"), + }, + { + ParameterKey: aws.String(EnvParamServiceDiscoveryEndpoint), + ParameterValue: aws.String("mockenv.mockapp.local"), + }, + { + ParameterKey: aws.String(envParamCreateHTTPSListenerKey), + ParameterValue: aws.String("false"), + }, + { + ParameterKey: aws.String(envParamCreateInternalHTTPSListenerKey), + ParameterValue: aws.String("false"), + }, + }, + }, "should retain the values from EnvControllerParameters": { input: deploymentInput, oldParams: []*cloudformation.Parameter{ @@ -290,6 +398,50 @@ func TestEnv_Parameters(t *testing.T) { ParameterKey: aws.String(envParamNATWorkloadsKey), ParameterValue: aws.String("backend"), }, + { + ParameterKey: aws.String(EnvParamAliasesKey), + ParameterValue: aws.String(""), + }, + { + ParameterKey: aws.String(envParamInternalALBWorkloadsKey), + ParameterValue: aws.String(""), + }, + { + ParameterKey: aws.String(envParamEFSWorkloadsKey), + ParameterValue: aws.String(""), + }, + { + ParameterKey: aws.String(envParamAppNameKey), + ParameterValue: aws.String(deploymentInput.App.Name), + }, + { + ParameterKey: aws.String(envParamEnvNameKey), + ParameterValue: aws.String(deploymentInput.Name), + }, + { + ParameterKey: aws.String(envParamToolsAccountPrincipalKey), + ParameterValue: aws.String(deploymentInput.App.AccountPrincipalARN), + }, + { + ParameterKey: aws.String(envParamAppDNSKey), + ParameterValue: aws.String(""), + }, + { + ParameterKey: aws.String(envParamAppDNSDelegationRoleKey), + ParameterValue: aws.String(""), + }, + { + ParameterKey: aws.String(EnvParamServiceDiscoveryEndpoint), + ParameterValue: aws.String("mockenv.mockapp.local"), + }, + { + ParameterKey: aws.String(envParamCreateHTTPSListenerKey), + ParameterValue: aws.String("false"), + }, + { + ParameterKey: aws.String(envParamCreateInternalHTTPSListenerKey), + ParameterValue: aws.String("false"), + }, }, want: []*cloudformation.Parameter{ @@ -335,7 +487,7 @@ func TestEnv_Parameters(t *testing.T) { }, { ParameterKey: aws.String(EnvParamServiceDiscoveryEndpoint), - ParameterValue: aws.String("env.project.local"), + ParameterValue: aws.String("mockenv.mockapp.local"), }, { ParameterKey: aws.String(envParamCreateHTTPSListenerKey), @@ -353,6 +505,58 @@ func TestEnv_Parameters(t *testing.T) { { ParameterKey: aws.String("deprecated"), }, + { + ParameterKey: aws.String(EnvParamALBWorkloadsKey), + ParameterValue: aws.String(""), + }, + { + ParameterKey: aws.String(envParamNATWorkloadsKey), + ParameterValue: aws.String(""), + }, + { + ParameterKey: aws.String(EnvParamAliasesKey), + ParameterValue: aws.String(""), + }, + { + ParameterKey: aws.String(envParamInternalALBWorkloadsKey), + ParameterValue: aws.String(""), + }, + { + ParameterKey: aws.String(envParamEFSWorkloadsKey), + ParameterValue: aws.String(""), + }, + { + ParameterKey: aws.String(envParamAppNameKey), + ParameterValue: aws.String(deploymentInput.App.Name), + }, + { + ParameterKey: aws.String(envParamEnvNameKey), + ParameterValue: aws.String(deploymentInput.Name), + }, + { + ParameterKey: aws.String(envParamToolsAccountPrincipalKey), + ParameterValue: aws.String(deploymentInput.App.AccountPrincipalARN), + }, + { + ParameterKey: aws.String(envParamAppDNSKey), + ParameterValue: aws.String(""), + }, + { + ParameterKey: aws.String(envParamAppDNSDelegationRoleKey), + ParameterValue: aws.String(""), + }, + { + ParameterKey: aws.String(EnvParamServiceDiscoveryEndpoint), + ParameterValue: aws.String("mockenv.mockapp.local"), + }, + { + ParameterKey: aws.String(envParamCreateHTTPSListenerKey), + ParameterValue: aws.String("false"), + }, + { + ParameterKey: aws.String(envParamCreateInternalHTTPSListenerKey), + ParameterValue: aws.String("false"), + }, }, want: []*cloudformation.Parameter{ @@ -398,7 +602,203 @@ func TestEnv_Parameters(t *testing.T) { }, { ParameterKey: aws.String(EnvParamServiceDiscoveryEndpoint), - ParameterValue: aws.String("env.project.local"), + ParameterValue: aws.String("mockenv.mockapp.local"), + }, + { + ParameterKey: aws.String(envParamCreateHTTPSListenerKey), + ParameterValue: aws.String("false"), + }, + { + ParameterKey: aws.String(envParamCreateInternalHTTPSListenerKey), + ParameterValue: aws.String("false"), + }, + }, + }, + "should reuse old service discovery endpoint value": { + input: deploymentInput, + oldParams: []*cloudformation.Parameter{ + { + ParameterKey: aws.String(EnvParamServiceDiscoveryEndpoint), + ParameterValue: aws.String("app.local"), + }, + { + ParameterKey: aws.String(EnvParamALBWorkloadsKey), + ParameterValue: aws.String(""), + }, + { + ParameterKey: aws.String(envParamNATWorkloadsKey), + ParameterValue: aws.String(""), + }, + { + ParameterKey: aws.String(EnvParamAliasesKey), + ParameterValue: aws.String(""), + }, + { + ParameterKey: aws.String(envParamInternalALBWorkloadsKey), + ParameterValue: aws.String(""), + }, + { + ParameterKey: aws.String(envParamEFSWorkloadsKey), + ParameterValue: aws.String(""), + }, + { + ParameterKey: aws.String(envParamAppNameKey), + ParameterValue: aws.String(deploymentInput.App.Name), + }, + { + ParameterKey: aws.String(envParamEnvNameKey), + ParameterValue: aws.String(deploymentInput.Name), + }, + { + ParameterKey: aws.String(envParamToolsAccountPrincipalKey), + ParameterValue: aws.String(deploymentInput.App.AccountPrincipalARN), + }, + { + ParameterKey: aws.String(envParamAppDNSKey), + ParameterValue: aws.String(""), + }, + { + ParameterKey: aws.String(envParamAppDNSDelegationRoleKey), + ParameterValue: aws.String(""), + }, + { + ParameterKey: aws.String(envParamCreateHTTPSListenerKey), + ParameterValue: aws.String("false"), + }, + { + ParameterKey: aws.String(envParamCreateInternalHTTPSListenerKey), + ParameterValue: aws.String("false"), + }, + }, + + want: []*cloudformation.Parameter{ + { + ParameterKey: aws.String(envParamAppNameKey), + ParameterValue: aws.String(deploymentInput.App.Name), + }, + { + ParameterKey: aws.String(envParamEnvNameKey), + ParameterValue: aws.String(deploymentInput.Name), + }, + { + ParameterKey: aws.String(envParamToolsAccountPrincipalKey), + ParameterValue: aws.String(deploymentInput.App.AccountPrincipalARN), + }, + { + ParameterKey: aws.String(envParamAppDNSKey), + ParameterValue: aws.String(""), + }, + { + ParameterKey: aws.String(envParamAppDNSDelegationRoleKey), + ParameterValue: aws.String(""), + }, + { + ParameterKey: aws.String(EnvParamAliasesKey), + ParameterValue: aws.String(""), + }, + { + ParameterKey: aws.String(EnvParamALBWorkloadsKey), + ParameterValue: aws.String(""), + }, + { + ParameterKey: aws.String(envParamInternalALBWorkloadsKey), + ParameterValue: aws.String(""), + }, + { + ParameterKey: aws.String(envParamEFSWorkloadsKey), + ParameterValue: aws.String(""), + }, + { + ParameterKey: aws.String(envParamNATWorkloadsKey), + ParameterValue: aws.String(""), + }, + { + ParameterKey: aws.String(EnvParamServiceDiscoveryEndpoint), + ParameterValue: aws.String("app.local"), + }, + { + ParameterKey: aws.String(envParamCreateHTTPSListenerKey), + ParameterValue: aws.String("false"), + }, + { + ParameterKey: aws.String(envParamCreateInternalHTTPSListenerKey), + ParameterValue: aws.String("false"), + }, + }, + }, + "should use app.local endpoint service discovery endpoint if it is a new parameter": { + input: deploymentInput, + oldParams: []*cloudformation.Parameter{ + { + ParameterKey: aws.String(EnvParamALBWorkloadsKey), + ParameterValue: aws.String(""), + }, + { + ParameterKey: aws.String(envParamAppNameKey), + ParameterValue: aws.String(deploymentInput.App.Name), + }, + { + ParameterKey: aws.String(envParamEnvNameKey), + ParameterValue: aws.String(deploymentInput.Name), + }, + { + ParameterKey: aws.String(envParamToolsAccountPrincipalKey), + ParameterValue: aws.String(deploymentInput.App.AccountPrincipalARN), + }, + { + ParameterKey: aws.String(envParamAppDNSKey), + ParameterValue: aws.String(""), + }, + { + ParameterKey: aws.String(envParamAppDNSDelegationRoleKey), + ParameterValue: aws.String(""), + }, + }, + + want: []*cloudformation.Parameter{ + { + ParameterKey: aws.String(envParamAppNameKey), + ParameterValue: aws.String(deploymentInput.App.Name), + }, + { + ParameterKey: aws.String(envParamEnvNameKey), + ParameterValue: aws.String(deploymentInput.Name), + }, + { + ParameterKey: aws.String(envParamToolsAccountPrincipalKey), + ParameterValue: aws.String(deploymentInput.App.AccountPrincipalARN), + }, + { + ParameterKey: aws.String(envParamAppDNSKey), + ParameterValue: aws.String(""), + }, + { + ParameterKey: aws.String(envParamAppDNSDelegationRoleKey), + ParameterValue: aws.String(""), + }, + { + ParameterKey: aws.String(EnvParamAliasesKey), + ParameterValue: aws.String(""), + }, + { + ParameterKey: aws.String(EnvParamALBWorkloadsKey), + ParameterValue: aws.String(""), + }, + { + ParameterKey: aws.String(envParamInternalALBWorkloadsKey), + ParameterValue: aws.String(""), + }, + { + ParameterKey: aws.String(envParamEFSWorkloadsKey), + ParameterValue: aws.String(""), + }, + { + ParameterKey: aws.String(envParamNATWorkloadsKey), + ParameterValue: aws.String(""), + }, + { + ParameterKey: aws.String(EnvParamServiceDiscoveryEndpoint), + ParameterValue: aws.String("project.local"), }, { ParameterKey: aws.String(envParamCreateHTTPSListenerKey), From f538acc91d13a11f0878eea49d1d4f03773a40cd Mon Sep 17 00:00:00 2001 From: Wanxian Yang Date: Thu, 25 Aug 2022 14:08:29 -0700 Subject: [PATCH 2/5] addr fb: callapse params of the same data type --- internal/pkg/deploy/cloudformation/stack/env.go | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/internal/pkg/deploy/cloudformation/stack/env.go b/internal/pkg/deploy/cloudformation/stack/env.go index 14efd64f1dd..368b1acbb62 100644 --- a/internal/pkg/deploy/cloudformation/stack/env.go +++ b/internal/pkg/deploy/cloudformation/stack/env.go @@ -220,7 +220,7 @@ func (e *EnvStackConfig) StackName() string { return NameForEnv(e.in.App.Name, e.in.Name) } -type transformParameterFunc func(new *cloudformation.Parameter, old *cloudformation.Parameter) *cloudformation.Parameter +type transformParameterFunc func(new, old *cloudformation.Parameter) *cloudformation.Parameter // transformParameters removes or transforms each of the current parameters and does not add any new parameters. // This means that parameters that exist only in the old template are left out. @@ -229,10 +229,7 @@ type transformParameterFunc func(new *cloudformation.Parameter, old *cloudformat // 1. It should return `nil` if the parameter should be removed. // 2. The transform functions are applied in a convolutional manner. // 3. If the parameter `old` is passed in as `nil`, the parameter does not exist in the old template. -func (e *EnvStackConfig) transformParameters( - currParams []*cloudformation.Parameter, - oldParams []*cloudformation.Parameter, - transformFunc ...transformParameterFunc) ([]*cloudformation.Parameter, error) { +func (e *EnvStackConfig) transformParameters(currParams, oldParams []*cloudformation.Parameter, transformFunc ...transformParameterFunc) ([]*cloudformation.Parameter, error) { // Make a map out of `currParams` and out of `oldParams`. curr := make(map[string]*cloudformation.Parameter) @@ -260,7 +257,7 @@ func (e *EnvStackConfig) transformParameters( // transformEnvControllerParameters transforms an env-controller managed parameter. // If the parameter exists in the old template, it uses its previous value. Otherwise, it returns its new default value. -func transformEnvControllerParameters(new *cloudformation.Parameter, old *cloudformation.Parameter) *cloudformation.Parameter { +func transformEnvControllerParameters(new, old *cloudformation.Parameter) *cloudformation.Parameter { if new == nil { return nil } @@ -289,7 +286,7 @@ func transformEnvControllerParameters(new *cloudformation.Parameter, old *cloudf // transformServiceDiscoveryEndpoint transforms the service discovery endpoint parameter. // If the parameter exists in the old template, it uses its previous value. // Otherwise, it uses a default value of `.local`. -func (e *EnvStackConfig) transformServiceDiscoveryEndpoint(new *cloudformation.Parameter, old *cloudformation.Parameter) *cloudformation.Parameter { +func (e *EnvStackConfig) transformServiceDiscoveryEndpoint(new, old *cloudformation.Parameter) *cloudformation.Parameter { if new == nil { return nil } From 0b40c80a11f6ce5d5c7780f842588828359be7c9 Mon Sep 17 00:00:00 2001 From: Wanxian Yang Date: Thu, 25 Aug 2022 14:11:12 -0700 Subject: [PATCH 3/5] addr fb: short declaration; anonymize "exists" var --- internal/pkg/deploy/cloudformation/stack/env.go | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/internal/pkg/deploy/cloudformation/stack/env.go b/internal/pkg/deploy/cloudformation/stack/env.go index 368b1acbb62..b4eb403dbf4 100644 --- a/internal/pkg/deploy/cloudformation/stack/env.go +++ b/internal/pkg/deploy/cloudformation/stack/env.go @@ -244,7 +244,7 @@ func (e *EnvStackConfig) transformParameters(currParams, oldParams []*cloudforma // Remove or transform each of the current parameters. var params []*cloudformation.Parameter for k, p := range curr { - var currP = p + currP := p for _, transform := range transformFunc { currP = transform(currP, old[k]) } @@ -261,12 +261,9 @@ func transformEnvControllerParameters(new, old *cloudformation.Parameter) *cloud if new == nil { return nil } - var ( - isEnvControllerManaged = make(map[string]struct{}) - exists = struct{}{} - ) + isEnvControllerManaged := make(map[string]struct{}) for _, f := range template.AvailableEnvFeatures() { - isEnvControllerManaged[f] = exists + isEnvControllerManaged[f] = struct{}{} } if _, ok := isEnvControllerManaged[aws.StringValue(new.ParameterKey)]; !ok { return new From c698e90813286eebdc5eef5368c2db53526543d1 Mon Sep 17 00:00:00 2001 From: Wanxian Yang Date: Fri, 26 Aug 2022 14:34:30 -0700 Subject: [PATCH 4/5] addr fb: return old param --- .../pkg/deploy/cloudformation/stack/env.go | 22 +++++++------------ 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/internal/pkg/deploy/cloudformation/stack/env.go b/internal/pkg/deploy/cloudformation/stack/env.go index b4eb403dbf4..0c0d65adcf3 100644 --- a/internal/pkg/deploy/cloudformation/stack/env.go +++ b/internal/pkg/deploy/cloudformation/stack/env.go @@ -271,13 +271,10 @@ func transformEnvControllerParameters(new, old *cloudformation.Parameter) *cloud if old == nil { // The EnvController-managed parameter doesn't exist in the old stack. Use the new value. return new } - return &cloudformation.Parameter{ - ParameterKey: new.ParameterKey, - - // Ideally, we would set `UsePreviousValue: true` unfortunately CodePipeline template config does not support it. - // https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/continuous-delivery-codepipeline-cfn-artifacts.html#w2ab1c21c15c15 - ParameterValue: old.ParameterValue, - } + // Ideally, we would return `&cloudformation.Parameter{ ParameterKey: new.ParameterKey, UsePreviousValue: true}`. + // Unfortunately CodePipeline template config does not support it. + // https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/continuous-delivery-codepipeline-cfn-artifacts.html#w2ab1c21c15c15 + return old } // transformServiceDiscoveryEndpoint transforms the service discovery endpoint parameter. @@ -296,13 +293,10 @@ func (e *EnvStackConfig) transformServiceDiscoveryEndpoint(new, old *cloudformat ParameterValue: aws.String(fmt.Sprintf(`%s.local`, e.in.App.Name)), } } - return &cloudformation.Parameter{ - ParameterKey: new.ParameterKey, - - // Ideally, we would set `UsePreviousValue: true` unfortunately CodePipeline template config does not support it. - // https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/continuous-delivery-codepipeline-cfn-artifacts.html#w2ab1c21c15c15 - ParameterValue: old.ParameterValue, - } + // Ideally, we would return `&cloudformation.Parameter{ ParameterKey: new.ParameterKey, UsePreviousValue: true}`. + // Unfortunately CodePipeline template config does not support it. + // https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/continuous-delivery-codepipeline-cfn-artifacts.html#w2ab1c21c15c15 + return old } // NewBootstrapEnvStackConfig sets up a BootstrapEnvStackConfig struct. From 541e9e85e0750bd83c3dd0a48312d25229830f51 Mon Sep 17 00:00:00 2001 From: Wanxian Yang Date: Mon, 29 Aug 2022 09:47:08 -0700 Subject: [PATCH 5/5] addr fb: update comment to include the assumption --- internal/pkg/deploy/cloudformation/stack/env.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/internal/pkg/deploy/cloudformation/stack/env.go b/internal/pkg/deploy/cloudformation/stack/env.go index 0c0d65adcf3..53c4d7a8d05 100644 --- a/internal/pkg/deploy/cloudformation/stack/env.go +++ b/internal/pkg/deploy/cloudformation/stack/env.go @@ -256,7 +256,8 @@ func (e *EnvStackConfig) transformParameters(currParams, oldParams []*cloudforma } // transformEnvControllerParameters transforms an env-controller managed parameter. -// If the parameter exists in the old template, it uses its previous value. Otherwise, it returns its new default value. +// If the parameter exists in the old template, it returns the old parameter assuming that old.ParameterKey = new.ParameterKey. +// Otherwise, it returns its new default value. func transformEnvControllerParameters(new, old *cloudformation.Parameter) *cloudformation.Parameter { if new == nil { return nil