tfdsl 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 558de3af9e9e0d5739a3b11318662ddcbc973e8b7cd52c3b1c4a3806f45a9267
4
- data.tar.gz: a6de4b68078b31e44f585575e102bc2f88a1880583db63e8ac49dddd251fec5c
3
+ metadata.gz: 87d14dbb280f759b3e8a28be2e70f5893d4d18173245bf612c8ec63c0f70b61e
4
+ data.tar.gz: 902faacd228f429f154b427f03741764b84ac7d23588b85ff15cbc38d78f9099
5
5
  SHA512:
6
- metadata.gz: d136fcaf31c7b1f86619bc7771cc24724a55b09c947966da7cb6708c014b781894dc29643dd67b0983dc85c70fbd5d5a872d438514bb0a297c6783015736d45d
7
- data.tar.gz: 716b456702dc6bf00c960a4d198c0eef420aac2224c9b9657679950185cb140725695783060c5c1b1649996ce2270b15536e91135a05d1499895be0e7bbe61f4
6
+ metadata.gz: bb25b4cba94784ce4da1ffcb584603a4eb0e7abf1ff70e4ad1ca895c0461496374d12a0ce3106920bdc7e26c646ea4664d7eef317ac8c8beb83a36815be4b932
7
+ data.tar.gz: 8eb5b34029b9db9e9bdadaf744667794aa1e2cb0553a204a6ca8961980b9699a694be3c218cdf1bb2919338701c9e1d287cf4f0b1e45a172e6cf25acfad5e89b
data/.rubocop.yml CHANGED
@@ -1,3 +1,5 @@
1
+ Style/ConditionalAssignment:
2
+ Enabled: false
1
3
  Layout/IndentArray:
2
4
  Enabled: false
3
5
  Style/ClassVars:
@@ -6,6 +8,7 @@ Style/ClassVars:
6
8
  Metrics/AbcSize:
7
9
  Exclude:
8
10
  - lib/**/formatter.rb
11
+ - lib/**/data_formatter.rb
9
12
  Metrics/MethodLength:
10
13
  Max: 35
11
14
  Metrics/LineLength:
data/.travis.yml CHANGED
@@ -1,7 +1,9 @@
1
- ---
2
- sudo: false
3
1
  language: ruby
4
- cache: bundler
5
2
  rvm:
6
- - 2.5.3
7
- before_install: gem install bundler -v 1.16.6
3
+ - "2.5.0"
4
+ - "2.6.0"
5
+ sudo: false
6
+ cache: bundler
7
+ script: bundle exec rake $TASK
8
+ env:
9
+ - TASK=test_with_coveralls
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- tfdsl (0.1.0)
4
+ tfdsl (0.1.1)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -10,6 +10,12 @@ GEM
10
10
  coderay (1.1.2)
11
11
  coolline (0.5.0)
12
12
  unicode_utils (~> 1.4)
13
+ coveralls (0.8.22)
14
+ json (>= 1.8, < 3)
15
+ simplecov (~> 0.16.1)
16
+ term-ansicolor (~> 1.3)
17
+ thor (~> 0.19.4)
18
+ tins (~> 1.6)
13
19
  docile (1.3.1)
14
20
  jaro_winkler (1.5.2)
15
21
  json (2.1.0)
@@ -40,6 +46,10 @@ GEM
40
46
  json (>= 1.8, < 3)
41
47
  simplecov-html (~> 0.10.0)
42
48
  simplecov-html (0.10.2)
49
+ term-ansicolor (1.7.1)
50
+ tins (~> 1.0)
51
+ thor (0.19.4)
52
+ tins (1.20.2)
43
53
  unicode-display_width (1.4.1)
44
54
  unicode_utils (1.4.0)
45
55
 
@@ -48,6 +58,7 @@ PLATFORMS
48
58
 
49
59
  DEPENDENCIES
50
60
  bundler (~> 1.16)
61
+ coveralls (~> 0.8)
51
62
  minitest (~> 5.0)
52
63
  pry (~> 0.12)
53
64
  pry-coolline (~> 0.2)
@@ -57,4 +68,4 @@ DEPENDENCIES
57
68
  tfdsl!
58
69
 
59
70
  BUNDLED WITH
60
- 1.16.6
71
+ 1.17.2
data/README.md CHANGED
@@ -1,15 +1,20 @@
1
+ [![Gem Version](https://badge.fury.io/rb/tfdsl.svg)](http://badge.fury.io/rb/tfdsl)
2
+ [![Build Status](https://travis-ci.org/tlopo-ruby/tfdsl.svg?branch=master)](https://travis-ci.org/tlopo-ruby/tfdsl)
3
+ [![Code Climate](https://codeclimate.com/github/tlopo-ruby/tfdsl/badges/gpa.svg)](https://codeclimate.com/github/tlopo-ruby/tfdsl)
4
+ [![Coverage Status](https://coveralls.io/repos/github/tlopo-ruby/tfdsl/badge.svg?branch=master)](https://coveralls.io/github/tlopo-ruby/tfdsl?branch=master)
5
+
1
6
  # TFDSL
2
7
 
3
8
  A Chef like DSL for Terraform.
4
9
 
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.
10
+ Terraform uses 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
11
 
7
12
  ## Installation
8
13
 
9
14
  Add this line to your application's Gemfile:
10
15
 
11
16
  ```ruby
12
- gem 'terraform_dsl'
17
+ gem 'tfdsl'
13
18
  ```
14
19
 
15
20
  And then execute:
@@ -29,7 +34,7 @@ require 'tfdsl'
29
34
  stack = TFDSL.stack do
30
35
  resource 'aws_vpc', 'main' do
31
36
  cidr_block '10.0.0.0/16'
32
- instance_tenacy 'dedicated'
37
+ instance_tenancy 'dedicated'
33
38
  tags do
34
39
  Name 'main'
35
40
  end
@@ -49,6 +54,28 @@ resource "aws_vpc" "main" {
49
54
  }
50
55
  }
51
56
  ```
57
+
58
+ ## Ruby Reserved Words
59
+
60
+ Since some terraform object names use Ruby reserved words, we had to do some slight modifications on how resources are named.
61
+ We use `datasource` for `data` and `tfmodule` for `module`
62
+
63
+ Example:
64
+
65
+ In ruby
66
+ ```ruby
67
+ datasource 'aws_ami', 'web' do
68
+ ...
69
+ end
70
+ ```
71
+ In HCL
72
+ ```hcl
73
+ data 'aws_ami' 'web' {
74
+ ...
75
+ }
76
+ ```
77
+
78
+
52
79
  ## Development
53
80
 
54
81
  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.
data/Rakefile CHANGED
@@ -1,6 +1,7 @@
1
1
  require 'bundler/gem_tasks'
2
2
  require 'rake/testtask'
3
3
  require 'rubocop/rake_task'
4
+ require 'coveralls/rake/task'
4
5
 
5
6
  Rake::TestTask.new(:test) do |t|
6
7
  t.libs << 'test'
@@ -9,4 +10,7 @@ Rake::TestTask.new(:test) do |t|
9
10
  end
10
11
 
11
12
  task default: %i[rubocop test]
13
+ task test_with_coveralls: [:default, 'coveralls:push']
14
+
12
15
  RuboCop::RakeTask.new
16
+ Coveralls::RakeTask.new
@@ -0,0 +1,63 @@
1
+ module TFDSL
2
+ # This will format hash maps, lists and elements in HCL format
3
+ class DataFormatter
4
+ def initialize
5
+ @sio = StringIO.new
6
+ @indent = ' ' * 4
7
+ end
8
+
9
+ def format(input, level = 0, last = false, parent_is_list = false)
10
+ if input.class == Hash
11
+ handle_hash input, level, last, parent_is_list
12
+ elsif input.class == Array
13
+ handle_list input, level, last, parent_is_list
14
+ else
15
+ handle_element input, level, last, parent_is_list
16
+ end
17
+
18
+ return @sio.string if level.zero?
19
+ end
20
+
21
+ def handle_element(input, _level, last, parent_is_list)
22
+ if last
23
+ @sio << %("#{input}"\n)
24
+ elsif parent_is_list
25
+ @sio << %("#{input}",\n)
26
+ else
27
+ @sio << %("#{input}"\n)
28
+ end
29
+ end
30
+
31
+ def handle_list(input, level, _last, _parent_is_list)
32
+ @sio << "[\n#{@indent * (level + 1)}"
33
+ input.each_with_index do |e, i|
34
+ if i == input.size - 1
35
+ format e, level + 1, true, true
36
+ else
37
+ format e, level + 1, false, true
38
+ end
39
+
40
+ @sio << @indent * (level + 1) unless i == input.size - 1
41
+ end
42
+ @sio << "#{@indent * level}]\n"
43
+ end
44
+
45
+ def handle_hash(input, level, last, _parent_is_list)
46
+ @sio << "{\n"
47
+ input.each_with_index do |e, i|
48
+ k, v = e
49
+ @sio << "#{@indent * (level + 1)}#{k} = "
50
+ if i == input.size - 1
51
+ format v, level + 1, true
52
+ else
53
+ format v, level + 1
54
+ end
55
+ end
56
+ if last || level.zero?
57
+ @sio << @indent * level + "}\n"
58
+ else
59
+ @sio << @indent * level + "},\n"
60
+ end
61
+ end
62
+ end
63
+ end
@@ -5,22 +5,14 @@ module TFDSL
5
5
 
6
6
  def list(name, value)
7
7
  template = <<-TEXT.gsub(/^ {6}/, '')
8
- <%=name%> = [
9
- <%-value.each_with_index do |v,index| -%>
10
- "<%=v%>"<%=index != value.size - 1 ? ',' : '' %>
11
- <%-end-%>
12
- ]
8
+ <%=name%> = <%=DataFormatter.new.format value%>
13
9
  TEXT
14
10
  ERB.new(template, nil, '-').result(binding).strip
15
11
  end
16
12
 
17
13
  def map(name, value)
18
14
  template = <<-TEXT.gsub(/^ {6}/, '')
19
- <%=name%> = {
20
- <%-value.each do |k,v| -%>
21
- <%=k%> = "<%=v%>"
22
- <%-end-%>
23
- }
15
+ <%=name%> = <%=DataFormatter.new.format value%>
24
16
  TEXT
25
17
  ERB.new(template, nil, '-').result(binding).strip
26
18
  end
data/lib/tfdsl/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module TFDSL
2
- VERSION = '0.1.0'.freeze
2
+ VERSION = '0.1.1'.freeze
3
3
  end
data/lib/tfdsl.rb CHANGED
@@ -9,6 +9,7 @@ module TFDSL
9
9
  LIB_DIR = "#{__dir__}/tfdsl/".freeze
10
10
 
11
11
  require "#{LIB_DIR}/template"
12
+ require "#{LIB_DIR}/data_formatter"
12
13
  require "#{LIB_DIR}/formatter"
13
14
  require "#{LIB_DIR}/block"
14
15
  require "#{LIB_DIR}/resource"
data/tfdsl.gemspec CHANGED
@@ -32,6 +32,7 @@ Gem::Specification.new do |spec|
32
32
  spec.require_paths = ['lib']
33
33
 
34
34
  spec.add_development_dependency 'bundler', '~> 1.16'
35
+ spec.add_development_dependency 'coveralls', '~> 0.8'
35
36
  spec.add_development_dependency 'minitest', '~> 5.0'
36
37
  spec.add_development_dependency 'pry', '~> 0.12'
37
38
  spec.add_development_dependency 'pry-coolline', '~> 0.2'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tfdsl
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tiago Lopo
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-03-16 00:00:00.000000000 Z
11
+ date: 2019-12-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.16'
27
+ - !ruby/object:Gem::Dependency
28
+ name: coveralls
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.8'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.8'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: minitest
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -128,6 +142,7 @@ files:
128
142
  - bin/setup
129
143
  - lib/tfdsl.rb
130
144
  - lib/tfdsl/block.rb
145
+ - lib/tfdsl/data_formatter.rb
131
146
  - lib/tfdsl/data_source.rb
132
147
  - lib/tfdsl/formatter.rb
133
148
  - lib/tfdsl/locals.rb
@@ -160,8 +175,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
160
175
  - !ruby/object:Gem::Version
161
176
  version: '0'
162
177
  requirements: []
163
- rubyforge_project:
164
- rubygems_version: 2.7.8
178
+ rubygems_version: 3.0.3
165
179
  signing_key:
166
180
  specification_version: 4
167
181
  summary: A chef like DSL for terraform