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

Commit

Permalink
make identifier backwards compatible and optional
Browse files Browse the repository at this point in the history
  • Loading branch information
Ciprian Ciubotariu committed Jul 28, 2015
1 parent 0ddf589 commit 16c2b70
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 9 deletions.
7 changes: 1 addition & 6 deletions bootstrap_cfn/config.py
Expand Up @@ -3,7 +3,6 @@
import os
import sys
import textwrap
import uuid

from troposphere import Base64, FindInMap, GetAZs, GetAtt, Join, Output, Ref, Tags, Template
from troposphere.autoscaling import AutoScalingGroup, BlockDeviceMapping, \
Expand Down Expand Up @@ -335,6 +334,7 @@ def rds(self, template):

optional_fields = {
'storage-encrypted': 'StorageEncrypted',
'identifier': 'DBInstanceIdentifier'
}

# LOAD STACK TEMPLATE
Expand Down Expand Up @@ -363,18 +363,13 @@ def rds(self, template):
)
resources.append(database_sg)

identifier = ("RDS%s%s"
% ((self.stack_name).replace('-', '').replace('.', '').replace('_', ''),
uuid.uuid4().__str__()[-8:]))

rds_instance = DBInstance(
"RDSInstance",
PubliclyAccessible=False,
AllowMajorVersionUpgrade=False,
AutoMinorVersionUpgrade=False,
VPCSecurityGroups=[GetAtt(database_sg, "GroupId")],
DBSubnetGroupName=Ref(rds_subnet_group),
DBInstanceIdentifier=identifier,
StorageEncrypted=False,
DependsOn=database_sg.title
)
Expand Down
7 changes: 4 additions & 3 deletions tests/tests.py
Expand Up @@ -302,9 +302,10 @@ def test_rds(self):
self.assertTrue("DBInstanceIdentifier" in rds_dict["RDSInstance"]["Properties"],
"test_rds: template does not contain DBInstanceIdentifier")
identifier = rds_dict["RDSInstance"]["Properties"]["DBInstanceIdentifier"]
# identifier starts RDS and contains an 8 char uuid plus stack name
# so this should always be true
self.assertTrue(len(identifier) >= 12)
# Identifier can be optionally be defined in the yaml template for compatibility.
# We're only testing the case where it's defined. If left undefined AWS will
# generate a random one.
self.assertEquals(identifier, 'test-dev')
rds_dict["RDSInstance"]["Properties"].pop("DBInstanceIdentifier")
known = self._resources_to_dict(known)
compare(known, rds_dict)
Expand Down

0 comments on commit 16c2b70

Please sign in to comment.