From 4a8f9cda460fa95acc3de7832c861ff59e55f868 Mon Sep 17 00:00:00 2001 From: Efe Karakus Date: Wed, 27 Oct 2021 09:25:32 -0700 Subject: [PATCH] fix: use env accountID for SNS topic ARNs instead of app (#2956) Fixes #2949 By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the Apache 2.0 License. --- internal/pkg/cli/job_deploy.go | 4 ++-- internal/pkg/cli/svc_deploy.go | 4 ++-- internal/pkg/cli/svc_package.go | 2 +- internal/pkg/cli/svc_package_test.go | 4 +++- .../pkg/deploy/cloudformation/stack/workload.go | 14 ++++++++------ 5 files changed, 16 insertions(+), 12 deletions(-) diff --git a/internal/pkg/cli/job_deploy.go b/internal/pkg/cli/job_deploy.go index d8a262ac6f1..2f5fd92126e 100644 --- a/internal/pkg/cli/job_deploy.go +++ b/internal/pkg/cli/job_deploy.go @@ -323,7 +323,7 @@ func (o *deployJobOpts) runtimeConfig(addonsURL string) (*stack.RuntimeConfig, e AddonsTemplateURL: addonsURL, AdditionalTags: tags.Merge(o.targetApp.Tags, o.resourceTags), ServiceDiscoveryEndpoint: endpoint, - AccountID: o.targetApp.AccountID, + AccountID: o.targetEnvironment.AccountID, Region: o.targetEnvironment.Region, }, nil } @@ -348,7 +348,7 @@ func (o *deployJobOpts) runtimeConfig(addonsURL string) (*stack.RuntimeConfig, e AddonsTemplateURL: addonsURL, AdditionalTags: tags.Merge(o.targetApp.Tags, o.resourceTags), ServiceDiscoveryEndpoint: endpoint, - AccountID: o.targetApp.AccountID, + AccountID: o.targetEnvironment.AccountID, Region: o.targetEnvironment.Region, }, nil } diff --git a/internal/pkg/cli/svc_deploy.go b/internal/pkg/cli/svc_deploy.go index 15a03f0966d..1ea45be275b 100644 --- a/internal/pkg/cli/svc_deploy.go +++ b/internal/pkg/cli/svc_deploy.go @@ -486,7 +486,7 @@ func (o *deploySvcOpts) runtimeConfig(addonsURL string) (*stack.RuntimeConfig, e AddonsTemplateURL: addonsURL, AdditionalTags: tags.Merge(o.targetApp.Tags, o.resourceTags), ServiceDiscoveryEndpoint: endpoint, - AccountID: o.targetApp.AccountID, + AccountID: o.targetEnvironment.AccountID, Region: o.targetEnvironment.Region, }, nil } @@ -512,7 +512,7 @@ func (o *deploySvcOpts) runtimeConfig(addonsURL string) (*stack.RuntimeConfig, e Digest: o.imageDigest, }, ServiceDiscoveryEndpoint: endpoint, - AccountID: o.targetApp.AccountID, + AccountID: o.targetEnvironment.AccountID, Region: o.targetEnvironment.Region, }, nil } diff --git a/internal/pkg/cli/svc_package.go b/internal/pkg/cli/svc_package.go index f1aa818ad33..2625dda5483 100644 --- a/internal/pkg/cli/svc_package.go +++ b/internal/pkg/cli/svc_package.go @@ -390,7 +390,7 @@ func (o *packageSvcOpts) getSvcTemplates(env *config.Environment) (*svcCfnTempla rc := stack.RuntimeConfig{ AdditionalTags: app.Tags, ServiceDiscoveryEndpoint: endpoint, - AccountID: app.AccountID, + AccountID: env.AccountID, Region: env.Region, } diff --git a/internal/pkg/cli/svc_package_test.go b/internal/pkg/cli/svc_package_test.go index 2e93411e139..d0790dd8efe 100644 --- a/internal/pkg/cli/svc_package_test.go +++ b/internal/pkg/cli/svc_package_test.go @@ -300,10 +300,12 @@ count: 1` opts.newInterpolator = func(app, env string) interpolator { return mockItpl } - opts.stackSerializer = func(_ interface{}, _ *config.Environment, _ *config.Application, _ stack.RuntimeConfig) (stackSerializer, error) { + opts.stackSerializer = func(_ interface{}, _ *config.Environment, _ *config.Application, rc stack.RuntimeConfig) (stackSerializer, error) { mockStackSerializer := mocks.NewMockstackSerializer(ctrl) mockStackSerializer.EXPECT().Template().Return("mystack", nil) mockStackSerializer.EXPECT().SerializedParameters().Return("myparams", nil) + require.Equal(t, rc.AccountID, "1111", "ensure the environment's account is used while rendering stack") + require.Equal(t, rc.Region, "us-west-2") return mockStackSerializer, nil } opts.newEndpointGetter = func(app, env string) (endpointGetter, error) { diff --git a/internal/pkg/deploy/cloudformation/stack/workload.go b/internal/pkg/deploy/cloudformation/stack/workload.go index 30f9bbdc46f..00980216795 100644 --- a/internal/pkg/deploy/cloudformation/stack/workload.go +++ b/internal/pkg/deploy/cloudformation/stack/workload.go @@ -61,12 +61,14 @@ const ( // RuntimeConfig represents configuration that's defined outside of the manifest file // that is needed to create a CloudFormation stack. type RuntimeConfig struct { - Image *ECRImage // Optional. Image location in an ECR repository. - AddonsTemplateURL string // Optional. S3 object URL for the addons template. - AdditionalTags map[string]string // AdditionalTags are labels applied to resources in the workload stack. - ServiceDiscoveryEndpoint string // Endpoint for the service discovery namespace in the environment. - AccountID string // Account ID for constructing ARNs - Region string // Region for constructing ARNs + Image *ECRImage // Optional. Image location in an ECR repository. + AddonsTemplateURL string // Optional. S3 object URL for the addons template. + AdditionalTags map[string]string // AdditionalTags are labels applied to resources in the workload stack. + + // The target environment metadata. + ServiceDiscoveryEndpoint string // Endpoint for the service discovery namespace in the environment. + AccountID string + Region string } // ECRImage represents configuration about the pushed ECR image that is needed to