@@ -91,9 +91,9 @@ class AutoscalingFargateCluster(tb_pulumi.ThunderbirdComponentResource):
9191 the only valid source. Defaults to {}.
9292 :type container_security_groups: _type_, optional
9393
94- :param exec_role_policies : A dict where the keys are the names of services and the values are lists of ARNs of IAM
95- Policies that service should operate with. These should provide permissions above and beyond what is provided by
96- using the ``registries``, ``secrets``, and ``ssm_params`` parameters.
94+ :param extra_policies : A dict where the keys are the names of services and the values are lists of ARNs of IAM
95+ Policies that service should operate with in addition to what is provided by using the ``registries``,
96+ ``secrets``, and ``ssm_params`` parameters.
9797
9898 :param listeners: A nested dict describing your load balancers' listeners and which targets they point to. At the
9999 top level, the keys are names of load balancers and the values are other dicts. Those dicts' keys are the names of
@@ -173,7 +173,7 @@ def __init__(
173173 cluster : dict = {},
174174 cluster_name : str = None ,
175175 container_security_groups : dict [str :dict ] = {},
176- exec_role_policies : dict [str :list ] = {},
176+ extra_policies : dict [str :list ] = {},
177177 listeners : dict [str , dict ] = {},
178178 load_balancer_security_groups : dict [str , dict ] = {},
179179 load_balancers : dict = {},
@@ -272,7 +272,6 @@ def __init__(
272272 f'{ name } -execrolepolicy-{ service } ' ,
273273 name = f'{ name } -{ service } ' ,
274274 description = f'Grants permissions needed to launch the { service } service for { self .project .name_prefix } ' ,
275- managed_policy_arns = exec_role_policies .get (service ),
276275 policy = exec_role_policy_docs [service ],
277276 opts = pulumi .ResourceOptions (parent = self ),
278277 tags = self .tags ,
@@ -281,21 +280,30 @@ def __init__(
281280 }
282281
283282 # Build the execution roles using the policies from above, if they exist
284- exec_roles = {
285- service : aws .iam .Role (
283+ _universal_managed_policy_arns = [
284+ # This AWS managed policy allows access to ECR and log streams
285+ 'arn:aws:iam::aws:policy/service-role/AmazonECSTaskExecutionRolePolicy' ,
286+ ]
287+
288+ exec_roles = {}
289+
290+ for service in services .keys ():
291+ _managed_policy_arns = _universal_managed_policy_arns .copy ()
292+ _managed_policy_arns += [
293+ item
294+ for item in [
295+ exec_role_policies [service ] if service in exec_role_policies else None ,
296+ ]
297+ if item is not None
298+ ]
299+ _managed_policy_arns += extra_policies .get (service , [])
300+
301+ exec_roles [service ] = aws .iam .Role (
286302 f'{ name } -execrole-{ service } ' ,
287303 name = f'{ name } -{ service } ' ,
288304 description = f'Task execution role for running the { service } service for { self .project .name_prefix } ' ,
289305 assume_role_policy = arp ,
290- managed_policy_arns = [
291- item
292- for item in [
293- # This AWS managed policy allows access to ECR and log streams
294- 'arn:aws:iam::aws:policy/service-role/AmazonECSTaskExecutionRolePolicy' ,
295- exec_role_policies [service ] if service in exec_role_policies else None ,
296- ]
297- if item is not None
298- ],
306+ managed_policy_arns = _universal_managed_policy_arns + exec_role_policies .get ('service' , []),
299307 tags = self .tags ,
300308 opts = pulumi .ResourceOptions (
301309 parent = self ,
@@ -306,8 +314,6 @@ def __init__(
306314 ],
307315 ),
308316 )
309- for service in services .keys ()
310- }
311317
312318 # First we build out task definitions. Later, we can refer to them by name. Since task definitions are
313319 # one-to-one with cluster services, the task_name here is assumed to match with a service name.
0 commit comments