Skip to content

Commit

Permalink
chore(template): make StorageOpts transformers safe in templates (aws…
Browse files Browse the repository at this point in the history
…#1910)

Fixes an issue which arose in aws#1892 where templates fail to execute. 
<!-- Provide summary of changes -->

<!-- Issue number, if available. E.g. "Fixes #31", "Addresses #42, 77" -->

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.
  • Loading branch information
bvtujo committed Feb 5, 2021
1 parent e3456b5 commit a6d803e
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 3 deletions.
4 changes: 2 additions & 2 deletions internal/pkg/template/template_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func TestTemplate_ParseLoadBalancedWebService(t *testing.T) {
"renders a valid template with all storage options": {
opts: template.WorkloadOpts{
HTTPHealthCheck: defaultHttpHealthCheck,
Storage: template.StorageOpts{
Storage: &template.StorageOpts{
EFSPerms: []*template.EFSPermission{
{
AccessPointID: aws.String("ap-1234"),
Expand Down Expand Up @@ -136,7 +136,7 @@ func TestTemplate_ParseLoadBalancedWebService(t *testing.T) {
"renders a valid template with minimal storage options": {
opts: template.WorkloadOpts{
HTTPHealthCheck: defaultHttpHealthCheck,
Storage: template.StorageOpts{
Storage: &template.StorageOpts{
EFSPerms: []*template.EFSPermission{
{
FilesystemID: aws.String("fs-5678"),
Expand Down
4 changes: 4 additions & 0 deletions templates/workloads/jobs/scheduled-job/cf.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,13 @@ Resources:
{{include "envvars" . | indent 10}}
{{include "secrets" . | indent 10}}
{{include "logconfig" . | indent 10}}
{{- if .Storage}}
{{include "mount-points" . | indent 10}}
{{- end}}
{{include "sidecars" . | indent 8}}
{{- if .Storage}}
{{include "volumes" . | indent 6}}
{{- end}}
{{include "executionrole" . | indent 2}}

{{include "taskrole" . | indent 2}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ DesiredCount: !GetAtt DynamicDesiredCountAction.DesiredCount
{{- else }}
DesiredCount: !Ref TaskCount
{{- end}}
{{- if .Storage.Volumes}}
{{- if .Storage}}
PlatformVersion: 1.4.0
{{- end}}
DeploymentConfiguration:
Expand Down
2 changes: 2 additions & 0 deletions templates/workloads/partials/cf/taskrole.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ TaskRole:
StringEquals:
'iam:ResourceTag/copilot-application': !Sub '${AppName}'
'iam:ResourceTag/copilot-environment': !Sub '${EnvName}'
{{- if .Storage}}
{{- range $EFS := .Storage.EFSPerms}}
- PolicyName: 'GrantEFSAccess{{$EFS.FilesystemID}}'
PolicyDocument:
Expand All @@ -45,5 +46,6 @@ TaskRole:
{{- end}}
Resource:
- !Sub 'arn:aws:elasticfilesystem:${AWS::Region}:${AWS::AccountId}:file-system/{{$EFS.FilesystemID}}'
{{- end}}
{{- end -}}

4 changes: 4 additions & 0 deletions templates/workloads/services/backend/cf.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,13 @@ Resources:
StartPeriod: {{.HealthCheck.StartPeriod}}
Timeout: {{.HealthCheck.Timeout}}
{{- end}}
{{- if .Storage}}
{{include "mount-points" . | indent 10}}
{{- end}}
{{include "sidecars" . | indent 8}}
{{- if .Storage}}
{{include "volumes" . | indent 6}}
{{- end}}
{{include "executionrole" . | indent 2}}
{{include "taskrole" . | indent 2}}
{{include "servicediscovery" . | indent 2}}
Expand Down
4 changes: 4 additions & 0 deletions templates/workloads/services/lb-web/cf.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,13 @@ Resources:
Value: !GetAtt EnvControllerAction.PublicLoadBalancerDNSName
{{include "secrets" . | indent 10}}
{{include "logconfig" . | indent 10}}
{{- if .Storage}}
{{include "mount-points" . | indent 10}}
{{- end}}
{{include "sidecars" . | indent 8}}
{{if .Storage}}
{{include "volumes" . | indent 6}}
{{- end}}
{{include "executionrole" . | indent 2}}
{{include "taskrole" . | indent 2}}
{{include "servicediscovery" . | indent 2}}
Expand Down

0 comments on commit a6d803e

Please sign in to comment.