tfrb 0.1.2 → 0.1.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: dcf070c3b3ae2566c53df75d4a38a6fdcae411cd0eadaa620062ea0d8c690a91
4
- data.tar.gz: 468e9dbf7423807d1fbe9ccca5ea835394013176848f671451eec28a5d439548
3
+ metadata.gz: 7007bbfc991d6e9b8ee14d9e0a7dc673338b589c1da0afd61c78859c6da2f1ff
4
+ data.tar.gz: ed13eab16dfdbfa573d9c9785a46c9a1d14b90ac3c6b0cc222777397ad40e240
5
5
  SHA512:
6
- metadata.gz: f93320b30f22b5b6101083e3e4d544de336f56abb85d74dbfe1db12e1340b2eb3b48f947b4130fb2156038d57655399895afb73d8dd98c71616b1ef1d7ec85a8
7
- data.tar.gz: 30e8349752c48e7a16cdc11070a752f0f79560aa1d3a8417f5946b2335d4a42db1968f44c49f212ab12cd25202129c99032e6d553a3d54cfbf17d48f68aaeae8
6
+ metadata.gz: 2ff08dde3f046f973a452a8b1752f5fcb9606bf06e2273dc4635def287bce7af92a8451d8d1714245c188a0c28b14e3675eee2fc16df1161c85b3e39340d1073
7
+ data.tar.gz: 6e9112522fe46f57fc4c27f6c4e7ee44aa228695a69dc628bded44b301a88869561b3ffe4a372200083048f997806e5853ff40c3e846c76cc5951bfab63397c3
data/README.md CHANGED
@@ -22,6 +22,34 @@ Or install it yourself as:
22
22
 
23
23
  $ tfrm --help
24
24
 
25
+ ## Configuration
26
+
27
+ tfrb is configured using a `tfrb.rb` file in the current working directory where you run `tfrb` similar to:
28
+
29
+ ::Tfrb::Config[:environment_name] = 'dev'
30
+ ::Tfrb::Config[:path] = ::File.join(::File.dirname(::Chef::Config.environment_path), 'infrastructure')
31
+ ::Tfrb::Config[:temp_path] = ::File.join(::File.dirname(::Chef::Config.environment_path), '.infrastructure')
32
+ ::Tfrb::Config[:files] = ::Chef::Config[:knife][:infrastructure_environments]
33
+
34
+ ::Tfrb::Config[:extra_modules] = [
35
+ Atlas::Aws,
36
+ Atlas::Chef
37
+ ]
38
+
39
+ ::Tfrb::Config[:overrides] = {
40
+ 'provider' => {
41
+ 'aws' => {
42
+ 'access_key' => ::Chef::Config[:knife][:aws_access_key_id],
43
+ 'secret_key' => ::Chef::Config[:knife][:aws_secret_access_key],
44
+ 'token' => ::Chef::Config[:knife][:aws_session_token]
45
+ }
46
+ },
47
+ 'resource' => {}
48
+ }
49
+
50
+ # Require everything in lib/tfrb/resource/
51
+ ::Dir[::File.join(::File.dirname(__FILE__), 'lib', 'tfrb', '*', '*.rb')].each { |file| require file }
52
+
25
53
  ## Development
26
54
 
27
55
  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.
data/lib/tfrb/base.rb CHANGED
@@ -7,7 +7,6 @@ require 'mixlib/shellout'
7
7
  class Tfrb::Base
8
8
  attr_accessor :block
9
9
  attr_accessor :path
10
- attr_accessor :temp_path
11
10
  attr_accessor :local_state_path
12
11
  attr_accessor :environments
13
12
  attr_accessor :state
@@ -21,7 +20,7 @@ class Tfrb::Base
21
20
  @path = Tfrb::Config[:path]
22
21
  @temp_path = File.join(Tfrb::Config[:temp_path], block)
23
22
  Dir.mkdir(@temp_path) unless Dir.exist?(@temp_path)
24
- @local_state_path = File.join(@temp_path, '.terraform', 'local.tfstate')
23
+ @local_state_path = temp_path('.terraform', 'local.tfstate')
25
24
  @environments = environments.each_with_object({}) do |environment, hash|
26
25
  hash[environment] = Tfrb::Block.load(environment)
27
26
  end
@@ -30,9 +29,7 @@ class Tfrb::Base
30
29
 
31
30
  def write!
32
31
  @environments.each do |environment_name, environment|
33
- File.open(File.join(temp_path, "#{environment_name}.tf.json"), 'w') do |file|
34
- file.write(JSON.pretty_generate(environment, indent: ' '))
35
- end
32
+ File.write(temp_path("#{environment_name}.tf.json"), JSON.pretty_generate(environment, indent: ' '))
36
33
  end
37
34
  end
38
35
 
@@ -144,16 +141,17 @@ class Tfrb::Base
144
141
  tf_apply = Mixlib::ShellOut.new('terraform', 'apply', '-auto-approve', 'plan.cache', shell_opts)
145
142
  tf_apply.run_command
146
143
  tf_apply.error!
147
- plan_cache = File.join(temp_path, 'plan.cache')
144
+ plan_cache = temp_path('plan.cache')
148
145
  File.delete(plan_cache) if File.exist?(plan_cache)
149
146
  end
150
147
 
151
148
  def clean!
152
149
  %w(*.tf.json).each do |glob|
153
- Dir.glob(File.join(temp_path, glob)).each do |file|
150
+ Dir.glob(temp_path(glob)).each do |file|
154
151
  File.delete(file) if File.exist?(file)
155
152
  end
156
153
  end
154
+ File.delete(local_state_path) if File.exist?(local_state_path)
157
155
  end
158
156
 
159
157
  def s3_state?
@@ -169,6 +167,10 @@ class Tfrb::Base
169
167
  }
170
168
  end
171
169
 
170
+ def temp_path(*args)
171
+ File.join(@temp_path, *args)
172
+ end
173
+
172
174
  class << self
173
175
  def load(block, environments, skip_import = false, dry_run = false)
174
176
  Tfrb::Resource.load_helpers!
@@ -192,7 +194,7 @@ class Tfrb::Base
192
194
  tfrb.write!
193
195
 
194
196
  # Run terraform init if necessary
195
- tfrb.init! unless Dir.exist?(File.join(tfrb.temp_path, '.terraform'))
197
+ tfrb.init! unless Dir.exist?(tfrb.temp_path('.terraform'))
196
198
 
197
199
  # Load state
198
200
  tfrb.load_state!
@@ -1,9 +1,10 @@
1
1
  module Tfrb::Provider::Aws
2
2
  def self.load(base, environment)
3
3
  if environment.has_key?('provider') && environment['provider'].has_key?('aws')
4
- unless environment['provider']['aws'].has_key?('access_key') || environment['provider']['aws'].has_key?('secret_key')
4
+ unless environment['provider']['aws'].has_key?('access_key') || environment['provider']['aws'].has_key?('secret_key') || environment['provider']['aws'].has_key?('token')
5
5
  environment['provider']['aws']['access_key'] = ENV['AWS_ACCESS_KEY_ID']
6
6
  environment['provider']['aws']['secret_key'] = ENV['AWS_SECRET_ACCESS_KEY']
7
+ environment['provider']['aws']['token'] = ENV['AWS_SESSION_TOKEN']
7
8
  end
8
9
  end
9
10
  end
data/lib/tfrb/resource.rb CHANGED
@@ -37,7 +37,7 @@ module Tfrb::Resource
37
37
  unless tfrb.s3_state?
38
38
  tfrb.state[resource_type] = {} unless tfrb.state.has_key?(resource_type)
39
39
  resources.each do |resource_name, resource|
40
- if ::File.exist?(::File.join(tfrb.temp_path, 'terraform.tfstate')) && !tfrb.state[resource_type].has_key?(resource_name)
40
+ if ::File.exist?(tfrb.temp_path('terraform.tfstate')) && !tfrb.state[resource_type].has_key?(resource_name)
41
41
  printf "\033[1m%s.%s: Loading state...\033[0m\n", resource_type, resource_name
42
42
  state = get_state(tfrb, resource_type, resource_name)
43
43
  tfrb.state[resource_type][resource_name] = state if state && state.keys.size > 0
@@ -113,7 +113,8 @@ module Tfrb::Resource
113
113
  {
114
114
  region: aws_provider['region'],
115
115
  access_key_id: aws_provider['access_key'],
116
- secret_access_key: aws_provider['secret_key']
116
+ secret_access_key: aws_provider['secret_key'],
117
+ session_token: aws_provider['token']
117
118
  }
118
119
  end
119
120
  end
data/lib/tfrb/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Tfrb
2
- VERSION = '0.1.2'
2
+ VERSION = '0.1.3'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tfrb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - 'Matt Kasa
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: exe
12
12
  cert_chain: []
13
- date: 2019-05-02 00:00:00.000000000 Z
13
+ date: 2019-05-08 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: bundler