ruby-terraform 0.4.0 → 0.5.0

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
  SHA1:
3
- metadata.gz: 2502b0fc281c42c5e7b5a8fa6666fdbc6b36f648
4
- data.tar.gz: d1f484f4b8bbe86bac2e2ea05ff466d0a8e3dec5
3
+ metadata.gz: 495ef01318ddc57c37fb25cf6c04c4e9db15cd28
4
+ data.tar.gz: 2809580c9ace7a4af184cb699b0ee94759421767
5
5
  SHA512:
6
- metadata.gz: 9f4387d78ab1320336034fbd08ecfb654486b660ffbe19059e8f13c7f6a4813462708ae06fb609af80e09352c419affe557ee90fb36136aa0d7d7eab927e9736
7
- data.tar.gz: fa88e7da09ac3f2e864424bcaa1bcfa22f35f74fcb1cf1e7a626a69a1c882147ff3b1fcf66244461d3543b82751ee84424e011a624d431dcbcbdea264c9a64b2
6
+ metadata.gz: 9181054e31a60c8c8c21e9f6dc69ce842db9b6eb0b7672ec3b1146e50fe2357ff437c055ade4682b1108661fc85001774ca206b259b4d80513572cdc8280460c
7
+ data.tar.gz: 474597664db46e457dbd770efed5a46d4b34d37017c64663d1da8a21b46b4f31c2632c0220aac216ae0c84ed7f4086f3076e90d1111b1f5c3fab6ae132858930
data/Gemfile.lock CHANGED
@@ -1,13 +1,13 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ruby-terraform (0.4.0)
4
+ ruby-terraform (0.5.0)
5
5
  lino (~> 1.1)
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
9
9
  specs:
10
- concurrent-ruby (1.0.4)
10
+ concurrent-ruby (1.0.5)
11
11
  diff-lcs (1.3)
12
12
  gem-release (0.7.4)
13
13
  hamster (3.0.0)
@@ -42,4 +42,4 @@ DEPENDENCIES
42
42
  ruby-terraform!
43
43
 
44
44
  BUNDLED WITH
45
- 1.14.3
45
+ 1.14.5
data/README.md CHANGED
@@ -1,8 +1,7 @@
1
1
  # RubyTerraform
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/ruby_terraform`. To experiment with that code, run `bin/console` for an interactive prompt.
4
-
5
- TODO: Delete this and the text above, and describe your gem
3
+ A simple wrapper around the Terraform binary to allow execution from within
4
+ a Ruby program or Rakefile.
6
5
 
7
6
  ## Installation
8
7
 
@@ -20,22 +19,198 @@ Or install it yourself as:
20
19
 
21
20
  $ gem install ruby_terraform
22
21
 
22
+
23
23
  ## Usage
24
24
 
25
- TODO: Write usage instructions here
25
+ RubyTerraform needs to know where the terraform binary is located before it
26
+ can do anything. By default, RubyTerraform looks on the path however this can
27
+ be configured with:
28
+
29
+ ```ruby
30
+ RubyTerraform.configure do |config|
31
+ config.binary = 'vendor/terraform/bin/terraform'
32
+ end
33
+ ```
34
+
35
+ In addition, each command that requires the terraform binary (all except
36
+ `clean`) takes a `binary` keyword argument at initialisation that overrides the
37
+ global configuration value.
38
+
39
+ Currently, there is partial support for the following commands:
40
+ * `RubyTerraform::Commands::Clean`: clean up all locally held terraform state
41
+ and modules.
42
+ * `RubyTerraform::Commands::Get`: executes `terraform get`
43
+ * `RubyTerraform::Commands::Apply`: executes `terraform apply`
44
+ * `RubyTerraform::Commands::Destroy`: executes `terraform destroy`
45
+ * `RubyTerraform::Commands::Output`: executes `terraform output`
46
+ * `RubyTerraform::Commands::RemoteConfig`: executes `terraform remote config`
47
+
48
+ ### RubyTerraform::Commands::Clean
49
+
50
+ The clean command can be called in the following ways:
51
+
52
+ ```ruby
53
+ RubyTerraform.clean
54
+ RubyTerraform.clean(directory: 'infra/.terraform')
55
+ RubyTerraform::Commands::Clean.new(base_directory: 'infra').execute
56
+ RubyTerraform::Commands::Clean.new.execute(directory: 'infra/.terraform')
57
+ ```
58
+
59
+ When called, it removes the contents of the .terraform directory in the
60
+ working directory by default. If another directory is specified, it instead
61
+ removes the specified directory. If the base directory is specified, it
62
+ removes the .terraform directory from within the base directory.
63
+
64
+
65
+ ### RubyTerraform::Commands::Get
66
+
67
+ The get command will fetch any modules referenced in the provided terraform
68
+ configuration directory. It can be called in the following ways:
69
+
70
+ ```ruby
71
+ RubyTerraform.get(directory: 'infra/networking')
72
+ RubyTerraforn::Commands::Get.new.execute(directory: 'infra/networking')
73
+ ```
74
+
75
+ The get command supports the following options passed as keyword arguments:
76
+ * `directory`: the directory containing terraform configuration; required.
77
+ * `update`: whether or not already downloaded modules should be updated;
78
+ defaults to `false`.
79
+ * `no_color`: whether or not the output from the command should be in color;
80
+ defaults to `false`.
81
+
82
+
83
+ ### RubyTerraform::Commands::Apply
84
+
85
+ The apply command applies terraform configuration in the provided terraform
86
+ configuration directory. It can be called in the following ways:
87
+
88
+ ```ruby
89
+ RubyTerraform.apply(
90
+ directory: 'infra/networking',
91
+ vars: {
92
+ region: 'eu-central'
93
+ })
94
+ RubyTerraform::Commands::Apply.new.execute(
95
+ directory: 'infra/networking',
96
+ vars: {
97
+ region: 'eu-central'
98
+ })
99
+ ```
100
+
101
+ The apply command supports the following options passed as keyword arguments:
102
+ * `directory`: the directory containing terraform configuration; required.
103
+ * `vars`: a map of vars to be passed in to the terraform configuration.
104
+ * `state`: the path to the state file in which to store state; defaults to
105
+ terraform.tfstate in the working directory or the remote state if configured.
106
+ * `backup`: the path to the backup file in which to store the state backup.
107
+ * `no_backup`: when `true`, no backup file will be written; defaults to `false`.
108
+ * `no_color`: whether or not the output from the command should be in color;
109
+ defaults to `false`.
110
+
111
+
112
+ ### RubyTerraform::Commands::Destroy
113
+
114
+ The destroy command destroys all resources defined in the terraform
115
+ configuration in the provided terraform configuration directory. It can be
116
+ called in the following ways:
117
+
118
+ ```ruby
119
+ RubyTerraform.destroy(
120
+ directory: 'infra/networking',
121
+ vars: {
122
+ region: 'eu-central'
123
+ })
124
+ RubyTerraform::Commands::Destroy.new.execute(
125
+ directory: 'infra/networking',
126
+ vars: {
127
+ region: 'eu-central'
128
+ })
129
+ ```
130
+
131
+ The destroy command supports the following options passed as keyword arguments:
132
+ * `directory`: the directory containing terraform configuration; required.
133
+ * `vars`: a map of vars to be passed in to the terraform configuration.
134
+ * `state`: the path to the state file containing the current state; defaults to
135
+ terraform.tfstate in the working directory or the remote state if configured.
136
+ * `force`: if `true`, the command destroys without prompting the user to confirm
137
+ the destruction; defaults to `false`.
138
+ * `backup`: the path to the backup file in which to store the state backup.
139
+ * `no_backup`: when `true`, no backup file will be written; defaults to `false`.
140
+ * `no_color`: whether or not the output from the command should be in color;
141
+ defaults to `false`.
142
+
143
+
144
+ ### RubyTerraform::Commands::Output
145
+
146
+ The output command retrieves an output from a state file. It can be called in
147
+ the following ways:
148
+
149
+ ```ruby
150
+ RubyTerraform.output(name: 'vpc_id')
151
+ RubyTerraform::Commands::Destroy.new.execute(name: 'vpc_id')
152
+ ```
153
+
154
+ The output command supports the following options passed as keyword arguments:
155
+ * `name`: the name of the output to retrieve; required.
156
+ * `state`: the path to the state file containing the current state; defaults to
157
+ terraform.tfstate in the working directory or the remote state if configured.
158
+ * `no_color`: whether or not the output from the command should be in color;
159
+ defaults to `false`.
160
+
161
+
162
+ ### RubyTerraform::Commands::RemoteConfig
163
+
164
+ The remote config command configures storage of state using a remote backend. It
165
+ can be called in the following ways:
166
+
167
+ ```ruby
168
+ RubyTerraform.remote_config(
169
+ backend: 's3',
170
+ backend_config: {
171
+ bucket: 'example-state-bucket',
172
+ key: 'infra/terraform.tfstate',
173
+ region: 'eu-west-2'
174
+ })
175
+ RubyTerraform::Commands::RemoteConfig.new.execute(
176
+ backend: 's3',
177
+ backend_config: {
178
+ bucket: 'example-state-bucket',
179
+ key: 'infra/terraform.tfstate',
180
+ region: 'eu-west-2'
181
+ })
182
+ ```
183
+
184
+ The remote config command supports the following options passed as keyword
185
+ arguments:
186
+ * `backend`: the type of backend to use; required.
187
+ * `backend_config`: a map of backend specific configuration parameters;
188
+ required.
189
+ * `no_color`: whether or not the output from the command should be in color;
190
+ defaults to `false`.
191
+
26
192
 
27
193
  ## Development
28
194
 
29
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
195
+ After checking out the repo, run `bin/setup` to install dependencies. Then,
196
+ run `rake spec` to run the tests. You can also run `bin/console` for an
197
+ interactive prompt that will allow you to experiment.
30
198
 
31
- 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).
199
+ To install this gem onto your local machine, run `bundle exec rake install`. To
200
+ release a new version, update the version number in `version.rb`, and then run
201
+ `bundle exec rake release`, which will create a git tag for the version, push
202
+ git commits and tags, and push the `.gem` file to
203
+ [rubygems.org](https://rubygems.org).
32
204
 
33
205
  ## Contributing
34
206
 
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/Toby Clemson/ruby_terraform. 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.
207
+ Bug reports and pull requests are welcome on GitHub at
208
+ https://github.com/tobyclemson/ruby_terraform. This project is intended to be a
209
+ safe, welcoming space for collaboration, and contributors are expected to adhere
210
+ to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
36
211
 
37
212
 
38
213
  ## License
39
214
 
40
- The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
41
-
215
+ The gem is available as open source under the terms of the
216
+ [MIT License](http://opensource.org/licenses/MIT).
@@ -0,0 +1,30 @@
1
+ require 'lino'
2
+ require_relative 'base'
3
+
4
+ module RubyTerraform
5
+ module Commands
6
+ class Plan < Base
7
+ def configure_command(builder, opts)
8
+ directory = opts[:directory]
9
+ vars = opts[:vars] || {}
10
+ state = opts[:state]
11
+ plan = opts[:plan]
12
+ destroy = opts[:destroy]
13
+ no_color = opts[:no_color]
14
+
15
+ builder
16
+ .with_subcommand('plan') do |sub|
17
+ vars.each do |key, value|
18
+ sub = sub.with_option('-var', "'#{key}=#{value}'", separator: ' ')
19
+ end
20
+ sub = sub.with_option('-state', state) if state
21
+ sub = sub.with_option('-out', plan) if plan
22
+ sub = sub.with_flag('-destroy') if destroy
23
+ sub = sub.with_flag('-no-color') if no_color
24
+ sub
25
+ end
26
+ .with_argument(directory)
27
+ end
28
+ end
29
+ end
30
+ end
@@ -1,5 +1,6 @@
1
1
  require_relative 'commands/clean'
2
2
  require_relative 'commands/get'
3
+ require_relative 'commands/plan'
3
4
  require_relative 'commands/apply'
4
5
  require_relative 'commands/destroy'
5
6
  require_relative 'commands/output'
@@ -1,3 +1,3 @@
1
1
  module RubyTerraform
2
- VERSION = "0.4.0"
2
+ VERSION = "0.5.0"
3
3
  end
@@ -24,6 +24,10 @@ module RubyTerraform
24
24
  Commands::Get.new.execute(opts)
25
25
  end
26
26
 
27
+ def plan(opts = {})
28
+ Commands::Plan.new.execute(opts)
29
+ end
30
+
27
31
  def apply(opts = {})
28
32
  Commands::Apply.new.execute(opts)
29
33
  end
@@ -39,6 +43,15 @@ module RubyTerraform
39
43
  def output(opts = {})
40
44
  Commands::Output.new.execute(opts)
41
45
  end
46
+
47
+ def output_from_remote(opts)
48
+ output_name = opts[:name]
49
+ remote_opts = opts[:remote]
50
+
51
+ clean
52
+ remote_config(remote_opts)
53
+ output(name: output_name)
54
+ end
42
55
  end
43
56
  extend ClassMethods
44
57
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-terraform
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Toby Clemson
@@ -108,6 +108,7 @@ files:
108
108
  - lib/ruby_terraform/commands/destroy.rb
109
109
  - lib/ruby_terraform/commands/get.rb
110
110
  - lib/ruby_terraform/commands/output.rb
111
+ - lib/ruby_terraform/commands/plan.rb
111
112
  - lib/ruby_terraform/commands/remote_config.rb
112
113
  - lib/ruby_terraform/version.rb
113
114
  - ruby_terraform.gemspec
@@ -131,7 +132,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
131
132
  version: '0'
132
133
  requirements: []
133
134
  rubyforge_project:
134
- rubygems_version: 2.6.6
135
+ rubygems_version: 2.0.14.1
135
136
  signing_key:
136
137
  specification_version: 4
137
138
  summary: A simple Ruby wrapper for invoking Terraform commands.