From 3718cde444b3e0117072c29b087237e1787c3a66 Mon Sep 17 00:00:00 2001 From: Panagiotis Irakleous <8356922+pirakleous@users.noreply.github.com> Date: Sat, 2 Apr 2022 18:07:40 +0100 Subject: [PATCH] fix cloudformation arn account id (#4995) --- moto/cloudformation/utils.py | 6 +++--- .../test_cloudformation_stack_crud_boto3.py | 12 +++++++----- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/moto/cloudformation/utils.py b/moto/cloudformation/utils.py index 652c6952b..a6dc37da7 100644 --- a/moto/cloudformation/utils.py +++ b/moto/cloudformation/utils.py @@ -7,7 +7,7 @@ import string from moto.core import ACCOUNT_ID -def generate_stack_id(stack_name, region="us-east-1", account="123456789"): +def generate_stack_id(stack_name, region="us-east-1", account=ACCOUNT_ID): random_id = uuid.uuid4() return "arn:aws:cloudformation:{}:{}:stack/{}/{}".format( region, account, stack_name, random_id @@ -16,8 +16,8 @@ def generate_stack_id(stack_name, region="us-east-1", account="123456789"): def generate_changeset_id(changeset_name, region_name): random_id = uuid.uuid4() - return "arn:aws:cloudformation:{0}:123456789:changeSet/{1}/{2}".format( - region_name, changeset_name, random_id + return "arn:aws:cloudformation:{0}:{1}:changeSet/{2}/{3}".format( + region_name, ACCOUNT_ID, changeset_name, random_id ) diff --git a/tests/test_cloudformation/test_cloudformation_stack_crud_boto3.py b/tests/test_cloudformation/test_cloudformation_stack_crud_boto3.py index 5dd731ae2..0be77de80 100644 --- a/tests/test_cloudformation/test_cloudformation_stack_crud_boto3.py +++ b/tests/test_cloudformation/test_cloudformation_stack_crud_boto3.py @@ -1073,10 +1073,10 @@ def test_creating_stacks_across_regions(): list(west2_cf.stacks.all()).should.have.length_of(1) list(west1_cf.stacks.all())[0].stack_id.should.contain( - "arn:aws:cloudformation:us-west-1:123456789:stack/test_stack/" + "arn:aws:cloudformation:us-west-1:{}:stack/test_stack/".format(ACCOUNT_ID) ) list(west2_cf.stacks.all())[0].stack_id.should.contain( - "arn:aws:cloudformation:us-west-2:123456789:stack/test_stack/" + "arn:aws:cloudformation:us-west-2:{}:stack/test_stack/".format(ACCOUNT_ID) ) @@ -1379,11 +1379,11 @@ def test_create_change_set_from_s3_url(): Tags=[{"Key": "tag-key", "Value": "tag-value"}], ) assert ( - "arn:aws:cloudformation:us-west-1:123456789:changeSet/NewChangeSet/" + "arn:aws:cloudformation:us-west-1:{}:changeSet/NewChangeSet/".format(ACCOUNT_ID) in response["Id"] ) assert ( - "arn:aws:cloudformation:us-west-1:123456789:stack/NewStack" + "arn:aws:cloudformation:us-west-1:{}:stack/NewStack".format(ACCOUNT_ID) in response["StackId"] ) @@ -1857,7 +1857,9 @@ def test_update_stack_when_rolled_back(): err = ex.value.response["Error"] err.should.have.key("Code").being.equal("ValidationError") err.should.have.key("Message").match( - r"Stack:arn:aws:cloudformation:us-east-1:123456789:stack/test_stack/[a-z0-9-]+ is in ROLLBACK_COMPLETE state and can not be updated." + r"Stack:arn:aws:cloudformation:us-east-1:{}:stack/test_stack/[a-z0-9-]+ is in ROLLBACK_COMPLETE state and can not be updated.".format( + ACCOUNT_ID + ) )