cfndsl 0.13.1 → 0.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rubocop.yml +4 -0
- data/CHANGELOG.md +17 -2
- data/README.md +23 -0
- data/bin/cfndsl +19 -2
- data/lib/cfndsl/errors.rb +2 -2
- data/lib/cfndsl/version.rb +1 -1
- data/lib/cfnlego.rb +42 -0
- data/lib/cfnlego/cloudformation.erb +21 -0
- data/lib/cfnlego/cloudformation.rb +19 -0
- data/lib/cfnlego/resource.rb +37 -0
- data/spec/cli_spec.rb +3 -0
- data/spec/generate_spec.rb +15 -0
- data/spec/spec_helper.rb +1 -0
- metadata +8 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 17794b4c98827341ca1be479e9b41394e351bf0a
|
4
|
+
data.tar.gz: 96c8c7fb7868190f9e69268c9b0e331671c9ff92
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 140566d5b12c819b586e000deb5c1dca773bc2aecce051935fec314b9c72f3103e976afea2daf058fe61d9a8400e95e2b7ccd4ae7a6356c0239fac23ab287124
|
7
|
+
data.tar.gz: 354452707c917d0db1e41dc98fdddff6aa20f9ba35301a27dbfdd5af643c92e555542353a02142b5f7ea5c51bb3c76e10e1667cb7819ecd0e1501b5a5e743f10
|
data/.rubocop.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,7 +1,22 @@
|
|
1
1
|
# Change Log
|
2
2
|
|
3
|
-
## [0.
|
4
|
-
[Full Changelog](https://github.com/stevenjack/cfndsl/compare/v0.13.
|
3
|
+
## [0.14.0](https://github.com/stevenjack/cfndsl/tree/0.14.0) (2017-06-15)
|
4
|
+
[Full Changelog](https://github.com/stevenjack/cfndsl/compare/v0.13.1...0.14.0)
|
5
|
+
|
6
|
+
**Implemented enhancements:**
|
7
|
+
|
8
|
+
- Adding support for auto generating cloudformation resources [\#326](https://github.com/stevenjack/cfndsl/pull/326) ([elmobp](https://github.com/elmobp))
|
9
|
+
|
10
|
+
**Closed issues:**
|
11
|
+
|
12
|
+
- Error reading specification file on 0.13.0 [\#322](https://github.com/stevenjack/cfndsl/issues/322)
|
13
|
+
|
14
|
+
**Merged pull requests:**
|
15
|
+
|
16
|
+
- Modernize cfndsl executable [\#319](https://github.com/stevenjack/cfndsl/pull/319) ([kornypoet](https://github.com/kornypoet))
|
17
|
+
|
18
|
+
## [v0.13.1](https://github.com/stevenjack/cfndsl/tree/v0.13.1) (2017-05-17)
|
19
|
+
[Full Changelog](https://github.com/stevenjack/cfndsl/compare/v0.13.0...v0.13.1)
|
5
20
|
|
6
21
|
**Implemented enhancements:**
|
7
22
|
|
data/README.md
CHANGED
@@ -434,6 +434,11 @@ Usage: cfndsl [options] FILE
|
|
434
434
|
-D, --define "VARIABLE=VALUE" Directly set local VARIABLE as VALUE
|
435
435
|
-v, --verbose Turn on verbose ouptut
|
436
436
|
-b, --disable-binding Disable binding configuration
|
437
|
+
-g RESOURCE_TYPE,RESOURCE_LOGICAL_NAME,
|
438
|
+
--generate Add resource type and logical name
|
439
|
+
-i, --indent TOKEN Use TOKEN for indent character (default space)
|
440
|
+
-l, --list List supported resources
|
441
|
+
-c, --indent-count [COUNT] Count of characters to use for indenting. (default: 2)
|
437
442
|
-h, --help Display this screen
|
438
443
|
```
|
439
444
|
|
@@ -573,3 +578,21 @@ And then use rake to generate the cloudformation:
|
|
573
578
|
```bash
|
574
579
|
$ bin/rake generate
|
575
580
|
```
|
581
|
+
|
582
|
+
### Generating CloudFormation resources from cfndsl
|
583
|
+
By supplying the -g paramater you are now able to generate cloudformation resources for support objects, for a list of supported resources run cfndsl -l
|
584
|
+
|
585
|
+
Example
|
586
|
+
```
|
587
|
+
cfndsl -g AWS::EC2::EIP,EIP
|
588
|
+
require 'cfndsl'
|
589
|
+
CloudFormation do
|
590
|
+
Description 'auto generated cloudformation cfndsl template'
|
591
|
+
|
592
|
+
EC2_EIP('EIP') do
|
593
|
+
Domain String # http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-ec2-eip.html#cfn-ec2-eip-domain
|
594
|
+
InstanceId String # http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-ec2-eip.html#cfn-ec2-eip-instanceid
|
595
|
+
end
|
596
|
+
end
|
597
|
+
```
|
598
|
+
Many thanks to the base code from cfnlego to make this possible!
|
data/bin/cfndsl
CHANGED
@@ -6,8 +6,9 @@ require 'fileutils'
|
|
6
6
|
require 'json'
|
7
7
|
require 'open-uri'
|
8
8
|
require 'optparse'
|
9
|
+
require 'cfnlego'
|
9
10
|
|
10
|
-
options = {}
|
11
|
+
options = { resources: [] }
|
11
12
|
|
12
13
|
optparse = OptionParser.new do |opts|
|
13
14
|
Version = CfnDsl::VERSION
|
@@ -37,7 +38,8 @@ optparse = OptionParser.new do |opts|
|
|
37
38
|
end
|
38
39
|
|
39
40
|
opts.on('-f', '--format FORMAT', 'Specify the output format (JSON default)') do |format|
|
40
|
-
|
41
|
+
types = %w[json yaml]
|
42
|
+
raise "Format #{format} not supported" unless types.include? format
|
41
43
|
options[:outformat] = format
|
42
44
|
end
|
43
45
|
|
@@ -62,6 +64,16 @@ optparse = OptionParser.new do |opts|
|
|
62
64
|
options[:update_spec] = true
|
63
65
|
end
|
64
66
|
|
67
|
+
opts.on('-g', '--generate RESOURCE_TYPE,RESOURCE_LOGICAL_NAME', 'Add resource type and logical name') do |r|
|
68
|
+
options[:lego] = true
|
69
|
+
options[:resources] << r
|
70
|
+
end
|
71
|
+
|
72
|
+
opts.on('-l', '--list', 'List supported resources') do
|
73
|
+
puts Cfnlego.Resources.sort
|
74
|
+
exit
|
75
|
+
end
|
76
|
+
|
65
77
|
# This displays the help screen, all programs are
|
66
78
|
# assumed to have this option.
|
67
79
|
opts.on('-h', '--help', 'Display this screen') do
|
@@ -80,6 +92,11 @@ if options[:update_spec]
|
|
80
92
|
STDERR.puts "Specification successfully written to #{CfnDsl.specification_file}"
|
81
93
|
end
|
82
94
|
|
95
|
+
if options[:lego]
|
96
|
+
puts Cfnlego.run(options)
|
97
|
+
exit
|
98
|
+
end
|
99
|
+
|
83
100
|
if ARGV.empty?
|
84
101
|
if options[:update_spec]
|
85
102
|
exit 0
|
data/lib/cfndsl/errors.rb
CHANGED
@@ -7,8 +7,8 @@ module CfnDsl
|
|
7
7
|
if idx.nil?
|
8
8
|
@errors.push(err + "\n" + caller.join("\n") + "\n")
|
9
9
|
else
|
10
|
-
m = caller
|
11
|
-
err_loc = m ? m[0] : caller
|
10
|
+
m = caller(idx..idx).first.match(/^.*?:\d+:/)
|
11
|
+
err_loc = m ? m[0] : caller(idx..idx).first
|
12
12
|
|
13
13
|
@errors.push(err_loc + ' ' + err + "\n")
|
14
14
|
end
|
data/lib/cfndsl/version.rb
CHANGED
data/lib/cfnlego.rb
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
require 'erb'
|
3
|
+
require 'cfnlego/cloudformation'
|
4
|
+
require 'cfnlego/resource'
|
5
|
+
require 'net/http'
|
6
|
+
require 'uri'
|
7
|
+
|
8
|
+
# Cfnlego
|
9
|
+
module Cfnlego
|
10
|
+
def self.Resources
|
11
|
+
content = fetch_resource_content
|
12
|
+
supported_resources = JSON.parse(content)
|
13
|
+
resources = []
|
14
|
+
supported_resources['ResourceTypes'].each do |resource, _value|
|
15
|
+
resources << resource
|
16
|
+
end
|
17
|
+
resources
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.fetch_resource_content
|
21
|
+
File.read(CfnDsl.specification_file)
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.run(options)
|
25
|
+
# Constructure Resources
|
26
|
+
resources = []
|
27
|
+
options[:resources].each do |r|
|
28
|
+
/(.*),(.*)/.match(r) do |m|
|
29
|
+
type = m[1]
|
30
|
+
name = m[2]
|
31
|
+
resources << Cfnlego::Resource.new(type, name)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
begin
|
36
|
+
return Cfnlego::CloudFormation.new(resources).render
|
37
|
+
rescue RuntimeError => e
|
38
|
+
$stderr.puts "Error: #{e.message}"
|
39
|
+
end
|
40
|
+
nil
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'cfndsl'
|
2
|
+
CloudFormation do
|
3
|
+
Description '<%= @description %>'
|
4
|
+
<%- @resources.each do |r| -%>
|
5
|
+
<% restype = r.type.split('::').delete_if{|i|i=='AWS'}
|
6
|
+
restype = restype.join('::').gsub('::', '_') %>
|
7
|
+
<%= restype %>('<%= r.name %>') do
|
8
|
+
<%- ps = r.properties -%>
|
9
|
+
<%- ps.keys.each do |p| -%>
|
10
|
+
<%- if !r.properties[p]['PrimitiveType'].nil?
|
11
|
+
type = r.properties[p]['PrimitiveType']
|
12
|
+
elsif r.properties[p]['Type'] == 'List'
|
13
|
+
type = '[List]'
|
14
|
+
else
|
15
|
+
type = r.properties[p]['Type']
|
16
|
+
end -%>
|
17
|
+
<%= p %> <%= type %> # <%= r.properties[p]['Documentation'] %>
|
18
|
+
<%- end -%>
|
19
|
+
end
|
20
|
+
<% end -%>
|
21
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# Cfnlego
|
2
|
+
module Cfnlego
|
3
|
+
# CloudFormation
|
4
|
+
class CloudFormation
|
5
|
+
TEMPLATE = "#{File.dirname(__FILE__)}/cloudformation.erb".freeze
|
6
|
+
|
7
|
+
attr_reader :resources
|
8
|
+
|
9
|
+
def initialize(resources)
|
10
|
+
@description = 'auto generated cloudformation cfndsl template'
|
11
|
+
@resources = resources
|
12
|
+
end
|
13
|
+
|
14
|
+
def render
|
15
|
+
erb = ERB.new(File.read(TEMPLATE), nil, '-')
|
16
|
+
erb.result(binding)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
require 'net/http'
|
3
|
+
require 'uri'
|
4
|
+
|
5
|
+
# Cfnlego
|
6
|
+
module Cfnlego
|
7
|
+
# Resource
|
8
|
+
class Resource
|
9
|
+
attr_reader :type, :name
|
10
|
+
|
11
|
+
def initialize(type, name)
|
12
|
+
@type = type
|
13
|
+
@name = name
|
14
|
+
end
|
15
|
+
|
16
|
+
def attributes
|
17
|
+
definition['Attributes']
|
18
|
+
end
|
19
|
+
|
20
|
+
def properties
|
21
|
+
definition['Properties']
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def definition
|
27
|
+
content = Cfnlego.fetch_resource_content
|
28
|
+
datainput = JSON.parse(content)
|
29
|
+
data = datainput['ResourceTypes']
|
30
|
+
begin
|
31
|
+
@definition ||= data[@type]
|
32
|
+
rescue
|
33
|
+
raise "unknown #{@type}, no matching definition found"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
data/spec/cli_spec.rb
CHANGED
@@ -15,6 +15,9 @@ describe 'cfndsl', type: :aruba do
|
|
15
15
|
-b, --disable-binding Disable binding configuration
|
16
16
|
-s, --specification-file FILE Location of Cloudformation Resource Specification file
|
17
17
|
-u, --update-specification Update the Cloudformation Resource Specification file
|
18
|
+
-g RESOURCE_TYPE,RESOURCE_LOGICAL_NAME,
|
19
|
+
--generate Add resource type and logical name
|
20
|
+
-l, --list List supported resources
|
18
21
|
-h, --help Display this screen
|
19
22
|
USAGE
|
20
23
|
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
describe Cfnlego do
|
3
|
+
let(:template) { Cfnlego.run(resources: ['AWS::EC2::EIP,EIP']) }
|
4
|
+
|
5
|
+
context '#Export' do
|
6
|
+
it 'formats correctly' do
|
7
|
+
output = "require 'cfndsl'\nCloudFormation do\n Description 'auto generated cloudformation cfndsl template'\n\n "
|
8
|
+
output << " EC2_EIP('EIP') do\n Domain String "
|
9
|
+
output << '# http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-ec2-eip.html#cfn-ec2-eip-domain'
|
10
|
+
output << "\n InstanceId String # http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-ec2-eip.html#cfn-ec2-eip-instanceid"
|
11
|
+
output << "\n end\nend\n"
|
12
|
+
expect(template).to eq output
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -13,6 +13,7 @@ require 'cfndsl/globals'
|
|
13
13
|
CfnDsl.specification_file File.expand_path('../../lib/cfndsl/aws/resource_specification.json', __FILE__)
|
14
14
|
# use local fixture for tests
|
15
15
|
require 'cfndsl'
|
16
|
+
require 'cfnlego'
|
16
17
|
|
17
18
|
bindir = File.expand_path('../../bin', __FILE__)
|
18
19
|
ENV['PATH'] = [ENV['PATH'], bindir].join(':')
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cfndsl
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.14.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Steven Jack
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2017-
|
12
|
+
date: 2017-06-15 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -75,6 +75,10 @@ files:
|
|
75
75
|
- lib/cfndsl/types.rb
|
76
76
|
- lib/cfndsl/update_policy.rb
|
77
77
|
- lib/cfndsl/version.rb
|
78
|
+
- lib/cfnlego.rb
|
79
|
+
- lib/cfnlego/cloudformation.erb
|
80
|
+
- lib/cfnlego/cloudformation.rb
|
81
|
+
- lib/cfnlego/resource.rb
|
78
82
|
- sample/autoscale.rb
|
79
83
|
- sample/autoscale.template
|
80
84
|
- sample/autoscale2.rb
|
@@ -106,6 +110,7 @@ files:
|
|
106
110
|
- spec/fixtures/serverless-api.json
|
107
111
|
- spec/fixtures/serverless-function.json
|
108
112
|
- spec/fixtures/test.rb
|
113
|
+
- spec/generate_spec.rb
|
109
114
|
- spec/heat_template_spec.rb
|
110
115
|
- spec/jsonable_spec.rb
|
111
116
|
- spec/metadata_spec.rb
|
@@ -158,6 +163,7 @@ test_files:
|
|
158
163
|
- spec/fixtures/serverless-api.json
|
159
164
|
- spec/fixtures/serverless-function.json
|
160
165
|
- spec/fixtures/test.rb
|
166
|
+
- spec/generate_spec.rb
|
161
167
|
- spec/heat_template_spec.rb
|
162
168
|
- spec/jsonable_spec.rb
|
163
169
|
- spec/metadata_spec.rb
|