tfdsl 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +8 -0
- data/.rubocop.yml +19 -0
- data/.travis.yml +7 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +60 -0
- data/LICENSE.txt +21 -0
- data/README.md +68 -0
- data/Rakefile +12 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/tfdsl/block.rb +44 -0
- data/lib/tfdsl/data_source.rb +4 -0
- data/lib/tfdsl/formatter.rb +72 -0
- data/lib/tfdsl/locals.rb +4 -0
- data/lib/tfdsl/output.rb +4 -0
- data/lib/tfdsl/provider.rb +4 -0
- data/lib/tfdsl/resource.rb +4 -0
- data/lib/tfdsl/stack.rb +25 -0
- data/lib/tfdsl/template.rb +49 -0
- data/lib/tfdsl/terraform.rb +4 -0
- data/lib/tfdsl/tfmodule.rb +4 -0
- data/lib/tfdsl/variable.rb +4 -0
- data/lib/tfdsl/version.rb +3 -0
- data/lib/tfdsl.rb +29 -0
- data/tfdsl.gemspec +41 -0
- metadata +168 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 558de3af9e9e0d5739a3b11318662ddcbc973e8b7cd52c3b1c4a3806f45a9267
|
4
|
+
data.tar.gz: a6de4b68078b31e44f585575e102bc2f88a1880583db63e8ac49dddd251fec5c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d136fcaf31c7b1f86619bc7771cc24724a55b09c947966da7cb6708c014b781894dc29643dd67b0983dc85c70fbd5d5a872d438514bb0a297c6783015736d45d
|
7
|
+
data.tar.gz: 716b456702dc6bf00c960a4d198c0eef420aac2224c9b9657679950185cb140725695783060c5c1b1649996ce2270b15536e91135a05d1499895be0e7bbe61f4
|
data/.gitignore
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
Layout/IndentArray:
|
2
|
+
Enabled: false
|
3
|
+
Style/ClassVars:
|
4
|
+
Exclude:
|
5
|
+
- lib/**/block.rb
|
6
|
+
Metrics/AbcSize:
|
7
|
+
Exclude:
|
8
|
+
- lib/**/formatter.rb
|
9
|
+
Metrics/MethodLength:
|
10
|
+
Max: 35
|
11
|
+
Metrics/LineLength:
|
12
|
+
Max: 120
|
13
|
+
Exclude:
|
14
|
+
- test/**/*
|
15
|
+
Layout/ElseAlignment:
|
16
|
+
Enabled: false
|
17
|
+
Metrics/BlockLength:
|
18
|
+
Exclude:
|
19
|
+
- '*.gemspec'
|
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at tiago_lopo_da_silva@external.mckinsey.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
tfdsl (0.1.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
ast (2.4.0)
|
10
|
+
coderay (1.1.2)
|
11
|
+
coolline (0.5.0)
|
12
|
+
unicode_utils (~> 1.4)
|
13
|
+
docile (1.3.1)
|
14
|
+
jaro_winkler (1.5.2)
|
15
|
+
json (2.1.0)
|
16
|
+
method_source (0.9.2)
|
17
|
+
minitest (5.11.3)
|
18
|
+
parallel (1.13.0)
|
19
|
+
parser (2.6.0.0)
|
20
|
+
ast (~> 2.4.0)
|
21
|
+
powerpack (0.1.2)
|
22
|
+
pry (0.12.2)
|
23
|
+
coderay (~> 1.1.0)
|
24
|
+
method_source (~> 0.9.0)
|
25
|
+
pry-coolline (0.2.5)
|
26
|
+
coolline (~> 0.5)
|
27
|
+
rainbow (3.0.0)
|
28
|
+
rake (10.5.0)
|
29
|
+
rubocop (0.63.1)
|
30
|
+
jaro_winkler (~> 1.5.1)
|
31
|
+
parallel (~> 1.10)
|
32
|
+
parser (>= 2.5, != 2.5.1.1)
|
33
|
+
powerpack (~> 0.1)
|
34
|
+
rainbow (>= 2.2.2, < 4.0)
|
35
|
+
ruby-progressbar (~> 1.7)
|
36
|
+
unicode-display_width (~> 1.4.0)
|
37
|
+
ruby-progressbar (1.10.0)
|
38
|
+
simplecov (0.16.1)
|
39
|
+
docile (~> 1.1)
|
40
|
+
json (>= 1.8, < 3)
|
41
|
+
simplecov-html (~> 0.10.0)
|
42
|
+
simplecov-html (0.10.2)
|
43
|
+
unicode-display_width (1.4.1)
|
44
|
+
unicode_utils (1.4.0)
|
45
|
+
|
46
|
+
PLATFORMS
|
47
|
+
ruby
|
48
|
+
|
49
|
+
DEPENDENCIES
|
50
|
+
bundler (~> 1.16)
|
51
|
+
minitest (~> 5.0)
|
52
|
+
pry (~> 0.12)
|
53
|
+
pry-coolline (~> 0.2)
|
54
|
+
rake (~> 10.0)
|
55
|
+
rubocop (~> 0.63)
|
56
|
+
simplecov (~> 0.16)
|
57
|
+
tfdsl!
|
58
|
+
|
59
|
+
BUNDLED WITH
|
60
|
+
1.16.6
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2019 Tiago Lopo
|
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,68 @@
|
|
1
|
+
# TFDSL
|
2
|
+
|
3
|
+
A Chef like DSL for Terraform.
|
4
|
+
|
5
|
+
Terraform use HCL for its configuration, which is better than json or yaml in my opinion, but still not quite as flexible as Chef DSL, so here it's a chef like DSL for terraform.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'terraform_dsl'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install terraform_dsl
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
A quick usage example
|
26
|
+
```ruby
|
27
|
+
require 'tfdsl'
|
28
|
+
|
29
|
+
stack = TFDSL.stack do
|
30
|
+
resource 'aws_vpc', 'main' do
|
31
|
+
cidr_block '10.0.0.0/16'
|
32
|
+
instance_tenacy 'dedicated'
|
33
|
+
tags do
|
34
|
+
Name 'main'
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
puts stack
|
40
|
+
```
|
41
|
+
The code above will produce the output below:
|
42
|
+
```hcl
|
43
|
+
resource "aws_vpc" "main" {
|
44
|
+
cidr_block = "10.0.0.0/16"
|
45
|
+
instance_tenancy = "dedicated"
|
46
|
+
|
47
|
+
tags = {
|
48
|
+
Name = "main"
|
49
|
+
}
|
50
|
+
}
|
51
|
+
```
|
52
|
+
## Development
|
53
|
+
|
54
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
55
|
+
|
56
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
57
|
+
|
58
|
+
## Contributing
|
59
|
+
|
60
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/terraform_dsl. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
61
|
+
|
62
|
+
## License
|
63
|
+
|
64
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
65
|
+
|
66
|
+
## Code of Conduct
|
67
|
+
|
68
|
+
Everyone interacting in the TerraformDsl project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/terraform_dsl/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
2
|
+
require 'rake/testtask'
|
3
|
+
require 'rubocop/rake_task'
|
4
|
+
|
5
|
+
Rake::TestTask.new(:test) do |t|
|
6
|
+
t.libs << 'test'
|
7
|
+
t.libs << 'lib'
|
8
|
+
t.test_files = FileList['test/**/*_test.rb']
|
9
|
+
end
|
10
|
+
|
11
|
+
task default: %i[rubocop test]
|
12
|
+
RuboCop::RakeTask.new
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'tfdsl'
|
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 'irb'
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/lib/tfdsl/block.rb
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
module TFDSL
|
2
|
+
# This class is the representation of terraform configuration block
|
3
|
+
# https://www.terraform.io/docs/configuration/
|
4
|
+
class Block
|
5
|
+
attr_reader :__type__, :__labels__
|
6
|
+
@@formatter = Formatter.new
|
7
|
+
def initialize(&block)
|
8
|
+
@__blocks__ = []
|
9
|
+
instance_eval(&block) if block_given?
|
10
|
+
end
|
11
|
+
|
12
|
+
def method_missing(method_name, *args, &block)
|
13
|
+
super if [:respond_to_missing?].include? method_name
|
14
|
+
method = method_name.to_s.gsub(/=$/, '')
|
15
|
+
|
16
|
+
if block_given?
|
17
|
+
r = Block.new
|
18
|
+
r.__type__ = method
|
19
|
+
r.__labels__ = args
|
20
|
+
@__blocks__ << r
|
21
|
+
return r.instance_eval(&block)
|
22
|
+
end
|
23
|
+
|
24
|
+
return instance_variable_set "@#{method}", *args unless args.empty?
|
25
|
+
return instance_variable_get "@#{method}" if args.empty?
|
26
|
+
end
|
27
|
+
|
28
|
+
def respond_to_missing?(_method_name, _include_private = true)
|
29
|
+
true
|
30
|
+
end
|
31
|
+
|
32
|
+
def to_tf
|
33
|
+
@@formatter.format self
|
34
|
+
end
|
35
|
+
|
36
|
+
def to_str
|
37
|
+
to_tf
|
38
|
+
end
|
39
|
+
|
40
|
+
def to_s
|
41
|
+
to_tf
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
module TFDSL
|
2
|
+
# Class responsible for formatting the string representation of terraform blocks
|
3
|
+
class Formatter
|
4
|
+
def kind(cls)
|
5
|
+
kinds = {
|
6
|
+
Provider => 'provider',
|
7
|
+
TFModule => 'module',
|
8
|
+
Locals => 'locals',
|
9
|
+
Resource => 'resource',
|
10
|
+
Variable => 'variable',
|
11
|
+
DataSource => 'data',
|
12
|
+
Output => 'output',
|
13
|
+
Terraform => 'terraform'
|
14
|
+
}
|
15
|
+
kinds[cls]
|
16
|
+
end
|
17
|
+
|
18
|
+
def format(tf_block)
|
19
|
+
@depth ||= 0
|
20
|
+
str = []
|
21
|
+
|
22
|
+
if @depth.zero?
|
23
|
+
str << first_line(tf_block)
|
24
|
+
close = true
|
25
|
+
end
|
26
|
+
|
27
|
+
str << local_vars(tf_block) unless local_vars(tf_block).empty?
|
28
|
+
|
29
|
+
str << child_blocks(tf_block) unless tf_block.__blocks__.empty?
|
30
|
+
str[1..-1] = str[1..-1].map { |line| line.gsub(/^/, ' ' * 4) } unless str[1..-1].nil?
|
31
|
+
str << "}\n\n" if close
|
32
|
+
str.join("\n")
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def first_line(tf_block)
|
38
|
+
labels = tf_block.__labels__.nil? ? [] : tf_block.__labels__
|
39
|
+
labels_str = labels.map { |l| %("#{l}") }.join ' '
|
40
|
+
kind = kind tf_block.class
|
41
|
+
type = tf_block.__type__.to_s.empty? ? '' : %( "#{tf_block.__type__}" )
|
42
|
+
"#{kind}#{type}#{labels_str} {"
|
43
|
+
end
|
44
|
+
|
45
|
+
def local_vars(tf_block)
|
46
|
+
str = []
|
47
|
+
tf_block.instance_variables.sort.each do |var_name|
|
48
|
+
next if var_name =~ /@__/
|
49
|
+
|
50
|
+
var = tf_block.instance_variable_get var_name
|
51
|
+
var_name = var_name.to_s.delete('@')
|
52
|
+
str << Template.list(var_name, var) if var.class == Array
|
53
|
+
str << Template.map(var_name, var) if var.class == Hash
|
54
|
+
str << Template.value(var_name, var) unless [Array, Hash].include? var.class
|
55
|
+
end
|
56
|
+
str.join "\n"
|
57
|
+
end
|
58
|
+
|
59
|
+
def child_blocks(tf_block)
|
60
|
+
str = []
|
61
|
+
tf_block.__blocks__.each do |b|
|
62
|
+
@depth += 1
|
63
|
+
indent = ' ' * 4
|
64
|
+
child = Template.child_block b
|
65
|
+
child = child.gsub(/^/, indent) if @depth > 1
|
66
|
+
str << child
|
67
|
+
@depth -= 1
|
68
|
+
end
|
69
|
+
str.join("\n")
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
data/lib/tfdsl/locals.rb
ADDED
data/lib/tfdsl/output.rb
ADDED
data/lib/tfdsl/stack.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
module TFDSL
|
2
|
+
# This class is the representation of a terraform stack, or in another words
|
3
|
+
# is a collection of terraform configuration blocks
|
4
|
+
class Stack
|
5
|
+
def initialize(&block)
|
6
|
+
@objects = []
|
7
|
+
instance_eval(&block) if block_given?
|
8
|
+
end
|
9
|
+
|
10
|
+
%w[Provider Variable Locals TFModule DataSource Resource Output Terraform].each do |word|
|
11
|
+
define_method word.downcase do |type = '', *labels, &b|
|
12
|
+
cls = Object.const_get "TFDSL::#{word}"
|
13
|
+
w = cls.new
|
14
|
+
w.__type__ = type
|
15
|
+
w.__labels__ = labels
|
16
|
+
@objects << w
|
17
|
+
w.instance_eval(&b) unless b.nil?
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def to_s
|
22
|
+
@objects.each_with_object('') { |o, str| str << o }
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
module TFDSL
|
2
|
+
# Collection of small templates to be used on to_s / to_str of blocks
|
3
|
+
module Template
|
4
|
+
module_function
|
5
|
+
|
6
|
+
def list(name, value)
|
7
|
+
template = <<-TEXT.gsub(/^ {6}/, '')
|
8
|
+
<%=name%> = [
|
9
|
+
<%-value.each_with_index do |v,index| -%>
|
10
|
+
"<%=v%>"<%=index != value.size - 1 ? ',' : '' %>
|
11
|
+
<%-end-%>
|
12
|
+
]
|
13
|
+
TEXT
|
14
|
+
ERB.new(template, nil, '-').result(binding).strip
|
15
|
+
end
|
16
|
+
|
17
|
+
def map(name, value)
|
18
|
+
template = <<-TEXT.gsub(/^ {6}/, '')
|
19
|
+
<%=name%> = {
|
20
|
+
<%-value.each do |k,v| -%>
|
21
|
+
<%=k%> = "<%=v%>"
|
22
|
+
<%-end-%>
|
23
|
+
}
|
24
|
+
TEXT
|
25
|
+
ERB.new(template, nil, '-').result(binding).strip
|
26
|
+
end
|
27
|
+
|
28
|
+
def child_block(value)
|
29
|
+
labels = value.__labels__.nil? ? [] : value.__labels__
|
30
|
+
labels_str = labels.map { |l| %("#{l}") }.join ' '
|
31
|
+
type = value.__type__.nil? ? '' : %( #{value.__type__} )
|
32
|
+
template = <<-TEXT.gsub(/^ {6}/, '')
|
33
|
+
<%=type%><%=labels_str%> {
|
34
|
+
<%- unless value.to_s.empty? -%>
|
35
|
+
<%=value.to_tf.strip.gsub(/^/,' ')%>
|
36
|
+
<%- end -%>
|
37
|
+
}
|
38
|
+
TEXT
|
39
|
+
ERB.new(template, nil, '-').result(binding).strip
|
40
|
+
end
|
41
|
+
|
42
|
+
def value(name, value)
|
43
|
+
template = <<-TEXT.gsub(/^ {6}/, '')
|
44
|
+
<%=name%> = "<%=value%>"
|
45
|
+
TEXT
|
46
|
+
ERB.new(template, nil, '-').result(binding).strip
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
data/lib/tfdsl.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'tfdsl/version'
|
2
|
+
require 'yaml'
|
3
|
+
require 'erb'
|
4
|
+
|
5
|
+
# Terraform DSL
|
6
|
+
module TFDSL
|
7
|
+
module_function
|
8
|
+
|
9
|
+
LIB_DIR = "#{__dir__}/tfdsl/".freeze
|
10
|
+
|
11
|
+
require "#{LIB_DIR}/template"
|
12
|
+
require "#{LIB_DIR}/formatter"
|
13
|
+
require "#{LIB_DIR}/block"
|
14
|
+
require "#{LIB_DIR}/resource"
|
15
|
+
require "#{LIB_DIR}/variable"
|
16
|
+
require "#{LIB_DIR}/output"
|
17
|
+
require "#{LIB_DIR}/data_source"
|
18
|
+
require "#{LIB_DIR}/provider"
|
19
|
+
require "#{LIB_DIR}/tfmodule"
|
20
|
+
require "#{LIB_DIR}/locals"
|
21
|
+
require "#{LIB_DIR}/terraform"
|
22
|
+
require "#{LIB_DIR}/stack"
|
23
|
+
|
24
|
+
def stack(&block)
|
25
|
+
Stack.new do
|
26
|
+
instance_eval(&block) if block_given?
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
data/tfdsl.gemspec
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
lib = File.expand_path('lib', __dir__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require 'tfdsl/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = 'tfdsl'
|
7
|
+
spec.version = TFDSL::VERSION
|
8
|
+
spec.authors = ['Tiago Lopo']
|
9
|
+
spec.email = ['tlopo@github.com']
|
10
|
+
|
11
|
+
spec.summary = 'A chef like DSL for terraform'
|
12
|
+
spec.description = 'A chef like DSL for terraform'
|
13
|
+
spec.homepage = 'https://github.com/tlopo-ruby/tfdsl.git'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
17
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
18
|
+
if spec.respond_to?(:metadata)
|
19
|
+
# spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
|
20
|
+
else
|
21
|
+
raise 'RubyGems 2.0 or newer is required to protect against ' \
|
22
|
+
'public gem pushes.'
|
23
|
+
end
|
24
|
+
|
25
|
+
# Specify which files should be added to the gem when it is released.
|
26
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
27
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
28
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
29
|
+
end
|
30
|
+
spec.bindir = 'exe'
|
31
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
32
|
+
spec.require_paths = ['lib']
|
33
|
+
|
34
|
+
spec.add_development_dependency 'bundler', '~> 1.16'
|
35
|
+
spec.add_development_dependency 'minitest', '~> 5.0'
|
36
|
+
spec.add_development_dependency 'pry', '~> 0.12'
|
37
|
+
spec.add_development_dependency 'pry-coolline', '~> 0.2'
|
38
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
39
|
+
spec.add_development_dependency 'rubocop', '~> 0.63'
|
40
|
+
spec.add_development_dependency 'simplecov', '~> 0.16'
|
41
|
+
end
|
metadata
ADDED
@@ -0,0 +1,168 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: tfdsl
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Tiago Lopo
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-03-16 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.16'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.16'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: minitest
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '5.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '5.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: pry
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0.12'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0.12'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: pry-coolline
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0.2'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0.2'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rake
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '10.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '10.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rubocop
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0.63'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0.63'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: simplecov
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0.16'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0.16'
|
111
|
+
description: A chef like DSL for terraform
|
112
|
+
email:
|
113
|
+
- tlopo@github.com
|
114
|
+
executables: []
|
115
|
+
extensions: []
|
116
|
+
extra_rdoc_files: []
|
117
|
+
files:
|
118
|
+
- ".gitignore"
|
119
|
+
- ".rubocop.yml"
|
120
|
+
- ".travis.yml"
|
121
|
+
- CODE_OF_CONDUCT.md
|
122
|
+
- Gemfile
|
123
|
+
- Gemfile.lock
|
124
|
+
- LICENSE.txt
|
125
|
+
- README.md
|
126
|
+
- Rakefile
|
127
|
+
- bin/console
|
128
|
+
- bin/setup
|
129
|
+
- lib/tfdsl.rb
|
130
|
+
- lib/tfdsl/block.rb
|
131
|
+
- lib/tfdsl/data_source.rb
|
132
|
+
- lib/tfdsl/formatter.rb
|
133
|
+
- lib/tfdsl/locals.rb
|
134
|
+
- lib/tfdsl/output.rb
|
135
|
+
- lib/tfdsl/provider.rb
|
136
|
+
- lib/tfdsl/resource.rb
|
137
|
+
- lib/tfdsl/stack.rb
|
138
|
+
- lib/tfdsl/template.rb
|
139
|
+
- lib/tfdsl/terraform.rb
|
140
|
+
- lib/tfdsl/tfmodule.rb
|
141
|
+
- lib/tfdsl/variable.rb
|
142
|
+
- lib/tfdsl/version.rb
|
143
|
+
- tfdsl.gemspec
|
144
|
+
homepage: https://github.com/tlopo-ruby/tfdsl.git
|
145
|
+
licenses:
|
146
|
+
- MIT
|
147
|
+
metadata: {}
|
148
|
+
post_install_message:
|
149
|
+
rdoc_options: []
|
150
|
+
require_paths:
|
151
|
+
- lib
|
152
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
153
|
+
requirements:
|
154
|
+
- - ">="
|
155
|
+
- !ruby/object:Gem::Version
|
156
|
+
version: '0'
|
157
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
158
|
+
requirements:
|
159
|
+
- - ">="
|
160
|
+
- !ruby/object:Gem::Version
|
161
|
+
version: '0'
|
162
|
+
requirements: []
|
163
|
+
rubyforge_project:
|
164
|
+
rubygems_version: 2.7.8
|
165
|
+
signing_key:
|
166
|
+
specification_version: 4
|
167
|
+
summary: A chef like DSL for terraform
|
168
|
+
test_files: []
|