Skip to content

Commit

Permalink
make explicit the use of working_group for state key by passing in at…
Browse files Browse the repository at this point in the history
…mos_working_group as a terraform variable
  • Loading branch information
wr0ngway committed Sep 26, 2018
1 parent 705beda commit 83a581f
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 30 deletions.
6 changes: 1 addition & 5 deletions lib/simplygenius/atmos/terraform_executor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -149,11 +149,6 @@ def setup_backend(skip_backend=false)
if backend_config.present? && ! skip_backend
logger.debug("Writing out terraform state backend config")

# Use a different state file per group
if @working_group
backend_config['key'] = "#{@working_group}-#{backend_config['key']}"
end

backend_type = backend_config.delete("type")

backend = {
Expand Down Expand Up @@ -226,6 +221,7 @@ def write_atmos_vars
atmos_env: Atmos.config.atmos_env,
all_env_names: Atmos.config.all_env_names,
account_ids: Atmos.config.account_hash,
atmos_working_group: @working_group,
atmos_config: atmos_config
}
var_hash = var_hash.merge(Atmos.config.to_h)
Expand Down
26 changes: 1 addition & 25 deletions spec/terraform_executor_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@ module Atmos
expect(vars['atmos_env']).to eq('ops')
expect(vars['all_env_names']).to eq(["ops"])
expect(vars['account_ids']).to eq("ops" => 123)
expect(vars['atmos_working_group']).to eq("default")
expect(vars['atmos_config']['foo']).to eq('bar')
expect(vars['atmos_config']['baz_boo']).to eq('bum')
expect(vars['foo']).to eq('bar')
Expand Down Expand Up @@ -364,31 +365,6 @@ module Atmos
end
end

it "changes backend key to reflect working group" do
within_construct do |c|
c.file('config/atmos.yml', YAML.dump(
'foo' => 'bar',
'providers' => {
'aws' => {
'backend' => {
'type' => "mytype",
'key' => 'foo'
}
}
}
))
Atmos.config = Config.new("ops")
te = described_class.new(process_env: Hash.new, working_group: "bootstrap")
te.send(:setup_backend)

file = File.join(te.send(:tf_recipes_dir), 'atmos-backend.tf.json')
expect(File.exist?(file)).to be true
vars = JSON.parse(File.read(file))
expect(vars['terraform']['backend']['mytype']).
to eq('key' => 'bootstrap-foo')
end
end

it "skips the terraform backend" do
within_construct do |c|
c.file('config/atmos.yml')
Expand Down

0 comments on commit 83a581f

Please sign in to comment.