cfer 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/.gitignore +11 -0
- data/.rspec +2 -0
- data/.travis.yml +16 -0
- data/.yardopts +1 -0
- data/CODE_OF_CONDUCT.md +13 -0
- data/Gemfile +18 -0
- data/LICENSE.txt +21 -0
- data/README.md +221 -0
- data/Rakefile +41 -0
- data/bin/cfer +13 -0
- data/bin/cfer-dbg +25 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/cfer-demo.gif +0 -0
- data/cfer.gemspec +37 -0
- data/examples/instance.rb +84 -0
- data/examples/vpc.rb +84 -0
- data/lib/cfer.rb +236 -0
- data/lib/cfer/block.rb +33 -0
- data/lib/cfer/cfn/aws.rb +29 -0
- data/lib/cfer/cfn/client.rb +164 -0
- data/lib/cfer/cli.rb +138 -0
- data/lib/cfer/core/client.rb +15 -0
- data/lib/cfer/core/fn.rb +55 -0
- data/lib/cfer/core/resource.rb +44 -0
- data/lib/cfer/core/stack.rb +170 -0
- data/lib/cfer/util/error.rb +31 -0
- data/lib/cfer/version.rb +3 -0
- data/lib/cferext/aws/ec2/instance.rb +12 -0
- data/lib/cferext/provisioning.rb +6 -0
- metadata +271 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
YmZlMTM5YzllNzU0ZjJiMTliYWEyMWIwYTVmNjU1OWFmNjQ0NDk5Yw==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
MmUxM2Y1ZjkwOWMyNDA5Mzk4OWJkZTA0Y2Y5ZTdmMjU3NzY3Nzg1Mg==
|
7
|
+
SHA512:
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
NmQyNGQyOWZmOTA1Mzc2OGQ3NmE0Mjg5YTE5MzdmYWFhNDQ4ODZkZTRjOTc1
|
10
|
+
ZTFmOTA5ZmJiODg3YzkwMTk0MTE5MGQzYWFlOTA0OGMxMzNlZTkyY2IwZjU4
|
11
|
+
NTdkMWQyZGEzYTEzMDE5MGU2YjFlMzljMzI3NzczZjJhYTJhMWY=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
YzkzMjUzMGJjYzgzODc2MmFkZWRlZjdiMzFkZDI1NGI5YmQ5ZWQxOWQ4ZTUy
|
14
|
+
YWZiZDZhYmJmNGQ5YmUzNTA4MDRkNTZhMThiMDhjMmRiY2IxZTA5MzBiZDM2
|
15
|
+
MDgxYzA0MTE3M2M0OGVhMWI0MjYxNmM5OTA4YTE2YzQwNzU5M2U=
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
language: ruby
|
2
|
+
install: bundle install --without debug --jobs=3 --retry=3
|
3
|
+
rvm:
|
4
|
+
- 2.1.3
|
5
|
+
- ruby-head
|
6
|
+
script:
|
7
|
+
- bundle exec rspec
|
8
|
+
- bundle exec yard
|
9
|
+
deploy:
|
10
|
+
provider: rubygems
|
11
|
+
api_key:
|
12
|
+
secure: nFmXjdI+hZqU7qUByM2qcLjbz3/5Q1VaQZhL752XrjCZ+1rURLB0hJOpSbbPtdlukdOlU3svDbyh9w9uUL4tIEyHY6u4QDUgaOLPbRyJFZSQkEug367NVVd/hRB4o7qxqJDoXI4mLQQRQRCFtZyrBEY1H6m7TUmTa3B3RwNqPWoHgTIQKdgM4ws17I8wmNVnA0s08AiiMf2sxyX8kkbyo8tOs5KpQ6Uw9Y8bD8EoSTt18nGmT7arhLrinu9ZcDyaoJOtIKQYLWDfoUMAw7zzUR9Z4msfPqepiwh3VIredNVkFVtZ8P6AvF9G2+Dn2Pc93Fb8XSaUfNRBiUC4Vt/5AXEkw5w2z4ok+Xjzc4/0jlSYBEECuZIi7L0ky4+W+5c+jteo2MD5Ave/YrOe4wHehg9xdT/43EWmtYNiFnqhcxcj9ZsR+QUe93fpitb4mBmLiNVY5wT+7L0yQRWMqL6Fl6eYD8qK1PO+0O230Ukxd7kSLpCWPdAxiGCNkCl27IRGaSqiObJL1S8tLZdm2DG4gcQBANyc/A6Ghkbn7qb/qMcYDEXSfWWKTox6cSXPpW4RYXTMwisOoe5Vvn+A0lDPMBIg62FXrem1hgU7twFt4SqyOYD377M+b46Zk7G/62hdCaLtxxbBX93ZWLLusSmlNdI0+xbhc26p4x0aoV4OJiU=
|
13
|
+
gem: cfer
|
14
|
+
on:
|
15
|
+
tags: true
|
16
|
+
repo: seanedwards/cfer
|
data/.yardopts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--markup=markdown
|
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# Contributor Code of Conduct
|
2
|
+
|
3
|
+
As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
|
4
|
+
|
5
|
+
We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, age, or religion.
|
6
|
+
|
7
|
+
Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
|
8
|
+
|
9
|
+
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
|
10
|
+
|
11
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
|
12
|
+
|
13
|
+
This Code of Conduct is adapted from the [Contributor Covenant](http:contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
|
data/Gemfile
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
# Specify your gem's dependencies in cfer.gemspec
|
4
|
+
gemspec
|
5
|
+
|
6
|
+
group :test do
|
7
|
+
gem 'rspec'
|
8
|
+
gem 'rspec-mocks'
|
9
|
+
gem 'guard-rspec'
|
10
|
+
gem 'coveralls', require: false
|
11
|
+
end
|
12
|
+
|
13
|
+
group :debug do
|
14
|
+
gem 'pry'
|
15
|
+
gem 'pry-byebug'
|
16
|
+
gem 'pry-rescue'
|
17
|
+
gem 'pry-stack_explorer'
|
18
|
+
end
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 Sean Edwards
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,221 @@
|
|
1
|
+
# Cfer
|
2
|
+
|
3
|
+
[![Build Status](https://travis-ci.org/seanedwards/cfer.svg?branch=master)](https://travis-ci.org/seanedwards/cfer)
|
4
|
+
[![Coverage Status](https://coveralls.io/repos/seanedwards/cfer/badge.svg)](https://coveralls.io/r/seanedwards/cfer)
|
5
|
+
|
6
|
+
Cfer is a lightweight toolkit for managing CloudFormation templates.
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
|
10
|
+
Add this line to your application's Gemfile:
|
11
|
+
|
12
|
+
```ruby
|
13
|
+
gem 'cfer'
|
14
|
+
```
|
15
|
+
|
16
|
+
And then execute:
|
17
|
+
|
18
|
+
$ bundle
|
19
|
+
|
20
|
+
Or install it yourself as:
|
21
|
+
|
22
|
+
$ gem install cfer
|
23
|
+
|
24
|
+
## Usage
|
25
|
+
|
26
|
+
To quickly see Cfer in action, try converging the example stacks:
|
27
|
+
|
28
|
+
```bash
|
29
|
+
cfer converge vpc -t examples/vpc.rb --profile [YOUR-PROFILE] --region [YOUR-REGION]
|
30
|
+
cfer converge instance -t examples/instance.rb --profile [YOUR-PROFILE] --region [YOUR-REGION] --parameters KeyName:[YOUR-EC2-SSH-KEY]
|
31
|
+
```
|
32
|
+
|
33
|
+
You should see something like this:
|
34
|
+
|
35
|
+
![Demo](cfer-demo.gif)
|
36
|
+
|
37
|
+
### Command line
|
38
|
+
|
39
|
+
Commands:
|
40
|
+
cfer converge [OPTIONS] <stack-name> # Converges a cloudformation stack according to the template
|
41
|
+
cfer generate [OPTIONS] <template.rb> # Generates a CloudFormation template by evaluating a Cfer template
|
42
|
+
cfer help [COMMAND] # Describe available commands or one specific command
|
43
|
+
cfer tail <stack-name> # Follows stack events on standard output as they occur
|
44
|
+
|
45
|
+
#### Global options
|
46
|
+
|
47
|
+
* `--profile <profile>`: The AWS profile to use (from your `~/.aws/credentials` file)
|
48
|
+
* `--region <region>`: The AWS region to use
|
49
|
+
* `--verbose`: Also print debugging messages
|
50
|
+
|
51
|
+
#### `generate <template.rb>`
|
52
|
+
|
53
|
+
The `generate` subcommand evaluates the given Ruby script and prints the CloudFormation stack JSON to standard output.
|
54
|
+
|
55
|
+
The following options may be used with the `generate` command:
|
56
|
+
|
57
|
+
* `--no-pretty-print`: Print minified JSON
|
58
|
+
|
59
|
+
#### `converge <stack-name>`
|
60
|
+
|
61
|
+
Creates or updates a CloudFormation stack according to the specified template.
|
62
|
+
|
63
|
+
The following options may be used with the `converge` command:
|
64
|
+
|
65
|
+
* `--follow` (`-f`): Follows stack events on standard output as the create/update process takes place.
|
66
|
+
* `--stack-file <template.rb>`: Reads this file from the filesystem, rather than the default `<stack-name>.rb`
|
67
|
+
* `--parameters <Key1>:<Value1> <Key2>:<Value2> ...`: Specifies input parameters, which will be available to Ruby in the `parameters` hash, or to CloudFormation by using the `Fn::ref` function
|
68
|
+
* `--on-failure <DELETE|ROLLBACK|DO_NOTHING>`: Specifies the action to take when a stack creation fails. Has no effect if the stack already exists and is being updated.
|
69
|
+
|
70
|
+
#### `tail <stack-name>`
|
71
|
+
|
72
|
+
Prints the latest `n` stack events, and optionally follows events while a stack is converging.
|
73
|
+
|
74
|
+
The following options may be used with the `tail` command:
|
75
|
+
|
76
|
+
* `--follow` (`-f`): Follows stack events on standard output as the create/update process takes place.
|
77
|
+
* `--number` (`-n`): Print the last `n` stack events.
|
78
|
+
|
79
|
+
### Template Anatomy
|
80
|
+
|
81
|
+
See the `examples` directory for some examples of complete templates.
|
82
|
+
|
83
|
+
#### Parameters
|
84
|
+
|
85
|
+
Parameters may be defined using the `parameter` function:
|
86
|
+
|
87
|
+
```ruby
|
88
|
+
parameter :ParameterName,
|
89
|
+
type: 'String',
|
90
|
+
default: 'ParameterValue'
|
91
|
+
```
|
92
|
+
|
93
|
+
A parameter's value may have the form `@stack.output` to look up output values from other stacks in the same account and region. This works anywhere a parameter value is specified, including defaults and inputs. (See the SDK section on [Cfer Stacks](#cfer-stacks) for caveats.)
|
94
|
+
|
95
|
+
Any parameter can be referenced either in Ruby by using the `parameters` hash:
|
96
|
+
|
97
|
+
```ruby
|
98
|
+
parameters[:ParameterName]
|
99
|
+
```
|
100
|
+
|
101
|
+
Parameters can also be used in a CloudFormation reference by using the `Fn::ref` function:
|
102
|
+
|
103
|
+
```ruby
|
104
|
+
Fn::ref(:ParameterName)
|
105
|
+
```
|
106
|
+
|
107
|
+
#### Resources
|
108
|
+
|
109
|
+
Resources may be defined using the `resource` function:
|
110
|
+
|
111
|
+
```ruby
|
112
|
+
resource :ResourceName, 'AWS::CloudFormation::CustomResource', AttributeName: {:attribute_key => 'attribute_value'} do
|
113
|
+
property_name 'property_value'
|
114
|
+
end
|
115
|
+
```
|
116
|
+
|
117
|
+
Gets transformed into the corresponding CloudFormation block:
|
118
|
+
|
119
|
+
```json
|
120
|
+
"ResourceName": {
|
121
|
+
"Type": "AWS::CloudFormation::CustomResource",
|
122
|
+
"AttributeName": {
|
123
|
+
"attribute_key": "attribute_value"
|
124
|
+
},
|
125
|
+
"Properties": {
|
126
|
+
"PropertyName": "property_value"
|
127
|
+
}
|
128
|
+
}
|
129
|
+
```
|
130
|
+
|
131
|
+
#### Outputs
|
132
|
+
|
133
|
+
Outputs may be defined using the `output` function:
|
134
|
+
|
135
|
+
```ruby
|
136
|
+
output :OutputName, Fn::ref(:ResourceName)
|
137
|
+
```
|
138
|
+
|
139
|
+
## SDK
|
140
|
+
|
141
|
+
Embedding the Cfer SDK involves interacting with two components: The `Client` and the `Stack`.
|
142
|
+
The Cfer `Client` is the interface with the Cloud provider.
|
143
|
+
|
144
|
+
### Cfn Client
|
145
|
+
|
146
|
+
Create a new client:
|
147
|
+
|
148
|
+
```ruby
|
149
|
+
Cfer::Cfn::Client.new(stack_name: <stack_name>)
|
150
|
+
```
|
151
|
+
|
152
|
+
`Cfer::Cfn::Client` also accepts options to be passed into the internal `Aws::CloudFormation::Client` constructor.
|
153
|
+
|
154
|
+
#### `converge(stack)`
|
155
|
+
|
156
|
+
Creates or updates the CloudFormation stack to match the input `stack` object. See below for how to create Cfer stack objects.
|
157
|
+
|
158
|
+
```ruby
|
159
|
+
client.converge(<stack>)
|
160
|
+
```
|
161
|
+
|
162
|
+
#### `tail(options = {})`
|
163
|
+
|
164
|
+
Yields to the specified block for each CloudFormation event that qualifies given the specified options.
|
165
|
+
|
166
|
+
```ruby
|
167
|
+
client.tail number: 1, follow: true do |event|
|
168
|
+
# Called for each CloudFormation event, as they occur, until the stack enters a COMPLETE or FAILED state.
|
169
|
+
end
|
170
|
+
```
|
171
|
+
|
172
|
+
### Cfer Stacks
|
173
|
+
|
174
|
+
Create a new stack:
|
175
|
+
|
176
|
+
#### `stack_from_file`
|
177
|
+
|
178
|
+
```ruby
|
179
|
+
stack = Cfer::stack_from_file(<file>, client: <client>)
|
180
|
+
```
|
181
|
+
|
182
|
+
#### `stack_from_block`
|
183
|
+
|
184
|
+
```ruby
|
185
|
+
stack = Cfer::stack_from_block(client: <client>) do
|
186
|
+
# Stack definition goes here
|
187
|
+
end
|
188
|
+
```
|
189
|
+
|
190
|
+
Note: Specifying a client is optional, but if no client is specified, parameter mappings will not occur.
|
191
|
+
|
192
|
+
## Contributing
|
193
|
+
|
194
|
+
This project uses [git-flow](http://nvie.com/posts/a-successful-git-branching-model/). Please name branches and pull requests according to that convention.
|
195
|
+
|
196
|
+
Always use `--no-ff` when merging into `develop` or `master`.
|
197
|
+
|
198
|
+
### New features
|
199
|
+
|
200
|
+
* Branch from `develop`
|
201
|
+
* Merge into `develop`
|
202
|
+
* Name branch `feature/<feature-name>`
|
203
|
+
|
204
|
+
### Unreleased bugs
|
205
|
+
|
206
|
+
* Branch from `develop`
|
207
|
+
* Merge into `develop`
|
208
|
+
* Name branch `bugfix/<issue-id>`
|
209
|
+
|
210
|
+
### Bugfixes against releases
|
211
|
+
|
212
|
+
* Branch from `master`
|
213
|
+
* Merge into `develop` and `master`
|
214
|
+
* Name branch `hotfix/<issue-id>`
|
215
|
+
|
216
|
+
### Releases
|
217
|
+
|
218
|
+
* Branch from `develop`
|
219
|
+
* Merge into `develop` and `master`
|
220
|
+
* Name branch `release/<major.minor>`
|
221
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
gem 'cfer'
|
3
|
+
require 'cfer'
|
4
|
+
require 'highline'
|
5
|
+
|
6
|
+
Cfer::LOGGER.level = Logger::DEBUG
|
7
|
+
|
8
|
+
task :default => [:spec]
|
9
|
+
|
10
|
+
task :config_aws, [:profile] do |t, args|
|
11
|
+
Aws.config.update region: ENV['AWS_REGION'] || 'us-east-1',
|
12
|
+
credentials: Aws::SharedCredentials.new(profile_name: ENV['AWS_PROFILE'] || 'default')
|
13
|
+
end
|
14
|
+
|
15
|
+
task :vpc => :config_aws do |t, args|
|
16
|
+
Cfer.converge! 'vpc',
|
17
|
+
template: 'examples/vpc.rb',
|
18
|
+
follow: true
|
19
|
+
end
|
20
|
+
|
21
|
+
task :describe_vpc => :config_aws do
|
22
|
+
Cfer.describe! 'vpc'
|
23
|
+
end
|
24
|
+
|
25
|
+
task :instance => :config_aws do |t, args|
|
26
|
+
key_pair = ask("Enter your EC2 KeyPair name: ")
|
27
|
+
|
28
|
+
Cfer.converge! 'instance',
|
29
|
+
template: 'examples/instance.rb',
|
30
|
+
parameters: {
|
31
|
+
:KeyName => key_pair
|
32
|
+
},
|
33
|
+
follow: true
|
34
|
+
end
|
35
|
+
|
36
|
+
task :describe_instance => :config_aws do
|
37
|
+
Cfer.describe! 'instance'
|
38
|
+
end
|
39
|
+
|
40
|
+
task :converge => [:vpc, :instance]
|
41
|
+
|
data/bin/cfer
ADDED
data/bin/cfer-dbg
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
lib = File.expand_path(File.dirname(__FILE__) + '/../lib')
|
3
|
+
$LOAD_PATH.unshift(lib) if File.directory?(lib) && !$LOAD_PATH.include?(lib)
|
4
|
+
|
5
|
+
require 'pry'
|
6
|
+
require 'pry-rescue'
|
7
|
+
|
8
|
+
module Cfer
|
9
|
+
DEBUG = true
|
10
|
+
end
|
11
|
+
|
12
|
+
require 'cfer'
|
13
|
+
|
14
|
+
Cfer::LOGGER.level = Logger::DEBUG
|
15
|
+
|
16
|
+
Cfer::LOGGER.fatal "Showing FATAL logs"
|
17
|
+
Cfer::LOGGER.error "Showing ERROR logs"
|
18
|
+
Cfer::LOGGER.warn "Showing WARN logs"
|
19
|
+
Cfer::LOGGER.info "Showing INFO logs"
|
20
|
+
Cfer::LOGGER.debug "Showing DEBUG logs"
|
21
|
+
|
22
|
+
Pry::rescue {
|
23
|
+
Cfer::Cli::main(ARGV)
|
24
|
+
}
|
25
|
+
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "cfer"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "pry"
|
14
|
+
Pry.start
|
data/bin/setup
ADDED
data/cfer-demo.gif
ADDED
Binary file
|