ruby-terraform 0.65.0.pre.15 → 1.0.0.pre.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +15 -15
- data/README.md +148 -397
- data/Rakefile +25 -0
- data/lib/ruby_terraform.rb +707 -45
- data/lib/ruby_terraform/commands.rb +0 -2
- data/lib/ruby_terraform/commands/apply.rb +7 -7
- data/lib/ruby_terraform/commands/base.rb +4 -1
- data/lib/ruby_terraform/commands/destroy.rb +6 -5
- data/lib/ruby_terraform/commands/force_unlock.rb +6 -4
- data/lib/ruby_terraform/commands/format.rb +8 -4
- data/lib/ruby_terraform/commands/get.rb +6 -4
- data/lib/ruby_terraform/commands/graph.rb +11 -3
- data/lib/ruby_terraform/commands/import.rb +8 -7
- data/lib/ruby_terraform/commands/init.rb +16 -6
- data/lib/ruby_terraform/commands/login.rb +2 -2
- data/lib/ruby_terraform/commands/logout.rb +2 -2
- data/lib/ruby_terraform/commands/output.rb +2 -2
- data/lib/ruby_terraform/commands/plan.rb +6 -3
- data/lib/ruby_terraform/commands/providers.rb +9 -3
- data/lib/ruby_terraform/commands/providers_lock.rb +10 -7
- data/lib/ruby_terraform/commands/providers_mirror.rb +3 -3
- data/lib/ruby_terraform/commands/providers_schema.rb +21 -2
- data/lib/ruby_terraform/commands/refresh.rb +70 -3
- data/lib/ruby_terraform/commands/show.rb +26 -3
- data/lib/ruby_terraform/commands/state_list.rb +54 -3
- data/lib/ruby_terraform/commands/state_move.rb +64 -6
- data/lib/ruby_terraform/commands/state_pull.rb +24 -2
- data/lib/ruby_terraform/commands/state_push.rb +49 -3
- data/lib/ruby_terraform/commands/state_remove.rb +55 -7
- data/lib/ruby_terraform/commands/state_replace_provider.rb +39 -6
- data/lib/ruby_terraform/commands/state_show.rb +26 -2
- data/lib/ruby_terraform/commands/taint.rb +63 -2
- data/lib/ruby_terraform/commands/untaint.rb +55 -2
- data/lib/ruby_terraform/commands/validate.rb +51 -6
- data/lib/ruby_terraform/commands/workspace_delete.rb +29 -7
- data/lib/ruby_terraform/commands/workspace_list.rb +21 -6
- data/lib/ruby_terraform/commands/workspace_new.rb +28 -7
- data/lib/ruby_terraform/commands/workspace_select.rb +23 -7
- data/lib/ruby_terraform/commands/workspace_show.rb +17 -2
- data/lib/ruby_terraform/options.rb +1 -1
- data/lib/ruby_terraform/options/definition.rb +3 -1
- data/lib/ruby_terraform/options/definitions.rb +12 -3
- data/lib/ruby_terraform/options/{common.rb → global.rb} +1 -1
- data/lib/ruby_terraform/options/types.rb +0 -1
- data/lib/ruby_terraform/options/types/flag.rb +8 -4
- data/lib/ruby_terraform/options/types/standard.rb +20 -6
- data/lib/ruby_terraform/version.rb +1 -1
- data/ruby_terraform.gemspec +2 -2
- metadata +9 -12
- data/lib/ruby_terraform/commands/clean.rb +0 -26
- data/lib/ruby_terraform/commands/remote_config.rb +0 -25
- data/lib/ruby_terraform/options/types/base.rb +0 -19
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f8868436d132ce01fabbee0b125f9752f4a0528287cfd4313153092fa2f2dc64
|
4
|
+
data.tar.gz: 5f67d580429c869a9c74346582877385708ce84dce5d80ccb0ecc1f0ad76f143
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8d53024bb998f356b8d11f005a1b28f50c18bb75a82b1feee29a85933f08d94fa66dea767aadb100a65ef7a83b201888b734454e21ddcdcf50daaacd78a0f2b9
|
7
|
+
data.tar.gz: 782938870f9111dd2b1607b4260b78d01f8328a96760888d3b4745344c7cdcc5e9bdc54942ac0464df24e636010e6dd3268ff2325ae2917b2ff4c6b0eb36f1ff
|
data/Gemfile.lock
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
ruby-terraform (0.
|
5
|
-
immutable-struct (
|
6
|
-
lino (
|
4
|
+
ruby-terraform (1.0.0.pre.1)
|
5
|
+
immutable-struct (~> 2.4)
|
6
|
+
lino (~> 2.7)
|
7
7
|
|
8
8
|
GEM
|
9
9
|
remote: https://rubygems.org/
|
10
10
|
specs:
|
11
|
-
activesupport (6.1.3.
|
11
|
+
activesupport (6.1.3.2)
|
12
12
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
13
13
|
i18n (>= 1.6, < 2)
|
14
14
|
minitest (>= 5.1)
|
@@ -22,7 +22,7 @@ GEM
|
|
22
22
|
concurrent-ruby (1.1.8)
|
23
23
|
diff-lcs (1.4.4)
|
24
24
|
docile (1.3.5)
|
25
|
-
excon (0.
|
25
|
+
excon (0.81.0)
|
26
26
|
faker (2.17.0)
|
27
27
|
i18n (>= 1.6, < 2)
|
28
28
|
faraday (1.4.1)
|
@@ -56,7 +56,7 @@ GEM
|
|
56
56
|
i18n (1.8.10)
|
57
57
|
concurrent-ruby (~> 1.0)
|
58
58
|
immutable-struct (2.4.1)
|
59
|
-
lino (2.
|
59
|
+
lino (2.7.0)
|
60
60
|
hamster (~> 3.0)
|
61
61
|
open4 (~> 1.3)
|
62
62
|
listen (3.5.1)
|
@@ -70,12 +70,12 @@ GEM
|
|
70
70
|
notiffany (0.1.3)
|
71
71
|
nenv (~> 0.1)
|
72
72
|
shellany (~> 0.0)
|
73
|
-
octokit (4.
|
73
|
+
octokit (4.21.0)
|
74
74
|
faraday (>= 0.9)
|
75
75
|
sawyer (~> 0.8.0, >= 0.5.3)
|
76
76
|
open4 (1.3.4)
|
77
77
|
parallel (1.20.1)
|
78
|
-
parser (3.0.1.
|
78
|
+
parser (3.0.1.1)
|
79
79
|
ast (~> 2.4.1)
|
80
80
|
pry (0.14.1)
|
81
81
|
coderay (~> 1.1)
|
@@ -121,20 +121,20 @@ GEM
|
|
121
121
|
diff-lcs (>= 1.2.0, < 2.0)
|
122
122
|
rspec-support (~> 3.10.0)
|
123
123
|
rspec-support (3.10.2)
|
124
|
-
rubocop (1.
|
124
|
+
rubocop (1.14.0)
|
125
125
|
parallel (~> 1.10)
|
126
126
|
parser (>= 3.0.0.0)
|
127
127
|
rainbow (>= 2.2.2, < 4.0)
|
128
128
|
regexp_parser (>= 1.8, < 3.0)
|
129
129
|
rexml
|
130
|
-
rubocop-ast (>= 1.
|
130
|
+
rubocop-ast (>= 1.5.0, < 2.0)
|
131
131
|
ruby-progressbar (~> 1.7)
|
132
132
|
unicode-display_width (>= 1.4.0, < 3.0)
|
133
|
-
rubocop-ast (1.
|
134
|
-
parser (>=
|
133
|
+
rubocop-ast (1.5.0)
|
134
|
+
parser (>= 3.0.1.1)
|
135
135
|
rubocop-rake (0.5.1)
|
136
136
|
rubocop
|
137
|
-
rubocop-rspec (2.
|
137
|
+
rubocop-rspec (2.3.0)
|
138
138
|
rubocop (~> 1.0)
|
139
139
|
rubocop-ast (>= 1.1.0)
|
140
140
|
ruby-progressbar (1.11.0)
|
@@ -150,7 +150,7 @@ GEM
|
|
150
150
|
simplecov-html (~> 0.11)
|
151
151
|
simplecov_json_formatter (~> 0.1)
|
152
152
|
simplecov-html (0.12.3)
|
153
|
-
simplecov_json_formatter (0.1.
|
153
|
+
simplecov_json_formatter (0.1.3)
|
154
154
|
sshkey (2.0.0)
|
155
155
|
thor (1.1.0)
|
156
156
|
tzinfo (2.0.4)
|
@@ -182,4 +182,4 @@ DEPENDENCIES
|
|
182
182
|
yard (~> 0.9)
|
183
183
|
|
184
184
|
BUNDLED WITH
|
185
|
-
2.2.
|
185
|
+
2.2.17
|
data/README.md
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# RubyTerraform
|
2
2
|
|
3
3
|
A simple wrapper around the Terraform binary to allow execution from within
|
4
|
-
a Ruby program or Rakefile.
|
4
|
+
a Ruby program, RSpec test or Rakefile.
|
5
5
|
|
6
6
|
|
7
7
|
## Installation
|
@@ -23,451 +23,161 @@ Or install it yourself as:
|
|
23
23
|
|
24
24
|
## Usage
|
25
25
|
|
26
|
-
|
27
|
-
can do anything. By default, RubyTerraform looks on the path however this can
|
28
|
-
be configured with:
|
26
|
+
To require `RubyTerraform`:
|
29
27
|
|
30
28
|
```ruby
|
31
|
-
|
32
|
-
config.binary = 'vendor/terraform/bin/terraform'
|
33
|
-
end
|
29
|
+
require 'ruby-terraform'
|
34
30
|
```
|
35
31
|
|
36
|
-
|
37
|
-
`clean`) takes a `binary` keyword argument at initialisation that overrides the
|
38
|
-
global configuration value.
|
32
|
+
### Supported versions and commands
|
39
33
|
|
40
|
-
|
41
|
-
|
42
|
-
The clean command can be called in the following ways:
|
43
|
-
|
44
|
-
```ruby
|
45
|
-
RubyTerraform.clean
|
46
|
-
RubyTerraform.clean(directory: 'infra/.terraform')
|
47
|
-
RubyTerraform::Commands::Clean.new(directory: 'infra/.terraform').execute
|
48
|
-
RubyTerraform::Commands::Clean.new.execute(directory: 'infra/.terraform')
|
49
|
-
```
|
34
|
+
`RubyTerraform` supports all commands and options up to Terraform 0.15, except
|
35
|
+
`terraform console`, `terraform test` and `terraform version`.
|
50
36
|
|
51
|
-
|
52
|
-
working directory by default. If another directory is specified, it instead
|
53
|
-
removes the specified directory.
|
37
|
+
### Getting started
|
54
38
|
|
39
|
+
There are a couple of ways to call Terraform using `RubyTerraform`.
|
55
40
|
|
56
|
-
|
41
|
+
Firstly, the `RubyTerraform` module includes class methods for each of the
|
42
|
+
supported Terraform commands. Each class method takes a parameter hash
|
43
|
+
containing options to pass to Terraform.
|
57
44
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
```ruby
|
62
|
-
RubyTerraform.init
|
63
|
-
RubyTerraform.init(from_module: 'some/module/path', path: 'infra/module')
|
64
|
-
RubyTerraform::Commands::Init.new.execute
|
65
|
-
RubyTerraform::Commands::Init.new.execute(
|
66
|
-
from_module: 'some/module/path',
|
67
|
-
path: 'infra/module')
|
68
|
-
```
|
69
|
-
|
70
|
-
The init command supports the following options passed as keyword arguments:
|
71
|
-
* `from_module`: the source module to use to initialise; required if `path` is
|
72
|
-
specified
|
73
|
-
* `path`: the path to initialise.
|
74
|
-
* `backend`: `true`/`false`, whether or not to configure the backend.
|
75
|
-
* `get`: `true`/`false`, whether or not to get dependency modules.
|
76
|
-
* `backend_config`: a map of backend specific configuration parameters.
|
77
|
-
* `no_color`: whether or not the output from the command should be in color;
|
78
|
-
defaults to `false`.
|
79
|
-
* `plugin_dir`: directory containing plugin binaries. Overrides all default;
|
80
|
-
search paths for plugins and prevents the automatic installation of plugins.
|
81
|
-
|
82
|
-
|
83
|
-
### RubyTerraform::Commands::Get
|
84
|
-
|
85
|
-
The get command will fetch any modules referenced in the provided terraform
|
86
|
-
configuration directory. It can be called in the following ways:
|
87
|
-
|
88
|
-
```ruby
|
89
|
-
RubyTerraform.get(directory: 'infra/networking')
|
90
|
-
RubyTerraform::Commands::Get.new.execute(directory: 'infra/networking')
|
91
|
-
```
|
92
|
-
|
93
|
-
The get command supports the following options passed as keyword arguments:
|
94
|
-
* `directory`: the directory containing terraform configuration; required.
|
95
|
-
* `update`: whether or not already downloaded modules should be updated;
|
96
|
-
defaults to `false`.
|
97
|
-
* `no_color`: whether or not the output from the command should be in color;
|
98
|
-
defaults to `false`.
|
99
|
-
|
100
|
-
|
101
|
-
### RubyTerraform::Commands::Plan
|
102
|
-
|
103
|
-
The plan command will generate the execution plan in the provided
|
104
|
-
configuration directory. It can be called in the following ways:
|
45
|
+
For example, to save the plan of changes for a Terraform configuration located
|
46
|
+
under `infra/network` to a file called `network.tfplan` whilst providing some
|
47
|
+
vars:
|
105
48
|
|
106
49
|
```ruby
|
107
50
|
RubyTerraform.plan(
|
108
|
-
|
109
|
-
|
110
|
-
region: 'eu-central'
|
111
|
-
})
|
112
|
-
RubyTerraform::Commands::Plan.new.execute(
|
113
|
-
directory: 'infra/networking',
|
51
|
+
chdir: 'infra/network',
|
52
|
+
out: 'network.tfplan',
|
114
53
|
vars: {
|
115
54
|
region: 'eu-central'
|
116
|
-
}
|
55
|
+
},
|
56
|
+
var_file: 'defaults.tfvars'
|
57
|
+
)
|
117
58
|
```
|
118
59
|
|
119
|
-
|
120
|
-
* `directory`: the directory containing terraform configuration; required.
|
121
|
-
* `vars`: a map of vars to be passed in to the terraform configuration.
|
122
|
-
* `var_file`: the path to a terraform var file; if both `var_file` and
|
123
|
-
`var_files` are provided, all var files will be passed to terraform.
|
124
|
-
* `var_files`: an array of paths to terraform var files; if both `var_file` and
|
125
|
-
`var_files` are provided, all var files will be passed to terraform.
|
126
|
-
* `target`: the address of a resource to target; if both `target` and
|
127
|
-
`targets` are provided, all targets will be passed to terraform.
|
128
|
-
* `targets`: and array of resource addresses to target; if both `target` and
|
129
|
-
`targets` are provided, all targets will be passed to terraform.
|
130
|
-
* `state`: the path to the state file in which to store state; defaults to
|
131
|
-
terraform.tfstate in the working directory or the remote state if configured.
|
132
|
-
* `plan`: the name of the file in which to save the generated plan.
|
133
|
-
* `input`: when `false`, will not ask for input for variables not directly set;
|
134
|
-
defaults to `true`.
|
135
|
-
* `destroy`: when `true`, a plan will be generated to destroy all resources
|
136
|
-
managed by the given configuration and state; defaults to `false`.
|
137
|
-
* `no_color`: whether or not the output from the command should be in color;
|
138
|
-
defaults to `false`.
|
139
|
-
|
140
|
-
|
141
|
-
### RubyTerraform::Commands::Apply
|
142
|
-
|
143
|
-
The apply command applies terraform configuration in the provided terraform
|
144
|
-
configuration directory. It can be called in the following ways:
|
60
|
+
To apply the generated plan of changes:
|
145
61
|
|
146
62
|
```ruby
|
147
63
|
RubyTerraform.apply(
|
148
|
-
|
64
|
+
chdir: 'infra/network',
|
65
|
+
plan: 'network.tfplan',
|
149
66
|
vars: {
|
150
67
|
region: 'eu-central'
|
151
|
-
}
|
152
|
-
|
153
|
-
|
154
|
-
vars: {
|
155
|
-
region: 'eu-central'
|
156
|
-
})
|
157
|
-
```
|
158
|
-
|
159
|
-
The apply command supports the following options passed as keyword arguments:
|
160
|
-
* `directory`: the directory containing terraform configuration; required.
|
161
|
-
* `vars`: a map of vars to be passed in to the terraform configuration.
|
162
|
-
* `var_file`: the path to a terraform var file; if both `var_file` and
|
163
|
-
`var_files` are provided, all var files will be passed to terraform.
|
164
|
-
* `var_files`: an array of paths to terraform var files; if both `var_file` and
|
165
|
-
`var_files` are provided, all var files will be passed to terraform.
|
166
|
-
* `target`: the address of a resource to target; if both `target` and
|
167
|
-
`targets` are provided, all targets will be passed to terraform.
|
168
|
-
* `targets`: and array of resource addresses to target; if both `target` and
|
169
|
-
`targets` are provided, all targets will be passed to terraform.
|
170
|
-
* `state`: the path to the state file in which to store state; defaults to
|
171
|
-
terraform.tfstate in the working directory or the remote state if configured.
|
172
|
-
* `backup`: the path to the backup file in which to store the state backup.
|
173
|
-
* `input`: when `false`, will not ask for input for variables not directly set;
|
174
|
-
defaults to `true`.
|
175
|
-
* `no_backup`: when `true`, no backup file will be written; defaults to `false`.
|
176
|
-
* `no_color`: whether or not the output from the command should be in color;
|
177
|
-
defaults to `false`.
|
178
|
-
* `auto_approve`: if `true`, the command applys without prompting the user to
|
179
|
-
confirm the changes; defaults to `false`.
|
180
|
-
|
181
|
-
|
182
|
-
### RubyTerraform::Commands::Show
|
183
|
-
|
184
|
-
The show command produces human-readable output from a state file or a plan
|
185
|
-
file. It can be called in the following ways:
|
186
|
-
|
187
|
-
```ruby
|
188
|
-
RubyTerraform.show(
|
189
|
-
path: 'infra/networking')
|
190
|
-
RubyTerraform::Commands::Show.new.execute(
|
191
|
-
path: 'infra/networking')
|
68
|
+
},
|
69
|
+
var_file: 'defaults.tfvars'
|
70
|
+
)
|
192
71
|
```
|
193
72
|
|
194
|
-
|
195
|
-
* `path`: the path to a state or plan file; required.
|
196
|
-
* `no_color`: whether or not the output from the command should be in color;
|
197
|
-
defaults to `false`.
|
198
|
-
* `module_depth`: the depth of modules to show in the output; defaults to
|
199
|
-
showing all modules.
|
200
|
-
* `json`: whether or not the output from the command should be in json format;
|
201
|
-
defaults to `false`.
|
202
|
-
|
203
|
-
### RubyTerraform::Commands::Destroy
|
204
|
-
|
205
|
-
The destroy command destroys all resources defined in the terraform
|
206
|
-
configuration in the provided terraform configuration directory. It can be
|
207
|
-
called in the following ways:
|
73
|
+
...and to destroy the resulting resources:
|
208
74
|
|
209
75
|
```ruby
|
210
76
|
RubyTerraform.destroy(
|
211
|
-
|
212
|
-
vars: {
|
213
|
-
region: 'eu-central'
|
214
|
-
})
|
215
|
-
RubyTerraform::Commands::Destroy.new.execute(
|
216
|
-
directory: 'infra/networking',
|
77
|
+
chdir: 'infra/network',
|
217
78
|
vars: {
|
218
79
|
region: 'eu-central'
|
219
|
-
}
|
80
|
+
},
|
81
|
+
var_file: 'defaults.tfvars'
|
82
|
+
)
|
220
83
|
```
|
221
84
|
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
`var_files` are provided, all var files will be passed to terraform.
|
227
|
-
* `var_files`: an array of paths to terraform var files; if both `var_file` and
|
228
|
-
`var_files` are provided, all var files will be passed to terraform.
|
229
|
-
* `target`: the address of a resource to target; if both `target` and
|
230
|
-
`targets` are provided, all targets will be passed to terraform.
|
231
|
-
* `targets`: and array of resource addresses to target; if both `target` and
|
232
|
-
`targets` are provided, all targets will be passed to terraform.
|
233
|
-
* `state`: the path to the state file containing the current state; defaults to
|
234
|
-
terraform.tfstate in the working directory or the remote state if configured.
|
235
|
-
* `force`: if `true`, the command destroys without prompting the user to confirm
|
236
|
-
the destruction; defaults to `false`.
|
237
|
-
* `backup`: the path to the backup file in which to store the state backup.
|
238
|
-
* `no_backup`: when `true`, no backup file will be written; defaults to `false`.
|
239
|
-
* `no_color`: whether or not the output from the command should be in color;
|
240
|
-
defaults to `false`.
|
241
|
-
|
242
|
-
|
243
|
-
### RubyTerraform::Commands::Output
|
244
|
-
|
245
|
-
The output command retrieves an output from a state file. It can be called in
|
246
|
-
the following ways:
|
85
|
+
Additionally, `RubyTerraform` allows command instances to be constructed and
|
86
|
+
invoked separately. This is useful when you need to override global
|
87
|
+
configuration on a command by command basis or when you need to pass a command
|
88
|
+
around.
|
247
89
|
|
248
|
-
|
249
|
-
|
250
|
-
RubyTerraform::Commands::Destroy.new.execute(name: 'vpc_id')
|
251
|
-
```
|
252
|
-
|
253
|
-
The output command supports the following options passed as keyword arguments:
|
254
|
-
* `name`: the name of the output to retrieve; required.
|
255
|
-
* `state`: the path to the state file containing the current state; defaults to
|
256
|
-
terraform.tfstate in the working directory or the remote state if configured.
|
257
|
-
* `no_color`: whether or not the output from the command should be in color;
|
258
|
-
defaults to `false`.
|
259
|
-
* `module`: the name of a module to retrieve output from.
|
260
|
-
|
261
|
-
|
262
|
-
### RubyTerraform::Commands::Refresh
|
263
|
-
|
264
|
-
The refresh command will reconcile state with resources found in the target
|
265
|
-
environment. It can be called in the following ways:
|
90
|
+
Using the command class approach, the equivalent plan invocation above can be
|
91
|
+
achieved using:
|
266
92
|
|
267
93
|
```ruby
|
268
|
-
RubyTerraform.
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
})
|
273
|
-
RubyTerraform::Commands::Refresh.new.execute(
|
274
|
-
directory: 'infra/networking',
|
94
|
+
command = RubyTerraform::Commands::Plan.new
|
95
|
+
command.execute(
|
96
|
+
chdir: 'infra/network',
|
97
|
+
out: 'network.tfplan',
|
275
98
|
vars: {
|
276
99
|
region: 'eu-central'
|
277
|
-
}
|
100
|
+
},
|
101
|
+
var_file: 'defaults.tfvars'
|
102
|
+
)
|
278
103
|
```
|
279
104
|
|
280
|
-
|
281
|
-
|
282
|
-
* `vars`: a map of vars to be passed in to the terraform configuration.
|
283
|
-
* `var_file`: the path to a terraform var file; if both `var_file` and
|
284
|
-
`var_files` are provided, all var files will be passed to terraform.
|
285
|
-
* `var_files`: an array of paths to terraform var files; if both `var_file` and
|
286
|
-
`var_files` are provided, all var files will be passed to terraform.
|
287
|
-
* `target`: the address of a resource to target; if both `target` and
|
288
|
-
`targets` are provided, all targets will be passed to terraform.
|
289
|
-
* `targets`: and array of resource addresses to target; if both `target` and
|
290
|
-
`targets` are provided, all targets will be passed to terraform.
|
291
|
-
* `state`: the path to the state file in which to store state; defaults to
|
292
|
-
terraform.tfstate in the working directory or the remote state if configured.
|
293
|
-
* `input`: when `false`, will not ask for input for variables not directly set;
|
294
|
-
defaults to `true`.
|
295
|
-
* `no_color`: whether or not the output from the command should be in color;
|
296
|
-
defaults to `false`.
|
297
|
-
|
298
|
-
|
299
|
-
### RubyTerraform::Commands::Import
|
300
|
-
|
301
|
-
The import command imports existing infrastructure into your terraform state.
|
302
|
-
It can be called in the following ways:
|
105
|
+
See the [API docs](https://infrablocks.github.io/ruby_terraform/index.html) for
|
106
|
+
more details on the supported commands.
|
303
107
|
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
region: 'eu-central'
|
311
|
-
})
|
312
|
-
RubyTerraform::Commands::Import.new.execute(
|
313
|
-
directory: 'infra/networking',
|
314
|
-
address: 'a.resource.address',
|
315
|
-
id: 'a-resource-id',
|
316
|
-
vars: {
|
317
|
-
region: 'eu-central'
|
318
|
-
})
|
319
|
-
```
|
108
|
+
### Parameters
|
109
|
+
|
110
|
+
The parameter hash passed to each command, whether via the class methods or the
|
111
|
+
`#execute` method, supports all the options available on the corresponding
|
112
|
+
Terraform command. There are a few different types of options depending on what
|
113
|
+
Terraform expects to receive:
|
320
114
|
|
321
|
-
|
322
|
-
* `
|
323
|
-
|
324
|
-
* `
|
325
|
-
|
326
|
-
* `
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
defaults to `true`.
|
332
|
-
* `state`: the path to the state file containing the current state; defaults to
|
333
|
-
terraform.tfstate in the working directory or the remote state if configured.
|
334
|
-
* `no_backup`: when `true`, no backup file will be written; defaults to `false`.
|
335
|
-
* `backup`: the path to the backup file in which to store the state backup.
|
336
|
-
* `no_color`: whether or not the output from the command should be in color;
|
337
|
-
defaults to `false`.
|
338
|
-
|
339
|
-
|
340
|
-
### RubyTerraform::Commands::RemoteConfig
|
341
|
-
|
342
|
-
The remote config command configures storage of state using a remote backend. It
|
343
|
-
has been deprecated and since removed from terraform but is retained in this
|
344
|
-
library for backwards compatibility. It can be called in the following ways:
|
115
|
+
* `Boolean` options, accepting `true` or `false`, such as `:input` or `:lock`;
|
116
|
+
* `String` options, accepting a single string value, such as `:state` or
|
117
|
+
`:target`;
|
118
|
+
* `Array<String>` options, accepting an array of strings, such as `:var_files`
|
119
|
+
`:targets`; and
|
120
|
+
* `Hash<String,Object>` options, accepting a hash of key value pairs, where the
|
121
|
+
value might be complex, such as `:vars` and `:backend_config`.
|
122
|
+
|
123
|
+
For all options that allow multiple values, both a singular and a plural option
|
124
|
+
key are supported. For example, to specify multiple var files during a plan:
|
345
125
|
|
346
126
|
```ruby
|
347
|
-
RubyTerraform.
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
})
|
354
|
-
RubyTerraform::Commands::RemoteConfig.new.execute(
|
355
|
-
backend: 's3',
|
356
|
-
backend_config: {
|
357
|
-
bucket: 'example-state-bucket',
|
358
|
-
key: 'infra/terraform.tfstate',
|
359
|
-
region: 'eu-west-2'
|
360
|
-
})
|
127
|
+
RubyTerraform.plan(
|
128
|
+
chdir: 'infra/network',
|
129
|
+
out: 'network.tfplan',
|
130
|
+
var_file: 'defaults.tfvars',
|
131
|
+
var_files: %w[environment.tfvars secrets.tfvars]
|
132
|
+
)
|
361
133
|
```
|
362
134
|
|
363
|
-
|
364
|
-
arguments:
|
365
|
-
* `backend`: the type of backend to use; required.
|
366
|
-
* `backend_config`: a map of backend specific configuration parameters;
|
367
|
-
required.
|
368
|
-
* `no_color`: whether or not the output from the command should be in color;
|
369
|
-
defaults to `false`.
|
135
|
+
In this case, all three var files are passed to Terraform.
|
370
136
|
|
371
|
-
|
137
|
+
Some options have aliases. For example, the `:out` option can also be provided
|
138
|
+
as `:plan` for symmetry with other terraform commands. However, in such
|
139
|
+
situations only one of the aliases should be used in the provided parameters
|
140
|
+
hash.
|
372
141
|
|
373
|
-
|
142
|
+
See the [API docs](https://infrablocks.github.io/ruby_terraform/index.html) for
|
143
|
+
a more complete listing of available parameter options.
|
374
144
|
|
375
|
-
|
376
|
-
RubyTerraform.format(
|
377
|
-
directory: 'infra/networking',
|
378
|
-
vars: {
|
379
|
-
region: 'eu-central'
|
380
|
-
})
|
381
|
-
RubyTerraform::Commands::Format.new.execute(
|
382
|
-
directory: 'infra/networking',
|
383
|
-
vars: {
|
384
|
-
region: 'eu-central'
|
385
|
-
})
|
386
|
-
```
|
145
|
+
### Configuration
|
387
146
|
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
* `list`: Don't list files whose formatting differs;
|
393
|
-
defaults to `false`.
|
394
|
-
* `write`: Don't write to source files;
|
395
|
-
defaults to `false`.
|
396
|
-
* `check`: Checks if the input is formatted, exit status will be 0 if all input is properly formatted and non zero otherwise;
|
397
|
-
defaults to `false`.
|
398
|
-
* `diff`: Displays a diff of the formatting changes;
|
399
|
-
defaults to `false`.
|
400
|
-
* `no_color`: whether or not the output from the command should be in color;
|
401
|
-
defaults to `false`.
|
402
|
-
|
403
|
-
### RubyTerraform::Commands::Validate
|
147
|
+
`RubyTerraform` uses sensible defaults for all configuration options. However,
|
148
|
+
there are a couple of ways to override the defaults when they are sufficient.
|
149
|
+
|
150
|
+
#### Binary
|
404
151
|
|
405
|
-
|
406
|
-
|
152
|
+
By default, `RubyTerraform` looks for the Terraform binary on the system path.
|
153
|
+
To globally configure a specific binary location:
|
407
154
|
|
408
155
|
```ruby
|
409
|
-
RubyTerraform.
|
410
|
-
|
411
|
-
|
412
|
-
region: 'eu-central'
|
413
|
-
})
|
414
|
-
RubyTerraform::Commands::Validate.new.execute(
|
415
|
-
directory: 'infra/networking',
|
416
|
-
vars: {
|
417
|
-
region: 'eu-central'
|
418
|
-
})
|
156
|
+
RubyTerraform.configure do |config|
|
157
|
+
config.binary = 'vendor/terraform/bin/terraform'
|
158
|
+
end
|
419
159
|
```
|
420
160
|
|
421
|
-
|
422
|
-
|
423
|
-
* `vars`: a map of vars to be passed in to the terraform configuration.
|
424
|
-
* `var_file`: the path to a terraform var file; if both `var_file` and
|
425
|
-
`var_files` are provided, all var files will be passed to terraform.
|
426
|
-
* `var_files`: an array of paths to terraform var files; if both `var_file` and
|
427
|
-
`var_files` are provided, all var files will be passed to terraform.
|
428
|
-
* `no_color`: whether or not the output from the command should be in color;
|
429
|
-
defaults to `false`.
|
430
|
-
* `check_variables`: if `true`, the command checks whether all variables have
|
431
|
-
been provided; defaults to `true`.
|
432
|
-
* `json`: whether or not the output from the command should be in json format;
|
433
|
-
defaults to `false`.
|
434
|
-
|
435
|
-
### RubyTerraform::Commands::Workspace
|
436
|
-
|
437
|
-
The `workspace` command configures
|
438
|
-
[Terraform Workspaces](https://www.terraform.io/docs/state/workspaces.html#using-workspaces).
|
439
|
-
It can be used as follows:
|
161
|
+
To configure the Terraform binary on a command by command basis, for example for
|
162
|
+
the `Plan` command:
|
440
163
|
|
441
164
|
```ruby
|
442
|
-
RubyTerraform.
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
165
|
+
command = RubyTerraform::Commands::Plan.new(
|
166
|
+
binary: 'vendor/terraform/bin/terraform'
|
167
|
+
)
|
168
|
+
command.execute(
|
169
|
+
# ...
|
170
|
+
)
|
448
171
|
```
|
449
172
|
|
450
|
-
|
451
|
-
* `directory`: the directory containing terraform configuration, the default is
|
452
|
-
the current path.
|
453
|
-
* `operation`: `list`, `select`, `new` or `delete`. default `list`.
|
454
|
-
* `workspace`: Workspace name.
|
455
|
-
|
456
|
-
|
457
|
-
## Configuration
|
458
|
-
|
459
|
-
In addition to configuring the location of the terraform binary, RubyTerraform
|
460
|
-
offers configuration of logging and standard streams. By default standard
|
461
|
-
streams map to `$stdin`, `$stdout` and `$stderr` and all logging goes to
|
462
|
-
`$stdout`.
|
463
|
-
|
464
|
-
### Logging
|
173
|
+
#### Logging
|
465
174
|
|
466
|
-
By default, RubyTerraform
|
175
|
+
By default, `RubyTerraform` 's own log statements are logged to `$stdout` with
|
176
|
+
level `info`.
|
467
177
|
|
468
|
-
To configure a custom logger:
|
178
|
+
To globally configure a custom logger:
|
469
179
|
|
470
|
-
```
|
180
|
+
```ruby
|
471
181
|
require 'logger'
|
472
182
|
|
473
183
|
logger = Logger.new($stdout)
|
@@ -478,13 +188,13 @@ RubyTerraform.configure do |config|
|
|
478
188
|
end
|
479
189
|
```
|
480
190
|
|
481
|
-
RubyTerraform supports logging to multiple different outputs at once,
|
191
|
+
`RubyTerraform` supports logging to multiple different outputs at once,
|
482
192
|
for example:
|
483
193
|
|
484
|
-
```
|
194
|
+
```ruby
|
485
195
|
require 'logger'
|
486
196
|
|
487
|
-
log_file = Logger::LogDevice.new('/foo/bar.log')
|
197
|
+
log_file = Logger::LogDevice.new('/foo/bar.log')
|
488
198
|
logger = Logger.new(RubyTerraform::MultiIO.new(STDOUT, log_file), level: :debug)
|
489
199
|
|
490
200
|
RubyTerraform.configure do |config|
|
@@ -494,18 +204,37 @@ RubyTerraform.configure do |config|
|
|
494
204
|
config.stderr = logger
|
495
205
|
end
|
496
206
|
```
|
497
|
-
> Creating the Logger with a file this way (using `Logger::LogDevice`),
|
207
|
+
> Creating the Logger with a file this way (using `Logger::LogDevice`),
|
208
|
+
> guarantees that the buffer content will be saved/written, as it sets
|
209
|
+
> **implicit flushing**.
|
210
|
+
|
211
|
+
Configured in this way, any logging performed by `RubyTerraform` will log to
|
212
|
+
both `STDOUT` and the provided `log_file`.
|
213
|
+
|
214
|
+
To configure the logger on a command by command basis, for example for the
|
215
|
+
`Show` command:
|
216
|
+
|
217
|
+
```ruby
|
218
|
+
require 'logger'
|
219
|
+
|
220
|
+
logger = Logger.new($stdout)
|
221
|
+
logger.level = Logger::DEBUG
|
498
222
|
|
499
|
-
|
500
|
-
|
223
|
+
command = RubyTerraform::Commands::Show.new(
|
224
|
+
logger: logger
|
225
|
+
)
|
226
|
+
command.execute(
|
227
|
+
# ...
|
228
|
+
)
|
229
|
+
```
|
501
230
|
|
502
|
-
|
231
|
+
#### Standard streams
|
503
232
|
|
504
|
-
By default, RubyTerraform uses streams `$stdin`, `$stdout` and `$stderr`.
|
233
|
+
By default, `RubyTerraform` uses streams `$stdin`, `$stdout` and `$stderr`.
|
505
234
|
|
506
235
|
To configure custom output and error streams:
|
507
236
|
|
508
|
-
```
|
237
|
+
```ruby
|
509
238
|
log_file = File.open('path/to/some/ruby_terraform.log', 'a')
|
510
239
|
|
511
240
|
RubyTerraform.configure do |config|
|
@@ -518,7 +247,7 @@ In this way, both outputs will be redirected to `log_file`.
|
|
518
247
|
|
519
248
|
Similarly, a custom input stream can be configured:
|
520
249
|
|
521
|
-
```
|
250
|
+
```ruby
|
522
251
|
require 'stringio'
|
523
252
|
|
524
253
|
input = StringIO.new("user\ninput\n")
|
@@ -531,6 +260,28 @@ end
|
|
531
260
|
In this way, terraform can be driven by input from somewhere other than
|
532
261
|
interactive input from the terminal.
|
533
262
|
|
263
|
+
To configure the standard streams on a command by command basis, for example for
|
264
|
+
the `Init` command:
|
265
|
+
|
266
|
+
```ruby
|
267
|
+
require 'logger'
|
268
|
+
|
269
|
+
input = StringIO.new("user\ninput\n")
|
270
|
+
log_file = File.open('path/to/some/ruby_terraform.log', 'a')
|
271
|
+
|
272
|
+
command = RubyTerraform::Commands::Init.new(
|
273
|
+
stdin: input,
|
274
|
+
stdout: log_file,
|
275
|
+
stderr: log_file
|
276
|
+
)
|
277
|
+
command.execute(
|
278
|
+
# ...
|
279
|
+
)
|
280
|
+
```
|
281
|
+
|
282
|
+
## Documentation
|
283
|
+
|
284
|
+
* [API docs](https://infrablocks.github.io/ruby_terraform/index.html)
|
534
285
|
|
535
286
|
## Development
|
536
287
|
|