From 04cbd1fa1a6996d3cb9e6bb61e88e24f6b96c69e Mon Sep 17 00:00:00 2001 From: Ismael Fernandez Molina Date: Sat, 20 Mar 2021 09:57:53 +0100 Subject: [PATCH] adding physical_resource_id in SubnetRouteTableAssociation, Route and NatGW classes (#3789) * adding physical_resource_id in SubnetRouteTableAssociation, Route and NatGW classes * adding tests * passing litern at test * passsing black==19.10b0 as lintern * passing test to python 2.7 --- moto/ec2/models.py | 12 ++++++++++++ .../test_cloudformation_stack_integration.py | 12 +++++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/moto/ec2/models.py b/moto/ec2/models.py index 7e59321ff..78b66f44f 100644 --- a/moto/ec2/models.py +++ b/moto/ec2/models.py @@ -4030,6 +4030,10 @@ class SubnetRouteTableAssociation(CloudFormationModel): self.route_table_id = route_table_id self.subnet_id = subnet_id + @property + def physical_resource_id(self): + return self.route_table_id + @staticmethod def cloudformation_name_type(): return None @@ -4254,6 +4258,10 @@ class Route(CloudFormationModel): self.interface = interface self.vpc_pcx = vpc_pcx + @property + def physical_resource_id(self): + return self.id + @staticmethod def cloudformation_name_type(): return None @@ -5843,6 +5851,10 @@ class NatGateway(CloudFormationModel): self._backend.associate_address(eni=self._eni, allocation_id=self.allocation_id) self.tags = tags + @property + def physical_resource_id(self): + return self.id + @property def vpc_id(self): subnet = self._backend.get_subnet(self.subnet_id) diff --git a/tests/test_cloudformation/test_cloudformation_stack_integration.py b/tests/test_cloudformation/test_cloudformation_stack_integration.py index e01b49aea..43248669f 100644 --- a/tests/test_cloudformation/test_cloudformation_stack_integration.py +++ b/tests/test_cloudformation/test_cloudformation_stack_integration.py @@ -1940,13 +1940,23 @@ def test_nat_gateway(): cf_conn = boto3.client("cloudformation", "us-east-1") cf_conn.create_stack(StackName="test_stack", TemplateBody=json.dumps(template)) + stack_resources = cf_conn.list_stack_resources(StackName="test_stack") + nat_gateway_resource = stack_resources.get("StackResourceSummaries")[0] + for resource in stack_resources["StackResourceSummaries"]: + if resource["ResourceType"] == "AWS::EC2::NatGateway": + nat_gateway_resource = resource + elif resource["ResourceType"] == "AWS::EC2::Route": + route_resource = resource result = ec2_conn.describe_nat_gateways() - result["NatGateways"].should.have.length_of(1) result["NatGateways"][0]["VpcId"].should.equal(vpc_id) result["NatGateways"][0]["SubnetId"].should.equal(subnet_id) result["NatGateways"][0]["State"].should.equal("available") + result["NatGateways"][0]["NatGatewayId"].should.equal( + nat_gateway_resource.get("PhysicalResourceId") + ) + route_resource.get("PhysicalResourceId").should.contain("rtb-") @mock_cloudformation()