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

Commit

Permalink
Automatic tagging of cloudformation and resources with environment name
Browse files Browse the repository at this point in the history
By passing tags while creating our cloudformation stack we can
propagate these tags to our created resources, enabling easy
separation of environments for billing purposes
  • Loading branch information
Niall Creech committed Jun 22, 2015
1 parent c2be12a commit 026f08d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
@@ -1,3 +1,6 @@
##Unreleased
* Tag stack and created resources created with environment name

## Version 0.5.3 [WIP]
* Improve message content when cfn_create raises an exception and fails.
* Cleanup SSL certificates when cfn_create raises an exception and fails.
Expand Down
5 changes: 3 additions & 2 deletions bootstrap_cfn/cloudformation.py
Expand Up @@ -17,10 +17,11 @@ def __init__(self, aws_profile_name, aws_region_name='eu-west-1'):
self.aws_region_name = aws_region_name
self.conn_cfn = utils.connect_to_aws(boto.cloudformation, self)

def create(self, stack_name, template_body):
def create(self, stack_name, template_body, tags=[]):
stack = self.conn_cfn.create_stack(stack_name=stack_name,
template_body=template_body,
capabilities=['CAPABILITY_IAM'])
capabilities=['CAPABILITY_IAM'],
tags=tags)
return stack

def delete(self, stack_name):
Expand Down
8 changes: 7 additions & 1 deletion bootstrap_cfn/fab_tasks.py
Expand Up @@ -344,7 +344,13 @@ def cfn_create(test=False):
# print cfn_config.process()
# Inject security groups in stack template and create stacks.
try:
stack = cfn.create(stack_name, cfn_config.process())
# Set a top-level set of tags for the stack, these will propagate
# down so that many of the created resources will be tagged in
# addition. Notable omissions are EC2 volumes and route53 resources
tags = {
"Env": env.environment
}
stack = cfn.create(stack_name, cfn_config.process(), tags=tags)
except:
# cleanup ssl certificates if any
if 'ssl' in cfn_config.data:
Expand Down

0 comments on commit 026f08d

Please sign in to comment.