tfw 0.1.9 → 0.1.14
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/Gemfile.lock +5 -3
- data/README.md +47 -21
- data/lib/tfw.rb +1 -1
- data/lib/tfw/state.rb +14 -12
- data/lib/tfw/version.rb +1 -1
- data/tfw.gemspec +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8bc1a297f3a4298321ef182f415a28d25855a65fb9c221c54733b91baa1087e3
|
4
|
+
data.tar.gz: 2062ad35f45c0939844fabf28cc2b67e7c8e189911b5a73b3885aa7df36aab9f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8521b1c5ae3ca1c671ae43744033a162427abde06084aa7e6f117196c821ea0b425d9e963f7a7333997a19ca53d601804b768348baac3612074a07fcd34f2a94
|
7
|
+
data.tar.gz: 18f7ac5a1b377bb88396577503447fb906232da4376e34ee77eb8072f8c926a4fa906a29f28fd29bf268a7ab27ae08c27548d4845acf7152273267dd762fe1d0
|
data/Gemfile.lock
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
tfw (0.1.
|
5
|
-
tfdsl (= 0.1.
|
4
|
+
tfw (0.1.14)
|
5
|
+
tfdsl (= 0.1.10)
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: https://rubygems.org/
|
@@ -15,6 +15,7 @@ GEM
|
|
15
15
|
term-ansicolor (~> 1.3)
|
16
16
|
thor (~> 0.19.4)
|
17
17
|
tins (~> 1.6)
|
18
|
+
deep_merge (1.2.1)
|
18
19
|
docile (1.3.1)
|
19
20
|
jaro_winkler (1.5.4)
|
20
21
|
json (2.1.0)
|
@@ -43,7 +44,8 @@ GEM
|
|
43
44
|
simplecov-html (0.10.2)
|
44
45
|
term-ansicolor (1.7.1)
|
45
46
|
tins (~> 1.0)
|
46
|
-
tfdsl (0.1.
|
47
|
+
tfdsl (0.1.10)
|
48
|
+
deep_merge (~> 1.2)
|
47
49
|
thor (0.19.4)
|
48
50
|
tins (1.20.2)
|
49
51
|
unicode-display_width (1.6.1)
|
data/README.md
CHANGED
@@ -1,43 +1,69 @@
|
|
1
|
-
#
|
1
|
+
# TFW - Terraform Wrapper
|
2
2
|
|
3
|
-
|
3
|
+
Terraform Wrapper writes terraform configuration using TFDSL (Terraform DSL for Ruby) and invokes the terraform binary.
|
4
4
|
|
5
|
-
|
5
|
+
## Motivation (Short Version)
|
6
|
+
|
7
|
+
Terraform is an excellent tool, but it lacks funcionalities like Loops and Conditionals, actually since version 0.12+ it has loops as meta-arguments which is a hacky implementation in my humble opinion.
|
8
|
+
|
9
|
+
For years I was templating terraform configuration with ERB / Jinja, that's reasonable way to avoid repetition in terraform but it's not very flexible nor reusable.
|
10
|
+
|
11
|
+
The solution was writing a tool which mimics terraform usage but writes configuration in plain Ruby.
|
6
12
|
|
7
|
-
## Installation
|
8
13
|
|
9
|
-
|
14
|
+
## Usage:
|
10
15
|
|
16
|
+
1. let's create a file called `foo.rb`
|
11
17
|
```ruby
|
12
|
-
|
18
|
+
resource 'local_file', 'foo' do
|
19
|
+
content 'foo'
|
20
|
+
filename '/tmp/foo.txt'
|
21
|
+
end
|
13
22
|
```
|
14
23
|
|
15
|
-
|
24
|
+
2. Just like in terrraform, run init and apply
|
25
|
+
```
|
26
|
+
$ tfw init && tfw apply
|
27
|
+
... <omitted output>
|
28
|
+
An execution plan has been generated and is shown below.
|
29
|
+
Resource actions are indicated with the following symbols:
|
30
|
+
+ create
|
16
31
|
|
17
|
-
|
32
|
+
Terraform will perform the following actions:
|
18
33
|
|
19
|
-
|
34
|
+
# local_file.foo will be created
|
35
|
+
+ resource "local_file" "foo" {
|
36
|
+
+ content = "foo"
|
37
|
+
+ directory_permission = "0777"
|
38
|
+
+ file_permission = "0777"
|
39
|
+
+ filename = "/tmp/foo.txt"
|
40
|
+
+ id = (known after apply)
|
41
|
+
}
|
20
42
|
|
21
|
-
|
43
|
+
Plan: 1 to add, 0 to change, 0 to destroy.
|
22
44
|
|
23
|
-
|
45
|
+
Do you want to perform these actions?
|
46
|
+
Terraform will perform the actions described above.
|
47
|
+
Only 'yes' will be accepted to approve.
|
24
48
|
|
25
|
-
|
49
|
+
Enter a value: yes
|
26
50
|
|
27
|
-
|
51
|
+
local_file.foo: Creating...
|
52
|
+
local_file.foo: Creation complete after 0s [id=0beec7b5ea3f0fdbc95d0dd47f3c5bc275da8a33]
|
28
53
|
|
29
|
-
|
54
|
+
Apply complete! Resources: 1 added, 0 changed, 0 destroyed.
|
55
|
+
```
|
30
56
|
|
31
|
-
|
57
|
+
## How it works
|
32
58
|
|
33
|
-
|
59
|
+
TFW will create a subdirectory called `.tfw`, and it will create a file called `.tfw/stack.tf` which is the dynamically generated terraform file, and will invoke terrafom in that directory.
|
34
60
|
|
35
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/tfw. 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.
|
36
61
|
|
37
|
-
##
|
62
|
+
## Installation
|
38
63
|
|
39
|
-
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
40
64
|
|
41
|
-
|
65
|
+
TFW is just a ruby gem and can easily be installed as below:
|
42
66
|
|
43
|
-
|
67
|
+
```bash
|
68
|
+
gem install tfw
|
69
|
+
```
|
data/lib/tfw.rb
CHANGED
@@ -101,7 +101,7 @@ module TFW
|
|
101
101
|
def configure_methods_using_stack(stack)
|
102
102
|
silent_block do
|
103
103
|
# This will trigger warnings as we are redefining methods
|
104
|
-
%w[provider variable locals tfmodule
|
104
|
+
%w[provider variable locals tfmodule datasource resource output terraform].each do |name|
|
105
105
|
TOPLEVEL_BINDING.eval('self').define_singleton_method name do |*args, &block|
|
106
106
|
stack.method(name).call(*args, &block)
|
107
107
|
end
|
data/lib/tfw/state.rb
CHANGED
@@ -1,19 +1,21 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
class
|
5
|
-
|
3
|
+
module TFW
|
4
|
+
# Singleton class to keep the stack
|
5
|
+
class State
|
6
|
+
include Singleton
|
6
7
|
|
7
|
-
|
8
|
-
|
9
|
-
|
8
|
+
def initialize
|
9
|
+
@stack = TFDSL::Stack.new
|
10
|
+
end
|
10
11
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
12
|
+
def stack(&block)
|
13
|
+
@stack.instance_eval(&block) if block_given?
|
14
|
+
@stack
|
15
|
+
end
|
15
16
|
|
16
|
-
|
17
|
-
|
17
|
+
def reset
|
18
|
+
@stack = TFDSL::Stack.new
|
19
|
+
end
|
18
20
|
end
|
19
21
|
end
|
data/lib/tfw/version.rb
CHANGED
data/tfw.gemspec
CHANGED
@@ -35,7 +35,7 @@ Gem::Specification.new do |spec|
|
|
35
35
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
36
36
|
spec.require_paths = ['lib']
|
37
37
|
|
38
|
-
spec.add_dependency 'tfdsl', '0.1.
|
38
|
+
spec.add_dependency 'tfdsl', '0.1.10'
|
39
39
|
|
40
40
|
spec.add_development_dependency 'bundler', '~> 1.17'
|
41
41
|
spec.add_development_dependency 'coveralls', '~> 0.8'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tfw
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.14
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tiago Lopo
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-07-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: tfdsl
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - '='
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 0.1.
|
19
|
+
version: 0.1.10
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - '='
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 0.1.
|
26
|
+
version: 0.1.10
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: bundler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|