From 6da22f9fa41b1f5d2c661f4d69369270b86b5ee7 Mon Sep 17 00:00:00 2001 From: Gordon Irving Date: Thu, 28 Dec 2017 19:04:37 +0000 Subject: [PATCH 1/2] fix adding tags to vpc created by cloudformation --- moto/ec2/models.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/moto/ec2/models.py b/moto/ec2/models.py index 932f535a1..1f372b57a 100755 --- a/moto/ec2/models.py +++ b/moto/ec2/models.py @@ -2004,6 +2004,11 @@ class VPC(TaggedEC2Resource): cidr_block=properties['CidrBlock'], instance_tenancy=properties.get('InstanceTenancy', 'default') ) + for tag in properties.get("Tags", []): + tag_key = tag["Key"] + tag_value = tag["Value"] + vpc.add_tag(tag_key, tag_value) + return vpc @property From e9b81bb3253cd7375617a733a5761752d645ee66 Mon Sep 17 00:00:00 2001 From: Gordon Irving Date: Thu, 28 Dec 2017 19:27:53 +0000 Subject: [PATCH 2/2] add test for vpc tags --- .../test_cloudformation_stack_integration.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/test_cloudformation/test_cloudformation_stack_integration.py b/tests/test_cloudformation/test_cloudformation_stack_integration.py index 051d8bed7..3a7525585 100644 --- a/tests/test_cloudformation/test_cloudformation_stack_integration.py +++ b/tests/test_cloudformation/test_cloudformation_stack_integration.py @@ -752,6 +752,9 @@ def test_vpc_single_instance_in_subnet(): security_group.vpc_id.should.equal(vpc.id) stack = conn.describe_stacks()[0] + + vpc.tags.should.have.key('Application').which.should.equal(stack.stack_id) + resources = stack.describe_resources() vpc_resource = [ resource for resource in resources if resource.resource_type == 'AWS::EC2::VPC'][0]