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

Commit

Permalink
make vpc_cidr and vpc_tenancy optional.
Browse files Browse the repository at this point in the history
	modified:   botoform/builders.py
	modified:   docs/source/index.rst
	modified:   docs/source/schema/index.rst
	new file:   docs/source/schema/jinja2/index.rst
	new file:   docs/source/schema/vpc.rst
	modified:   readme.rst
	modified:   tests/fixtures/webapp.yaml
  • Loading branch information
russellballestrini committed Jan 5, 2017
1 parent 007aef9 commit 7845456
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 8 deletions.
17 changes: 12 additions & 5 deletions botoform/builders.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,10 @@ def _apply_all(self, config):
# set a var for no_cfg.
no_cfg = {}

# builds the vpc.
self.build_vpc(config.get('vpc_cidr', None))
# build the vpc.
vpc_cidr = config.get('vpc_cidr', '172.31.0.0/16')
vpc_tenancy = config.get('vpc_tenancy', 'default')
self.build_vpc(vpc_cidr, vpc_tenancy)

# attach EnrichedVPC to self.
self.evpc = EnrichedVPC(self.vpc_name, self.boto.region_name, self.boto.profile_name, self.log)
Expand Down Expand Up @@ -137,10 +139,15 @@ def _apply_all(self, config):

self.log.emit('done! don\'t you look awesome. : )')

def build_vpc(self, cidrblock):
def build_vpc(self, cidrblock, tenancy='default'):
"""Build VPC"""
self.log.emit('creating vpc ({}, {})'.format(self.vpc_name, cidrblock))
vpc = self.boto.ec2.create_vpc(CidrBlock = cidrblock)
msg_vpc = 'creating vpc ({}, {}) with {} tenancy'
self.log.emit(msg_vpc.format(self.vpc_name, cidrblock, tenancy))

vpc = self.boto.ec2.create_vpc(
CidrBlock = cidrblock,
InstanceTenancy = tenancy,
)

self.log.emit('tagging vpc (Name:{})'.format(self.vpc_name), 'debug')
update_tags(vpc, Name = self.vpc_name)
Expand Down
4 changes: 3 additions & 1 deletion docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Quickstart
:maxdepth: 2
:glob:

guides/quickstart
guides/quickstart.rst

Tools
=====
Expand All @@ -48,6 +48,8 @@ End user YAML Schema Reference for describing VPCs and related AWS resources.

schema/index.rst

You may optionally use :ref:`Jinja2` in your YAML config.

Developer Reference
===================

Expand Down
4 changes: 3 additions & 1 deletion docs/source/schema/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ End user YAML Schema Reference for describing VPCs and related AWS resources.

These documents describe how to structure YAML in a Botoform compatible schema.

You may optionally use :ref:`Jinja2` in your YAML config.

.. toctree::
:maxdepth: 2
:glob:

*
*

40 changes: 40 additions & 0 deletions docs/source/schema/jinja2/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
.. _jinja2:

Jinja2
###########

Jinja2 is a templating language.

.. note:: Jinja2 is optional and considered "advanced".

Jinja2 variable substitutions
================================

One popular use of Jinja2 is for variable substitutions and expansions.

In this example we use a substitution to define the ``vpc_cidr``.

.. code-block:: yaml
vpc_cidr: {{ vpc_cidr }}
When the time comes to create a new VPC, we pass an extra variable using ``-e``.

For example, to set the ``vpc_cidr`` to ``192.168.1.0/24``:

.. code-block:: bash
bf create dogtest01 -e 'vpc_cidr=192.168.1.0/24' webapp.yaml
Jinja2 default filter
================================

In this example we will use a Jinja2 filter called ``default``.

Like our example from before, but this time setting a default.

.. code-block:: yaml
vpc_cidr: {{ vpc_cidr | default(10.10.0.0/24) }}
Now the user may omit the extra variables and we will use the default.
19 changes: 19 additions & 0 deletions docs/source/schema/vpc.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
.. _vpc:

vpc
#######

Optional ``vpc`` schema settings:

.. code-block:: yaml
vpc_cidr: the-cidr-block-to-allocate-to-your-vpc
vpc_tenancy: whether-or-not-your-vpc-should-use-default-or-dedicated
For example:

.. code-block:: yaml
vpc_cidr: 10.10.10.0/24
vpc_tenancy: default
3 changes: 2 additions & 1 deletion readme.rst
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,9 @@ The full YAML Schema_ Reference documentation is in progress.

For now please look here for examples:

https://github.com/russellballestrini/botoform/blob/master/tests/fixtures/webapp.yaml
https://github.com/russellballestrini/botoform/blob/master/tests/fixtures/webapp.yaml

You may optionally use Jinja2 in your YAML config.

Misc
====
Expand Down
4 changes: 4 additions & 0 deletions tests/fixtures/webapp.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ includes:
# for example, when creating new vpc, use -e 'vpc_cidr=192.168.21.0/24'
vpc_cidr: {{ vpc_cidr }}

# Sometimes you want to pay a bunch of money for a dedicated hypervisor.
# set vpc_tenancy to 'dedicated' or 'default' or not at all.
#vpc_tenancy: {{ vpc_tenancy | default('default') }}

# optional way to add tags (key:value) to all resources.
tags:
env: dev
Expand Down

0 comments on commit 7845456

Please sign in to comment.