From 65c29e1f5eaf1d7541b6605fb1a7d4ac20e999bc Mon Sep 17 00:00:00 2001 From: Paul Roberts Date: Fri, 17 Sep 2021 15:45:11 -0700 Subject: [PATCH] Fix CloudFormation create_stack returning stack_id with wrong region (#4302) --- moto/cloudformation/models.py | 2 +- .../test_cloudformation_stack_crud.py | 27 +++++++++++++++++++ .../test_cloudformation_stack_crud_boto3.py | 7 +++++ 3 files changed, 35 insertions(+), 1 deletion(-) diff --git a/moto/cloudformation/models.py b/moto/cloudformation/models.py index 8fddcdab1..83328a5f1 100644 --- a/moto/cloudformation/models.py +++ b/moto/cloudformation/models.py @@ -623,7 +623,7 @@ class CloudFormationBackend(BaseBackend): tags=None, role_arn=None, ): - stack_id = generate_stack_id(name) + stack_id = generate_stack_id(name, region_name) new_stack = FakeStack( stack_id=stack_id, name=name, diff --git a/tests/test_cloudformation/test_cloudformation_stack_crud.py b/tests/test_cloudformation/test_cloudformation_stack_crud.py index 7093296a3..05a1ffeed 100644 --- a/tests/test_cloudformation/test_cloudformation_stack_crud.py +++ b/tests/test_cloudformation/test_cloudformation_stack_crud.py @@ -85,6 +85,33 @@ def test_create_stack(): conn.create_stack("test_stack", template_body=dummy_template_json) stack = conn.describe_stacks()[0] + stack.stack_id.should.contain( + "arn:aws:cloudformation:us-east-1:123456789:stack/test_stack/" + ) + stack.stack_name.should.equal("test_stack") + stack.get_template().should.equal( + { + "GetTemplateResponse": { + "GetTemplateResult": { + "TemplateBody": dummy_template_json, + "ResponseMetadata": { + "RequestId": "2d06e36c-ac1d-11e0-a958-f9382b6eb86bEXAMPLE" + }, + } + } + } + ) + + +@mock_cloudformation_deprecated +def test_create_stack_with_other_region(): + conn = boto.cloudformation.connect_to_region("us-west-2") + conn.create_stack("test_stack", template_body=dummy_template_json) + + stack = conn.describe_stacks()[0] + stack.stack_id.should.contain( + "arn:aws:cloudformation:us-west-2:123456789:stack/test_stack/" + ) stack.stack_name.should.equal("test_stack") stack.get_template().should.equal( { diff --git a/tests/test_cloudformation/test_cloudformation_stack_crud_boto3.py b/tests/test_cloudformation/test_cloudformation_stack_crud_boto3.py index e28cd0ac2..382d46ae1 100644 --- a/tests/test_cloudformation/test_cloudformation_stack_crud_boto3.py +++ b/tests/test_cloudformation/test_cloudformation_stack_crud_boto3.py @@ -907,6 +907,13 @@ def test_creating_stacks_across_regions(): list(west1_cf.stacks.all()).should.have.length_of(1) 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/" + ) + list(west2_cf.stacks.all())[0].stack_id.should.contain( + "arn:aws:cloudformation:us-west-2:123456789:stack/test_stack/" + ) + @mock_cloudformation @mock_sns