Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(templates): render service cfn templates when addons have no outputs #1075

Merged
merged 1 commit into from
Jun 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 63 additions & 0 deletions internal/pkg/template/template_integration_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// +build integration

// Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

package template_test

import (
"testing"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/cloudformation"
"github.com/aws/copilot-cli/internal/pkg/aws/session"
"github.com/aws/copilot-cli/internal/pkg/template"
"github.com/stretchr/testify/require"
)

func TestTemplate_ParseLoadBalancedWebService(t *testing.T) {
testCases := map[string]struct {
opts template.ServiceOpts
}{
"renders a valid template by default": {
opts: template.ServiceOpts{},
},
"renders a valid template with addons with no outputs": {
opts: template.ServiceOpts{
NestedStack: &template.ServiceNestedStackOpts{
StackName: "AddonsStack",
},
},
},
"renders a valid template with addons with outputs": {
opts: template.ServiceOpts{
NestedStack: &template.ServiceNestedStackOpts{
StackName: "AddonsStack",
VariableOutputs: []string{"TableName"},
SecretOutputs: []string{"TablePassword"},
PolicyOutputs: []string{"TablePolicy"},
},
},
},
}

for name, tc := range testCases {
t.Run(name, func(t *testing.T) {
// GIVEN
sess, err := session.NewProvider().Default()
require.NoError(t, err)
cfn := cloudformation.New(sess)
tpl := template.New()

// WHEN
content, err := tpl.ParseLoadBalancedWebService(tc.opts)
require.NoError(t, err)

// THEN
_, err = cfn.ValidateTemplate(&cloudformation.ValidateTemplateInput{
TemplateBody: aws.String(content.String()),
})
require.NoError(t, err, content.String())
})
}
}
4 changes: 2 additions & 2 deletions templates/services/common/cf/taskrole.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
TaskRole:
Type: AWS::IAM::Role
Properties:{{if .NestedStack}}{{$stackName := .NestedStack.StackName}}
Properties:{{if .NestedStack}}{{$stackName := .NestedStack.StackName}}{{if gt (len .NestedStack.PolicyOutputs) 0}}
ManagedPolicyArns:{{range $managedPolicy := .NestedStack.PolicyOutputs}}
- Fn::GetAtt: [{{$stackName}}, Outputs.{{$managedPolicy}}]{{end}}{{end}}
- Fn::GetAtt: [{{$stackName}}, Outputs.{{$managedPolicy}}]{{end}}{{end}}{{end}}
AssumeRolePolicyDocument:
Statement:
- Effect: Allow
Expand Down