convection 0.2.33 → 0.2.34.pre.beta.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. checksums.yaml +4 -4
  2. data/.yardopts +1 -0
  3. data/CONTRIBUTING.md +22 -0
  4. data/README.md +15 -202
  5. data/Rakefile +3 -0
  6. data/docs/adding-new-resource-coverage.md +265 -0
  7. data/docs/canceling-stack-updates.md +5 -0
  8. data/docs/deleting-stacks.md +5 -0
  9. data/docs/getting-started.md +904 -0
  10. data/docs/index.md +69 -0
  11. data/docs/pygment.css +62 -0
  12. data/docs/relationship-to-cloudformation.md +51 -0
  13. data/docs/stacks.md +86 -0
  14. data/docs/template.html +130 -0
  15. data/example/getting-started-guide/Cloudfile +12 -0
  16. data/example/getting-started-guide/vpc.rb +74 -0
  17. data/example/stacks/Cloudfile +12 -0
  18. data/example/stacks/tasks/lookup_vpc_task.rb +28 -0
  19. data/example/stacks/templates/vpc.rb +14 -0
  20. data/lib/convection.rb +6 -0
  21. data/lib/convection/control/cloud.rb +1 -0
  22. data/lib/convection/control/stack.rb +126 -15
  23. data/lib/convection/model/cloudfile.rb +3 -0
  24. data/lib/convection/model/template/resource/aws_cloudfront_distribution.rb +24 -30
  25. data/lib/convection/model/template/resource/aws_ec2_dhcp_options.rb +38 -0
  26. data/lib/convection/model/template/resource/aws_ec2_security_group.rb +24 -2
  27. data/lib/convection/model/template/resource/aws_iam_user.rb +17 -3
  28. data/lib/convection/model/template/resource/aws_s3_bucket.rb +9 -3
  29. data/lib/convection/model/template/resource/aws_s3_bucket_policy.rb +10 -3
  30. data/lib/convection/model/template/resource/aws_sns_topic.rb +6 -3
  31. data/lib/convection/model/template/resource/aws_sns_topic_policy.rb +10 -3
  32. data/lib/convection/model/template/resource/aws_sqs_queue.rb +5 -3
  33. data/lib/convection/model/template/resource/aws_sqs_queue_policy.rb +10 -3
  34. data/spec/convection/model/template/resource/ec2_dhcp_options_spec.rb +55 -0
  35. data/yard_extensions.rb +4 -0
  36. data/yard_extensions/properties_handler.rb +30 -0
  37. data/yard_extensions/type_handler.rb +188 -0
  38. metadata +27 -23
  39. data/example/Cloudfile +0 -13
  40. data/example/deprecated/elb.rb +0 -27
  41. data/example/deprecated/iam_access_key.rb +0 -18
  42. data/example/deprecated/iam_group.rb +0 -31
  43. data/example/deprecated/iam_role.rb +0 -52
  44. data/example/deprecated/iam_user.rb +0 -31
  45. data/example/deprecated/rds.rb +0 -70
  46. data/example/deprecated/s3.rb +0 -13
  47. data/example/deprecated/sqs.rb +0 -32
  48. data/example/deprecated/vpc.rb +0 -85
  49. data/example/instances.rb +0 -93
  50. data/example/output/vpc.json +0 -335
  51. data/example/security-groups.rb +0 -77
  52. data/example/sqs-queue/Cloudfile +0 -19
  53. data/example/sqs-queue/README.md +0 -12
  54. data/example/trust_cloudtrail.rb +0 -24
  55. data/example/vpc.rb +0 -143
@@ -0,0 +1,69 @@
1
+ # Convection [![Build Status](https://travis-ci.org/rapid7/convection.svg)](https://travis-ci.org/rapid7/convection)
2
+ _A fully generic, modular DSL for AWS CloudFormation_
3
+
4
+ This gem aims to provide a reusable model for AWS CloudFormation in Ruby. It exposes a DSL for template definition, and a simple, decoupled abstraction of a CloudFormation Stack to compile and apply templates.
5
+
6
+ ## Contributing
7
+ Please read our [Contributing guidelines](CONTRIBUTING.md) for more information on contributing to Convection.
8
+
9
+ ## Installation
10
+ Add this line to your application's Gemfile:
11
+
12
+ ```ruby
13
+ gem 'convection'
14
+ ```
15
+
16
+ And then execute:
17
+
18
+ $ bundle
19
+
20
+ Or install it yourself as:
21
+
22
+ $ gem install convection
23
+
24
+ ##CLI Commands
25
+ ###### Converging
26
+ - To converge all stacks in your cloudfile run `convection converge`. If you provide the name of your stack as a additional argument such as `convection converge my-stack-name` then all stacks above and including the stack you specified will be converged.
27
+
28
+ ###### Diff
29
+ - To display diff between your local changes and the version of your stack in cloud formation of your changes run `convection diff`.
30
+
31
+ ###### Help
32
+ - To print out a list of available cli options with their descriptions run `convection help`.
33
+
34
+ ###### Print
35
+ - To print out the cloud formation template for a specific stack run `convection print my-stack-name`.
36
+
37
+ ###### Validate
38
+ - To validate your stack is not missing a required resource run `convection validate my-stack-name`.
39
+
40
+ ## Documentation
41
+ We highly recommend consulting the [getting started guide](./docs/getting-started.md) for a in depth walk through on how to to set up your project and create and deploy a stack. Example stacks and resources are available in the [convection/example](https://github.com/rapid7/convection/tree/master/example) folder
42
+
43
+ ## License
44
+ _Copyright (c) 2015 John Manero, Rapid7 LLC._
45
+
46
+ ```
47
+ MIT License
48
+ ===========
49
+
50
+ Permission is hereby granted, free of charge, to any person obtaining
51
+ a copy of this software and associated documentation files (the
52
+ "Software"), to deal in the Software without restriction, including
53
+ without limitation the rights to use, copy, modify, merge, publish,
54
+ distribute, sublicense, and/or sell copies of the Software, and to
55
+ permit persons to whom the Software is furnished to do so, subject to
56
+ the following conditions:
57
+
58
+ The above copyright notice and this permission notice shall be
59
+ included in all copies or substantial portions of the Software.
60
+
61
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
62
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
63
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
64
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
65
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
66
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
67
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
68
+
69
+ ```
@@ -0,0 +1,62 @@
1
+ /* Pygment syntax highlighting setup for viewdocs.io */
2
+ .highlight { background: #ffffff; }
3
+ .highlight .pl-bp { color: #999999 } /* Name.Builtin.Pseudo */
4
+ .highlight .pl-c { color: #999988; font-style: italic } /* Comment */
5
+ .highlight .pl-c1 { color: #999988; font-style: italic } /* Comment.Single */
6
+ .highlight .pl-cm { color: #999988; font-style: italic } /* Comment.Multiline */
7
+ .highlight .pl-cp { color: #999999; font-weight: bold } /* Comment.Preproc */
8
+ .highlight .pl-cs { color: #999999; font-weight: bold; font-style: italic } /* Comment.Special */
9
+ .highlight .pl-err { color: #a61717; background-color: #e3d2d2 } /* Error */
10
+ .highlight .pl-gd .x { color: #000000; background-color: #ffaaaa } /* Generic.Deleted.Specific */
11
+ .highlight .pl-gd { color: #000000; background-color: #ffdddd } /* Generic.Deleted */
12
+ .highlight .pl-ge { font-style: italic } /* Generic.Emph */
13
+ .highlight .pl-gh { color: #999999 } /* Generic.Heading */
14
+ .highlight .pl-gi .x { color: #000000; background-color: #aaffaa } /* Generic.Inserted.Specific */
15
+ .highlight .pl-gi { color: #000000; background-color: #ddffdd } /* Generic.Inserted */
16
+ .highlight .pl-go { color: #888888 } /* Generic.Output */
17
+ .highlight .pl-gp { color: #555555 } /* Generic.Prompt */
18
+ .highlight .pl-gr { color: #aa0000 } /* Generic.Error */
19
+ .highlight .pl-gs { font-weight: bold } /* Generic.Strong */
20
+ .highlight .pl-gt { color: #aa0000 } /* Generic.Traceback */
21
+ .highlight .pl-gu { color: #800080; font-weight: bold; } /* Generic.Subheading */
22
+ .highlight .pl-il { color: #009999 } /* Literal.Number.Integer.Long */
23
+ .highlight .pl-k { font-weight: bold } /* Keyword */
24
+ .highlight .pl-kc { font-weight: bold } /* Keyword.Constant */
25
+ .highlight .pl-kd { font-weight: bold } /* Keyword.Declaration */
26
+ .highlight .pl-kn { font-weight: bold } /* Keyword.Namespace */
27
+ .highlight .pl-kp { font-weight: bold } /* Keyword.Pseudo */
28
+ .highlight .pl-kr { font-weight: bold } /* Keyword.Reserved */
29
+ .highlight .pl-kt { color: #445588; font-weight: bold } /* Keyword.Type */
30
+ .highlight .pl-m { color: #009999 } /* Literal.Number */
31
+ .highlight .pl-mf { color: #009999 } /* Literal.Number.Float */
32
+ .highlight .pl-mh { color: #009999 } /* Literal.Number.Hex */
33
+ .highlight .pl-mi { color: #009999 } /* Literal.Number.Integer */
34
+ .highlight .pl-mo { color: #009999 } /* Literal.Number.Oct */
35
+ .highlight .pl-na { color: #008080 } /* Name.Attribute */
36
+ .highlight .pl-nb { color: #0086B3 } /* Name.Builtin */
37
+ .highlight .pl-nc { color: #445588; font-weight: bold } /* Name.Class */
38
+ .highlight .pl-ne { color: #990000; font-weight: bold } /* Name.Exception */
39
+ .highlight .pl-nf { color: #990000; font-weight: bold } /* Name.Function */
40
+ .highlight .pl-ni { color: #800080 } /* Name.Entity */
41
+ .highlight .pl-nn { color: #555555 } /* Name.Namespace */
42
+ .highlight .pl-no { color: #008080 } /* Name.Constant */
43
+ .highlight .pl-nt { color: #000080 } /* Name.Tag */
44
+ .highlight .pl-nv { color: #008080 } /* Name.Variable */
45
+ .highlight .pl-o { font-weight: bold } /* Operator */
46
+ .highlight .pl-ow { font-weight: bold } /* Operator.Word */
47
+ .highlight .pl-s { color: #d14 } /* Literal.String */
48
+ .highlight .pl-s1 { color: #d14 } /* Literal.String.Single */
49
+ .highlight .pl-s2 { color: #d14 } /* Literal.String.Double */
50
+ .highlight .pl-sb { color: #d14 } /* Literal.String.Backtick */
51
+ .highlight .pl-sc { color: #d14 } /* Literal.String.Char */
52
+ .highlight .pl-sd { color: #d14 } /* Literal.String.Doc */
53
+ .highlight .pl-se { color: #d14 } /* Literal.String.Escape */
54
+ .highlight .pl-sh { color: #d14 } /* Literal.String.Heredoc */
55
+ .highlight .pl-si { color: #d14 } /* Literal.String.Interpol */
56
+ .highlight .pl-sr { color: #009926 } /* Literal.String.Regex */
57
+ .highlight .pl-ss { color: #990073 } /* Literal.String.Symbol */
58
+ .highlight .pl-sx { color: #d14 } /* Literal.String.Other */
59
+ .highlight .pl-vc { color: #008080 } /* Name.Variable.Class */
60
+ .highlight .pl-vg { color: #008080 } /* Name.Variable.Global */
61
+ .highlight .pl-vi { color: #008080 } /* Name.Variable.Instance */
62
+ .highlight .pl-w { color: #bbbbbb } /* Text.Whitespace */
@@ -0,0 +1,51 @@
1
+ # Relationship to CloudFormation
2
+ Convection builds on top of the [Amazon CloudFormation](https://aws.amazon.com/cloudformation/) resource managment tooling. Additionally it adds support for providing additional functionalities using thirdparty tools (AWS APIs or otherwise).
3
+
4
+ ## Convection Stacks
5
+ A Convection Stack (see [Convection::Control::Stack][convection-stack-api]) acts as a Ruby wrapper for a CloudFormation stack. When `Convection::Control::Stack#to_json` is called it is rendered into the CloudFormation template format to be pushed to CloudFormation.
6
+
7
+ Convection adds the notion of state by comparing the remote stack (from CloudFormation) and local stack (rendered from your Ruby DSL template).
8
+
9
+ ## Cloudfiles
10
+ A Cloudfile is used to connect a series of stacks. A Cloudfile requires a name and a region. You can specify multiple stacks to converge for a given "cloud".
11
+
12
+ ### Example
13
+ You may have multiple Cloudfiles for your different regions or for your test/prod environments like so:
14
+
15
+ #### Environments
16
+ ##### `clouds/test-0/Cloudfile`
17
+ ```ruby
18
+ name 'test-0'
19
+ region 'us-east-1'
20
+
21
+ # Mock RDS (create a ec2 mysql server, etc.) in the test environment for quicker turn around.
22
+ stack 'rds', Templates::MOCK_RDS
23
+ ```
24
+
25
+ ##### `clouds/prod-0/Cloudfile`
26
+ ```ruby
27
+ name 'prod-0'
28
+ region 'us-east-1'
29
+
30
+ stack 'rds', Templates::RDS
31
+ ```
32
+
33
+ #### Regions
34
+ ##### `clouds/us-east-1/Cloudfile`
35
+ ```ruby
36
+ name 'prod-0'
37
+ region 'us-east-1'
38
+
39
+ stack 'cdn', Templates::CDN
40
+ ```
41
+
42
+ ##### `clouds/us-west-1/Cloudfile`
43
+ ```ruby
44
+ name 'prod-1'
45
+ region 'us-west-1'
46
+
47
+ # Instead of re-creating a CDN per region create a "cdn mirror" in this region.
48
+ stack 'cdn', Templates::CDN_MIRROR
49
+ ```
50
+
51
+ [convection-stack-api]: http://www.rubydoc.info/gems/convection/Convection/Control/Stack
@@ -0,0 +1,86 @@
1
+ # Convection Stacks
2
+ **NOTE**: Examples in this file can be found in `example/stacks`.
3
+
4
+ ### Defining a stack
5
+ Defining a stack is as simple as a few lines of Ruby:
6
+
7
+ ```ruby
8
+ # templates/vpc.rb
9
+ require 'convection'
10
+
11
+ module Templates
12
+ VPC = Convection.template do
13
+ description 'EC2 VPC Test Template'
14
+
15
+ ec2_vpc 'TargetVPC' do
16
+ network '10.10.10.0/23'
17
+ end
18
+ end
19
+ end
20
+ ```
21
+
22
+ ### Using a defined stack
23
+ ```ruby
24
+ # Cloudfile
25
+ require_relative './templates/vpc.rb'
26
+
27
+ user = ENV['USER'] || 'anon'
28
+ name "#{user}-demo-cloud"
29
+ region 'us-east-1'
30
+
31
+ stack 'vpc', Templates::VPC
32
+ ```
33
+
34
+ Once evaluated by Convection stacks will be represented as CloudFormation JSON.
35
+
36
+ ### Defining a task to execute on a stack
37
+ A stack has the following life-cycle phases:
38
+
39
+ 1. Before creation (`before_create_task`)
40
+ 2. After creation (`after_create_task`)
41
+ 3. Before being updated (`before_update_task`)
42
+ 4. After being updated (`after_update_task`)
43
+ 5. Before deletion (`before_delete_task`)
44
+ 6. After deletion (`after_delete_task`)
45
+
46
+ To define tasks on a stack (using the `VPC` stack defined above for example):
47
+
48
+ ```ruby
49
+ # tasks/lookup_vpc_task.rb
50
+ module Tasks
51
+ class LookupVpcTask
52
+ # REQUIRED: Convection expects tasks to respond to #call.
53
+ def call(stack)
54
+ @vpc_id = stack.get('vpc', 'id')
55
+ @result = vpc_found?
56
+ end
57
+
58
+ # REQUIRED: Convection expects tasks to respond to #success?.
59
+ def success?
60
+ @result
61
+ end
62
+
63
+ # OPTIONAL: Convection emits the task as `task.to_s` in certain log messages.
64
+ def to_s
65
+ return 'VPC lookup' unless @vpc_id
66
+
67
+ "VPC lookup of #{@vpc_id.inspect}"
68
+ end
69
+
70
+ private
71
+
72
+ def vpc_found?
73
+ true # XXX: This could be a call to the aws-sdk APIs.
74
+ end
75
+ end
76
+ end
77
+ ```
78
+
79
+ You would then change your Cloudfile to give the optional configuration block to the stack declaration:
80
+ ```ruby
81
+ # Cloudfile
82
+ stack 'vpc', Templates::VPC do
83
+ after_create_task Tasks::LookupVpcTask.new
84
+ after_update_task Tasks::LookupVpcTask.new
85
+ end
86
+ ```
@@ -0,0 +1,130 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <title>{{NAME}} :: viewdocs.io</title>
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <meta charset="utf-8">
7
+
8
+ <link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootswatch/3.0.2/yeti/bootstrap.min.css">
9
+ <link rel="stylesheet" href="http://rapid7.github.io/convection/stylesheets/pygment.css">
10
+
11
+ <style>
12
+ html, body {
13
+ height: 100%;
14
+ margin: 0;
15
+ padding: 0;
16
+ /* The html and body elements cannot have any padding or margin. */
17
+ }
18
+
19
+ /* Wrapper for page content to push down footer */
20
+ #wrap {
21
+ min-height: 100%;
22
+ height: auto;
23
+ /* Negative indent footer by its height */
24
+ margin: 0 auto -60px;
25
+ /* Pad bottom by footer height */
26
+ padding: 0 0 60px;
27
+ }
28
+
29
+ /* Set the fixed height of the footer here */
30
+ footer {
31
+ height: 60px;
32
+ background-color: #f5f5f5;
33
+ padding-top: 9px;
34
+ }
35
+
36
+ footer p {
37
+ clear: left;
38
+ margin-bottom: 0;
39
+ }
40
+
41
+ #wrap > .container,.col-sm-3,.col-sm-9 {
42
+ padding-top: 60px;
43
+ }
44
+
45
+ #side-nav {
46
+ padding-left: 30px;
47
+ }
48
+
49
+ .navbar-nav>li>iframe {
50
+ margin-top: 12px;
51
+ }
52
+ </style>
53
+
54
+ <!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
55
+ <!--[if lt IE 9]>
56
+ <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
57
+ <script src="https://oss.maxcdn.com/libs/respond.js/1.3.0/respond.min.js"></script>
58
+ <![endif]-->
59
+ </head>
60
+ <body>
61
+ <div id="wrap">
62
+ <div class="navbar navbar-inverse navbar-fixed-top">
63
+ <div class="container">
64
+ <div class="navbar-header">
65
+ <a href="/{{NAME}}/" class="navbar-brand">{{NAME}}</a>
66
+ <button class="navbar-toggle" type="button" data-toggle="collapse" data-target="#navbar-main">
67
+ <span class="icon-bar"></span>
68
+ <span class="icon-bar"></span>
69
+ <span class="icon-bar"></span>
70
+ </button>
71
+ </div>
72
+ <div class="navbar-collapse collapse" id="navbar-main">
73
+ <ul class="nav navbar-nav">
74
+ <li>
75
+ <a href="https://github.com/{{USER}}/{{NAME}}">View on GitHub</a>
76
+ </li>
77
+ <li>
78
+ <a href="http://www.rubydoc.info/gems/{{NAME}}">View on RubyDoc.info</a>
79
+ </li>
80
+ <li>
81
+ <a href="https://rubygems.org/gems/{{NAME}}">View on RubyGems</a>
82
+ </li>
83
+ </ul>
84
+
85
+ <ul class="nav navbar-nav navbar-right visible-md visible-lg">
86
+ <li><iframe src="http://ghbtns.com/github-btn.html?user={{USER}}&repo={{NAME}}&type=watch&count=true" allowtransparency="true" frameborder="0" scrolling="0" width="110" height="20"></iframe></li>
87
+ <li><iframe src="http://ghbtns.com/github-btn.html?user={{USER}}&repo={{NAME}}&type=fork&count=true" allowtransparency="true" frameborder="0" scrolling="0" width="95" height="20"></iframe></li>
88
+ <li><iframe src="http://ghbtns.com/github-btn.html?user={{USER}}&type=follow&count=true" allowtransparency="true" frameborder="0" scrolling="0" width="165" height="20"></iframe></li>
89
+ </ul>
90
+ </div>
91
+ </div>
92
+ </div>
93
+
94
+ <div class="row">
95
+ <div id="side-nav" class="col-sm-3">
96
+ <div class="bs-component">
97
+ <ul class="list-group">
98
+ <li class="list-group-item"><a href="/{{NAME}}/">Home</a></li>
99
+ <li class="list-group-item"><a href="/{{NAME}}/getting-started">Getting Started</a></li>
100
+ <li class="list-group-item"><a href="/{{NAME}}/relationship-to-cloudformation">Relationship to CloudFormation</a></li>
101
+ <li class="list-group-item"><a href="/{{NAME}}/stacks">Stacks</a></li>
102
+ <li class="list-group-item"><a href="/{{NAME}}/deleting-stacks">Deleting Stacks</a></li>
103
+ <li class="list-group-item"><a href="/{{NAME}}/canceling-stack-updates">Canceling Stack Updates</a></li>
104
+ <li class="list-group-item"><a href="/{{NAME}}/adding-new-resource-coverage">Adding New Resource Coverage</a></li>
105
+
106
+ </ul>
107
+ </div>
108
+ </div>
109
+
110
+ <div class="col-sm-9">
111
+ {{CONTENT}}
112
+ </div>
113
+ </div>
114
+ </div>
115
+
116
+ <footer>
117
+ <div class="container">
118
+ <div class="row">
119
+ <div class="col-lg-12">
120
+ <p>Hosted on <a href="http://viewdocs.io">http://viewdocs.io</a>.</p>
121
+ <p>Theme based on <a href="http://bootswatch.com/yeti/">Yeti</a> built by <a href="http://thomaspark.me">Thomas Park</a> and adapted to Viewdocs by <a href="http://fabiorehm.com/">Fábio Rehm</a>.</p>
122
+ </div>
123
+ </div>
124
+ </div>
125
+ </footer>
126
+
127
+ <script src="//oss.maxcdn.com/libs/jquery/2.0.3/jquery.min.js"></script>
128
+ <script src="//netdna.bootstrapcdn.com/bootstrap/3.0.3/js/bootstrap.min.js"></script>
129
+ </body>
130
+ </html>
@@ -0,0 +1,12 @@
1
+ #See the getting started guide for a description of this file and what it does.
2
+ #to run this file make sure you are following the project layout in the getting started guide
3
+ Dir.glob('./../../templates/**.rb') do |file|
4
+ require_relative file
5
+ end
6
+
7
+ require 'convection'
8
+
9
+ region 'us-east-1'
10
+ name 'convection-demo'
11
+
12
+ stack 'vpc', Templates::VPC
@@ -0,0 +1,74 @@
1
+ #See the getting started guide for a description of this file and what it does.
2
+ #to run this file make sure you are following the project layout in the getting started guide
3
+ require 'convection'
4
+
5
+ module Templates
6
+ VPC = Convection.template do
7
+ description 'VPC with Public and Private Subnets (NAT)'
8
+
9
+ ec2_vpc 'DemoVPC' do
10
+ network '10.10.10.0/23'
11
+ tag 'Name', "#{stack.cloud}-#{stack.name}"
12
+ enable_dns true
13
+ add_route_table 'InternetGateway', gateway_route: true
14
+ end
15
+
16
+ ec2_subnet 'PrivateSubnet' do
17
+ network '10.10.10.0/24'
18
+ tag 'Name', "#{stack.cloud}-#{stack.name}-private"
19
+ vpc fn_ref('DemoVPC')
20
+ end
21
+
22
+ ec2_subnet 'PublicSubnet' do
23
+ network '10.10.11.0/24'
24
+ tag 'Name', "#{stack.cloud}-#{stack.name}-public"
25
+ vpc fn_ref('DemoVPC')
26
+ public_ips true
27
+ end
28
+
29
+ ec2_security_group 'NATSecurityGroup' do
30
+ description 'NAT access for private subnet'
31
+ vpc fn_ref('DemoVPC')
32
+ tag 'Name', "#{stack.cloud}-#{stack.name}-nat-security-group"
33
+ ingress_rule :tcp, 443 do
34
+ source '10.10.10.0/24'
35
+ end
36
+ ingress_rule :tcp, 80 do
37
+ source '10.10.10.0/24'
38
+ end
39
+ egress_rule :tcp, 443 do
40
+ source '0.0.0.0/0'
41
+ end
42
+ egress_rule :tcp, 80 do
43
+ source '0.0.0.0/0'
44
+ end
45
+ end
46
+
47
+ ec2_instance 'NATInstance' do
48
+ tag 'Name', "#{stack.cloud}-#{stack.name}-nat"
49
+ image_id 'ami-c02b04a8'
50
+ subnet fn_ref('PublicSubnet')
51
+ security_group fn_ref('NATSecurityGroup')
52
+ src_dst_checks false
53
+ end
54
+
55
+ ec2_subnet_route_table_association 'DemoVPCRouteTable' do
56
+ route_table fn_ref('DemoVPCTableInternetGateway')
57
+ subnet fn_ref('PublicSubnet')
58
+ end
59
+
60
+ ec2_route_table 'PrivateRouteTable' do
61
+ vpc fn_ref('DemoVPC')
62
+ route 'PrivateRoute' do
63
+ destination '0.0.0.0/0'
64
+ instance fn_ref('NATInstance')
65
+ end
66
+ end
67
+
68
+ ec2_subnet_route_table_association 'PrivateRouteAssoc' do
69
+ route_table fn_ref('PrivateRouteTable')
70
+ subnet fn_ref('PrivateSubnet')
71
+ end
72
+
73
+ end
74
+ end