Skip to content

Commit 1305d9a

Browse files
hanwen-clusterhanwen-pcluste
authored andcommitted
Remove dangling IAM policies resources when CustomLambdaRole is specified in cfn custom resource
Signed-off-by: Hanwen <[email protected]>
1 parent 2bccedb commit 1305d9a

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ CHANGELOG
2626

2727
**BUG FIXES**
2828
- Add validation to `ScaledownIdletime` value, to prevent setting a value lower than `-1`.
29+
- Fix issue causing dangling IAM policies to be created when creating ParallelCluster CloudFormation custom resource provider with `CustomLambdaRole`.
2930

3031
3.6.1
3132
------

cloudformation/custom_resource/cluster.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ Resources:
6868
LogGroupName: !Sub /aws/lambda/${PclusterCfnFunction}
6969

7070
EventsPolicy:
71+
Condition: UsePCPolicies
7172
Type: AWS::IAM::ManagedPolicy
7273
Properties:
7374
PolicyDocument:
@@ -82,6 +83,7 @@ Resources:
8283
- events:RemoveTargets
8384
Resource: !Sub arn:${AWS::Partition}:events:${AWS::Region}:${AWS::AccountId}:rule/*
8485
S3Policy:
86+
Condition: UsePCPolicies
8587
Type: AWS::IAM::ManagedPolicy
8688
Properties:
8789
PolicyDocument:

tests/integration-tests/tests/custom_resource/test_cluster_custom_resource.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,15 +319,27 @@ def test_cluster_create_with_custom_policies(
319319
):
320320
"""Create a custom resource provider with a custom role and create a cluster to validate it."""
321321
parameters = {"CustomBucket": resource_bucket, stack_param: resource_bucket_policies.cfn_outputs[cfn_output]}
322+
provider_stack_name = generate_stack_name(
323+
"integ-test-custom-resource-provider", request.config.getoption("stackname_suffix")
324+
)
322325
custom_resource_gen = cluster_custom_resource_provider_generator(
323326
cfn_stacks_factory,
324327
region,
325-
generate_stack_name("integ-test-custom-resource-provider", request.config.getoption("stackname_suffix")),
328+
provider_stack_name,
326329
parameters,
327330
cluster_custom_resource_provider_template,
328331
)
329332
service_token = next(custom_resource_gen)
330333

334+
if stack_param == "CustomLambdaRole":
335+
logging.info("Checking no IAM resources are created when CustomLambdaRole is specified")
336+
resources = boto3.client("cloudformation").describe_stack_resources(StackName=provider_stack_name)[
337+
"StackResources"
338+
]
339+
for resource in resources:
340+
resource_type = resource["ResourceType"]
341+
assert_that(resource_type).does_not_contain("AWS::IAM::")
342+
331343
stack = cluster_custom_resource_factory(pcluster_config_reader(), service_token=service_token)
332344
cluster_name = _stack_parameter(stack, "ClusterName")
333345
cluster = pc().list_clusters(query=f"clusters[?clusterName=='{cluster_name}']|[0]")

0 commit comments

Comments
 (0)