Skip to content
This repository has been archived by the owner on Jan 19, 2022. It is now read-only.

Commit

Permalink
Add DependsOn Requirements to cloudformation
Browse files Browse the repository at this point in the history
Some cloudformation resources depend on other resources before they
can be created or deleted. This especially causes problems when deleting
VPC's, meaning that the delete fails since there are dependent resources
still in the process of being removed form the VPC.

By adding the DependsOn attribute to these resources, this problem can be resolved.
This change uses the AWS guidance on when this is required to add this attribute to resources
that do, or may require it. The details are in the link below.
http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-attribute-dependson.html#gatewayattachment

Following the advice in the document above, the resources below are considered,

Already has DependsOn the VPCGatewayAttachment
* Amazon VPC routes that include the Internet gateway

Added DependsOn the VPCGatewayAttachment since EC2 instances have public ips
* Auto Scaling groups
* Elastic Load Balancers

Added DependsOn the VPCGatewayAttachment since they can have public ips
* RDS instances

No action required
* Elastic IP addresses - we dont have any yet
* Amazon EC2 instances - these are handled by the ASG

(Closes #177)
  • Loading branch information
Niall Creech committed Jun 29, 2016
1 parent 11b3fed commit 40ccd1f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
6 changes: 4 additions & 2 deletions bootstrap_cfn/config.py
Expand Up @@ -535,7 +535,7 @@ def rds(self, template):
AutoMinorVersionUpgrade=False,
VPCSecurityGroups=[GetAtt(database_sg, "GroupId")],
DBSubnetGroupName=Ref(rds_subnet_group),
DependsOn=database_sg.title
DependsOn=["AttachGateway", database_sg.title],
)
resources.append(rds_instance)

Expand Down Expand Up @@ -738,7 +738,8 @@ def elb(self, template):
Enabled=True,
Timeout=120,
),
Policies=elb_policies
Policies=elb_policies,
DependsOn=["AttachGateway"],
)
if "health_check" in elb:
load_balancer.HealthCheck = HealthCheck(**elb['health_check'])
Expand Down Expand Up @@ -1112,6 +1113,7 @@ def ec2(self):
LaunchConfigurationName=Ref(launch_config),
HealthCheckGracePeriod=health_check_grace_period,
HealthCheckType=health_check_type,
DependsOn=["AttachGateway"],
)
resources.append(scaling_group)

Expand Down
12 changes: 9 additions & 3 deletions tests/tests.py
Expand Up @@ -312,7 +312,7 @@ def test_rds(self):
db_subnet.SubnetIds = [Ref('SubnetA'), Ref('SubnetB'), Ref('SubnetC')]
db_subnet.DBSubnetGroupDescription = 'VPC Subnets'

db_instance = rds.DBInstance('RDSInstance', DependsOn=db_sg.title)
db_instance = rds.DBInstance('RDSInstance', DependsOn=["AttachGateway", db_sg.title])
db_instance.MultiAZ = False
db_instance.MasterUsername = 'testuser'
db_instance.MasterUserPassword = 'testpassword'
Expand Down Expand Up @@ -457,7 +457,8 @@ def test_elb(self):
PolicyType='SSLNegotiationPolicyType',
PolicyName='PinDownSSLNegotiationPolicy201505'
)
]
],
DependsOn=["AttachGateway"],
)

pt1 = PolicyType(
Expand Down Expand Up @@ -566,6 +567,7 @@ def test_elb(self):
PolicyName='PinDownSSLNegotiationPolicy201505'
)
],
DependsOn=["AttachGateway"],
)
known_load_balancer_resources = [lb, lb2]
known_policy_type_resources = [pt1, pt2]
Expand Down Expand Up @@ -986,6 +988,7 @@ def test_elb_with_ssl(self):
PolicyName='PinDownSSLNegotiationPolicy201505'
)
],
DependsOn=["AttachGateway"],
)

Policydockerregistryservice = PolicyType(
Expand Down Expand Up @@ -1110,6 +1113,7 @@ def test_elb_with_healthcheck(self):
PolicyName='PinDownSSLNegotiationPolicy201505'
)
],
DependsOn=["AttachGateway"],
)

Policydockerregistryservice = PolicyType(
Expand Down Expand Up @@ -1213,6 +1217,7 @@ def test_elb_with_reserved_chars(self):
PolicyName='PinDownSSLNegotiationPolicy201505'
)
],
DependsOn=["AttachGateway"],
)

DNSdevdockerregistryservice = RecordSetGroup(
Expand Down Expand Up @@ -1321,7 +1326,8 @@ def test_ec2(self):
LaunchConfigurationName=Ref("BaseHostLaunchConfig"),
AvailabilityZones=GetAZs(""),
HealthCheckGracePeriod=300,
HealthCheckType='EC2'
HealthCheckType='EC2',
DependsOn=["AttachGateway"],
)

BaseHostSG = SecurityGroup(
Expand Down

0 comments on commit 40ccd1f

Please sign in to comment.