Skip to content

Commit e0faee5

Browse files
committed
Add support to define policy for timer and if it is not defined inherit policies from service
1 parent d93b3da commit e0faee5

File tree

3 files changed

+37
-4
lines changed

3 files changed

+37
-4
lines changed

pkg/manifest/timer.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@ import (
88
type Timer struct {
99
Name string `yaml:"-"`
1010

11-
Command string `yaml:"command"`
12-
Schedule string `yaml:"schedule"`
13-
Service string `yaml:"service"`
11+
Command string `yaml:"command"`
12+
Schedule string `yaml:"schedule"`
13+
Service string `yaml:"service"`
14+
Policies []string `yaml:"policies,omitempty"`
1415
}
1516

1617
type Timers []Timer

provider/aws/formation/app.json.tmpl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -571,6 +571,11 @@
571571
"LogDriver": { "Ref": "LogDriver" },
572572
"LogGroup": { "Fn::If": [ "EnableCloudWatch", { "Ref": "LogGroup" }, { "Ref": "AWS::NoValue" } ] },
573573
"Memory": { "Fn::Select": [ 2, { "Ref": "{{ upper .Service }}Formation" } ] },
574+
{{ if gt (len .Policies) 0 }}
575+
"Policies": "{{ join .Policies "," }}",
576+
{{ else }}
577+
"Policies": "{{ join ($.Manifest.Service .Service).Policies "," }}",
578+
{{ end }}
574579
"Rack": { "Ref": "Rack" },
575580
"RackUrl": { "Ref": "RackUrl" },
576581
"Registry": { "Ref": "Registry" },

provider/aws/formation/timer.json.tmpl

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
{
33
"AWSTemplateFormatVersion" : "2010-09-09",
44
"Conditions": {
5+
"DedicatedRole": { "Fn::Not":[{"Fn::Equals":[{"Ref":"Policies"},""]} ] },
56
"EnableCloudWatch": { "Fn::Equals": [ { "Ref": "LogDriver" }, "CloudWatch" ] },
67
"EnableSyslog": { "Fn::Equals": [ { "Ref": "LogDriver" }, "Syslog" ] },
78
"FargateEither": { "Fn::Or": [ { "Condition": "FargateBase" }, { "Condition": "FargateSpot" } ] },
@@ -51,6 +52,10 @@
5152
"Memory": {
5253
"Type": "Number"
5354
},
55+
"Policies": {
56+
"Description": "It will create a new role to be used instead of 'ServiceRole' parameter.",
57+
"Type": "String"
58+
},
5459
"Rack": {
5560
"Type": "String"
5661
},
@@ -159,6 +164,28 @@
159164
} ]
160165
}
161166
},
167+
"DedicatedRole": {
168+
"Condition": "DedicatedRole",
169+
"Type": "AWS::IAM::Role",
170+
"Properties": {
171+
"AssumeRolePolicyDocument": {
172+
"Statement": [ { "Effect": "Allow", "Principal": { "Service": [ "ecs-tasks.amazonaws.com" ] }, "Action": [ "sts:AssumeRole" ] } ],
173+
"Version": "2012-10-17"
174+
},
175+
"ManagedPolicyArns": {"Fn::Split":[",",{"Fn::Join":[",",[{"Ref":"Policies"},{"Fn::ImportValue":{"Fn::Sub":"${Rack}:CMKPolicy"}}]]}]},
176+
"Path": "/convox/",
177+
"Policies": [ {
178+
"PolicyName": "convox-env",
179+
"PolicyDocument": {
180+
"Version": "2012-10-17",
181+
"Statement": [
182+
{ "Effect": "Allow", "Action": "s3:GetObject", "Resource": { "Fn::Sub": "arn:${AWS::Partition}:s3:::${Settings}/*" } },
183+
{ "Effect": "Allow", "Action": "kms:Decrypt", "Resource": { "Fn::ImportValue": { "Fn::Sub": "${Rack}:EncryptionKey" } } }
184+
]
185+
}
186+
} ]
187+
}
188+
},
162189
"TaskDefinition": {
163190
"Type": "AWS::ECS::TaskDefinition",
164191
"Properties": {
@@ -272,7 +299,7 @@
272299
"Memory": { "Fn::If": [ "FargateEither", { "Ref": "Memory" }, { "Ref": "AWS::NoValue" } ] },
273300
"NetworkMode": { "Fn::If": [ "FargateEither", "awsvpc", { "Ref": "AWS::NoValue" } ] },
274301
"RequiresCompatibilities": [ { "Fn::If": [ "FargateEither", "FARGATE", { "Ref": "AWS::NoValue" } ] } ],
275-
"TaskRoleArn": { "Ref": "ServiceRole" },
302+
"TaskRoleArn": { "Fn::If": [ "DedicatedRole", { "Fn::GetAtt": [ "DedicatedRole", "Arn" ] }, { "Ref": "ServiceRole" } ] },
276303
"Volumes": [
277304
{{ $resources := ($.Manifest.Service .Service).Resources }}
278305
{{ range $i, $v := ($.Manifest.Service .Service).Volumes }}

0 commit comments

Comments
 (0)