terraspace 2.2.14 → 2.2.15

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
  SHA256:
3
- metadata.gz: b6aa27ac1150e1d8a655455563ed6b65ebbcb7393c6f93c70cbb2c6940a06b9a
4
- data.tar.gz: d314706f83d8376cfed32d2cf1c96c19e4ce1b8196da53c8f69b93af838dc13c
3
+ metadata.gz: 967dc53b88e3a6e310eb1cac59b9247e54f77e097ee8eb98ab5d129a44550705
4
+ data.tar.gz: 36c77aac237a37b26a96e018f51d6b885528cb69d8ca2bf6f40e8e0c638d4001
5
5
  SHA512:
6
- metadata.gz: dd0e67073071970c300fffe59988b934a72fcb7755d78e5257034c41d963a39395d8a6a379d8cdd536201aa85c8601abcaadeb261afd91fe56b842e0726520a6
7
- data.tar.gz: 8d8bb60a136df285e62014e7a8f40c07d7d9dda3ef7c08fa024fca0bd4dbe0c81f8b902b9b50939127bfb70cd39fa841a9c65a84067f2e9286bd241f4b99bd18
6
+ metadata.gz: 98366017d1a0e256d101d3cbc2361c93f948ec056b39893296a83256efc09e6df8daaf07109a94d539f367932d80f12a5ed1267b84592340bb12232783b9e275
7
+ data.tar.gz: 68c8327b6d66aceeec12dc3ffacc0324df964495cecccbcd37a3e517bbf3ab2c19e49314a2819ff95fc0ce3ac376ee01a5008af8792b34a4098b6ee0171162a1
data/CHANGELOG.md CHANGED
@@ -3,6 +3,15 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  This project *loosely tries* to adhere to [Semantic Versioning](http://semver.org/), even before v1.0.
5
5
 
6
+ ## [2.2.15] - 2023-10-18
7
+ - [#331](https://github.com/boltops-tools/terraspace/pull/331) adding tainting/untainting as a terraspace command
8
+ - [#332](https://github.com/boltops-tools/terraspace/pull/332) terraspace fmt: generalize and pass through fmt option
9
+ - [#333](https://github.com/boltops-tools/terraspace/pull/333) remove unused noop and verbose options
10
+ - [#334](https://github.com/boltops-tools/terraspace/pull/334) fix taint and untaint and support pass through args
11
+ - [#335](https://github.com/boltops-tools/terraspace/pull/335) use tofu fork when available
12
+ - [#336](https://github.com/boltops-tools/terraspace/pull/336) improve tfvars lookup location to include config/stacks/demo/tfvars
13
+ - [#337](https://github.com/boltops-tools/terraspace/pull/337) update cli help examples to config/stacks/demo/tfvars folder
14
+
6
15
  ## [2.2.14] - 2023-09-12
7
16
  - [#329](https://github.com/boltops-tools/terraspace/pull/329) fix terraspace check
8
17
 
@@ -77,11 +77,10 @@ module Terraspace
77
77
  EOL
78
78
  end
79
79
 
80
- # Note opentf is not an official fork yet. Mocked it out for testing.
81
- # Should be ready to swap out the official fork name when it is ready.
82
- BINS = %w[opentf terraform]
80
+ BINS = %w[tofu terraform]
83
81
  @@terraform_bin = nil
84
82
  def terraform_bin
83
+ return ENV['TS_TERRAFORM_BIN'] if ENV['TS_TERRAFORM_BIN']
85
84
  return @@terraform_bin if @@terraform_bin.present?
86
85
  BINS.each do |bin|
87
86
  if Gem.win_platform?
@@ -115,8 +114,8 @@ module Terraspace
115
114
  #
116
115
  # Another example
117
116
  #
118
- # $ opentf --version
119
- # OpenTF v0.12.24
117
+ # $ tofu --version
118
+ # OpenTofu v1.6.0
120
119
  #
121
120
  # Note: The -json option is only available in v0.13+
122
121
  def terraform_version
@@ -2,10 +2,9 @@ class Terraspace::CLI::Fmt
2
2
  class Runner
3
3
  include Terraspace::CLI::Concerns::SourceDirs
4
4
  include Terraspace::Util::Logging
5
- SKIP_PATTERN = /\.skip$/
6
5
 
7
- def initialize(dir)
8
- @dir = dir
6
+ def initialize(dir, options)
7
+ @dir, @options = dir, options
9
8
  end
10
9
 
11
10
  def format!
@@ -13,7 +12,7 @@ class Terraspace::CLI::Fmt
13
12
 
14
13
  exit_status = nil
15
14
  Dir.chdir(@dir) do
16
- skip_rename
15
+ rename_to_skip_fmt
17
16
  begin
18
17
  exit_status = terraform_fmt
19
18
  ensure
@@ -23,7 +22,7 @@ class Terraspace::CLI::Fmt
23
22
  exit_status
24
23
  end
25
24
 
26
- def skip_rename
25
+ def rename_to_skip_fmt
27
26
  tf_files.each do |path|
28
27
  if !skip?(path) && erb?(path)
29
28
  FileUtils.mv(path, "#{path}.skip")
@@ -32,19 +31,29 @@ class Terraspace::CLI::Fmt
32
31
  end
33
32
 
34
33
  def terraform_fmt
35
- sh "#{Terraspace.terraform_bin} fmt"
34
+ sh "#{Terraspace.terraform_bin} fmt #{args}"
35
+ end
36
+
37
+ def args
38
+ mod = nil # not needed here
39
+ pass = Terraspace::Terraform::Args::Pass.new(mod, "fmt", @options)
40
+ pass.args.flatten.join(' ')
36
41
  end
37
42
 
38
43
  def sh(command)
39
44
  logger.debug("=> #{command}")
40
- success = system(command)
41
- unless success
42
- logger.info "WARN: There were some errors running terraform fmt for files in #{@dir}:".color(:yellow)
45
+ system(command)
46
+ case $?.exitstatus
47
+ when 2 # errors fmt
48
+ logger.info "WARN: There were some errors running #{Terraspace.terraform_bin} fmt for files in #{@dir}:".color(:yellow)
43
49
  logger.info "The errors are shown above"
50
+ when 3 # fmt ran and changes were made
51
+ logger.debug "fmt ran and changes were made unless -check or -write=false"
44
52
  end
45
53
  $?.exitstatus
46
54
  end
47
55
 
56
+ SKIP_PATTERN = /\.skip$/
48
57
  def restore_rename
49
58
  tf_files.each do |path|
50
59
  if skip?(path) && erb?(path)
@@ -10,7 +10,7 @@ class Terraspace::CLI
10
10
 
11
11
  @@exit_status = 0
12
12
  def run
13
- logger.info "Formating terraform files"
13
+ logger.info "Formatting terraform files"
14
14
  dirs.each do |dir|
15
15
  exit_status = format(dir)
16
16
  @@exit_status = exit_status if exit_status != 0
@@ -19,7 +19,7 @@ class Terraspace::CLI
19
19
  end
20
20
 
21
21
  def format(dir)
22
- Runner.new(dir).format!
22
+ Runner.new(dir, @options).format!
23
23
  end
24
24
 
25
25
  private
@@ -24,3 +24,13 @@ Format scoping to module or stack types. In case there's a module and stack with
24
24
  Format all, so both modules and stacks:
25
25
 
26
26
  $ terraspace fmt -t all
27
+
28
+ Check format of all source files, but don't fix. Examples:
29
+
30
+ $ terraspace fmt demo -write=false -list
31
+ $ terraspace fmt demo -check
32
+ $ terraspace fmt -write=false -list
33
+
34
+ ## Some Notes
35
+
36
+ The `terraspace fmt` will only format terraform source files that do not have any ERB templating logic in it. It will format the files directly in your source code. IE: app/stacks/demo
@@ -3,5 +3,5 @@
3
3
  $ terraspace seed demo
4
4
  Seeding tfvar files for demo
5
5
  Reading: .terraspace-cache/us-west-2/dev/stacks/demo/variables.tf
6
- create app/stacks/demo/tfvars/dev.tfvars
6
+ create config/stacks/demo/tfvars/dev.tfvars
7
7
  $
@@ -0,0 +1,13 @@
1
+ ## Examples
2
+
3
+ terraspace taint ec2 aws_instance.my_instance
4
+
5
+ Example with output:
6
+
7
+ $ terraspace taint ec2 aws_instance.my_instance
8
+ Building .terraspace-cache/us-east-1/dev/stacks/ec2
9
+ Hook: Running terraspace before build hook.
10
+ Current directory: .terraspace-cache/us-east-1/dev/stacks/ec2
11
+ => terraform taint aws_instance.my_instance
12
+ Resource instance aws_instance.my_instance has been successfully tainted.
13
+ Releasing state lock. This may take a few moments...
@@ -0,0 +1,13 @@
1
+ ## Examples
2
+
3
+ terraspace untaint ec2 aws_instance.my_instance
4
+
5
+ Example with output:
6
+
7
+ $ terraspace taint ec2 aws_instance.my_instance
8
+ Building .terraspace-cache/us-east-1/dev/stacks/ec2
9
+ Hook: Running terraspace before build hook.
10
+ Current directory: .terraspace-cache/us-east-1/dev/stacks/ec2
11
+ => terraform untaint aws_instance.my_instance
12
+ Resource instance aws_instance.my_instance has been successfully untainted.
13
+ Releasing state lock. This may take a few moments...
@@ -0,0 +1,12 @@
1
+ class Terraspace::CLI
2
+ class Taint < Base
3
+ def run
4
+ commander.run
5
+ end
6
+
7
+ def commander
8
+ Commander.new("taint", @options)
9
+ end
10
+ memoize :commander
11
+ end
12
+ end
@@ -0,0 +1,12 @@
1
+ class Terraspace::CLI
2
+ class Untaint < Base
3
+ def run
4
+ commander.run
5
+ end
6
+
7
+ def commander
8
+ Commander.new("untaint", @options)
9
+ end
10
+ memoize :commander
11
+ end
12
+ end
@@ -2,9 +2,6 @@ module Terraspace
2
2
  class CLI < Command
3
3
  include Concern
4
4
 
5
- class_option :verbose, type: :boolean
6
- class_option :noop, type: :boolean
7
-
8
5
  yes_option = Proc.new {
9
6
  option :yes, aliases: :y, type: :boolean, desc: "-auto-approve the terraform apply"
10
7
  }
@@ -111,8 +108,9 @@ module Terraspace
111
108
  desc "fmt", "Run terraform fmt"
112
109
  long_desc Help.text(:fmt)
113
110
  type_option.call
114
- def fmt(mod=nil)
115
- Fmt.new(options.merge(mod: mod)).run
111
+ def fmt(*args)
112
+ mod = args.shift if args.first && !args.first.include?('-')
113
+ Fmt.new(options.merge(mod: mod, args: args)).run
116
114
  end
117
115
 
118
116
  desc "import STACK ADDR ID", "Import existing infrastructure into your Terraform state"
@@ -214,6 +212,12 @@ module Terraspace
214
212
  State.new(options.merge(subcommand: subcommand, mod: mod, rest: rest)).run
215
213
  end
216
214
 
215
+ desc "taint STACK ADDR", "Mark a resource instance as not fully functional."
216
+ long_desc Help.text(:taint)
217
+ def taint(mod, addr, *args)
218
+ Taint.new(options.merge(mod: mod, addr: addr, args: args)).run
219
+ end
220
+
217
221
  desc "test", "Run test."
218
222
  long_desc Help.text(:test)
219
223
  def test
@@ -228,6 +232,12 @@ module Terraspace
228
232
  Commander.new("output", options.merge(mod: mod, args: args)).run
229
233
  end
230
234
 
235
+ desc "untaint STACK ADDR", "Remove the 'tainted' state from a resource instance."
236
+ long_desc Help.text(:untaint)
237
+ def untaint(mod, addr, *args)
238
+ Untaint.new(options.merge(mod: mod, addr: addr, args: args)).run
239
+ end
240
+
231
241
  desc "up STACK", "Deploy infrastructure stack."
232
242
  long_desc Help.text(:up)
233
243
  auto_option.call
@@ -39,9 +39,10 @@ class Terraspace::Compiler::Strategy::Tfvar
39
39
  end
40
40
 
41
41
  def paths
42
- project_paths = full_paths(project_tfvars_dir)
43
- stack_paths = full_paths(stack_tfvars_dir)
44
- paths = (project_paths + stack_paths).uniq
42
+ config_terraform = full_paths(config_terraform_tfvars_dir) # deprecated
43
+ app_stacks = full_paths(app_stacks_tfvars_dir) # deprecated
44
+ config_stacks = full_paths(config_stacks_tfvars_dir) # recommended
45
+ paths = (config_terraform + app_stacks + config_stacks).uniq
45
46
  show_layers(paths)
46
47
  paths.select do |path|
47
48
  File.exist?(path)
@@ -131,27 +132,19 @@ class Terraspace::Compiler::Strategy::Tfvar
131
132
  layers
132
133
  end
133
134
 
134
- def project_tfvars_dir
135
+ # IE: config/terraform/tfvars
136
+ def config_terraform_tfvars_dir
135
137
  "#{Terraspace.root}/config/terraform/tfvars"
136
138
  end
137
139
 
138
- # seed dir takes higher precedence than the tfvars folder within the stack module. Example:
139
- #
140
- # seed/tfvars/stacks/demo (folder must have *.tfvars or *.rb files)
141
- # app/stacks/demo/tfvars
142
- #
143
- # This allows user to take over the tfvars embedded in the stack if they need to. Generally,
144
- # putting tfvars in within the app/stacks/MOD/tfvars folder seems cleaner and easier to follow.
145
- #
146
- # Will also consider app/modules/demo/tfvars. Though modules to be reuseable and stacks is where business logic
147
- # should go.
148
- #
149
- def stack_tfvars_dir
150
- seed_dir = "#{Terraspace.root}/seed/tfvars/#{@mod.build_dir(disable_extra: true)}"
151
- mod_dir = "#{@mod.root}/tfvars"
140
+ # IE: app/stacks/demo/tfvars
141
+ def app_stacks_tfvars_dir
142
+ "#{@mod.root}/tfvars"
143
+ end
152
144
 
153
- empty = Dir.glob("#{seed_dir}/*").empty?
154
- empty ? mod_dir : seed_dir
145
+ # IE: config/stacks/demo/tfvars
146
+ def config_stacks_tfvars_dir
147
+ "#{Terraspace.root}/config/#{@mod.build_dir(disable_extra: true)}/tfvars"
155
148
  end
156
149
 
157
150
  @@shown_layers = {}
@@ -5,30 +5,19 @@ class Terraspace::Seeder
5
5
  end
6
6
 
7
7
  def dest_path
8
- case @options[:where]
9
- when "app"
10
- app_path
11
- when "seed"
12
- seed_path
8
+ if @options[:where] == "app"
9
+ seed_path("app")
13
10
  else
14
- infer_dest_path
11
+ seed_path("config")
15
12
  end
16
13
  end
17
14
 
18
- def infer_dest_path
19
- @mod.type == "stack" ? app_path : seed_path
20
- end
21
-
22
- def app_path
23
- "#{Terraspace.root}/app/#{@mod.build_dir}/tfvars/#{seed_file}.tfvars"
24
- end
25
-
26
- def seed_path
27
- "#{Terraspace.root}/seed/tfvars/#{@mod.build_dir}/#{seed_file}.tfvars"
15
+ def seed_path(folder)
16
+ "#{Terraspace.root}/#{folder}/#{@mod.build_dir(disable_extra: true)}/tfvars/#{seed_file}.tfvars"
28
17
  end
29
18
 
30
19
  def seed_file
31
- @options[:instance] || Terraspace.env
20
+ [Terraspace.app, Terraspace.role, Terraspace.env, Terraspace.extra].compact.join("/")
32
21
  end
33
22
  end
34
23
  end
@@ -121,6 +121,14 @@ module Terraspace::Terraform::Args
121
121
  [@options[:addr], @options[:id]]
122
122
  end
123
123
 
124
+ def taint_args
125
+ [@options[:addr]]
126
+ end
127
+
128
+ def untaint_args
129
+ [@options[:addr]]
130
+ end
131
+
124
132
  def auto_approve_arg
125
133
  @options[:yes] || @options[:auto] ? ["-auto-approve"] : []
126
134
  end
@@ -66,7 +66,7 @@ class Terraspace::Terraform::Tfc::Runs
66
66
  action = discardable?(item) ? "Discarded" : "Cancelled"
67
67
  p = ItemPresenter.new(item)
68
68
  msg = "#{action} #{p.id} #{p.message}" # note id is named run-xxx
69
- logger.info("NOOP: #{msg}") && return if @options[:noop]
69
+ logger.info("NOOP: #{msg}") && return if ENV['NOOP']
70
70
 
71
71
  if discardable?(item)
72
72
  api.runs.discard(id)
@@ -1,3 +1,3 @@
1
1
  module Terraspace
2
- VERSION = "2.2.14"
2
+ VERSION = "2.2.15"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: terraspace
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.14
4
+ version: 2.2.15
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tung Nguyen
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-09-12 00:00:00.000000000 Z
11
+ date: 2023-10-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -599,12 +599,14 @@ files:
599
599
  - lib/terraspace/cli/help/show.md
600
600
  - lib/terraspace/cli/help/state.md
601
601
  - lib/terraspace/cli/help/summary.md
602
+ - lib/terraspace/cli/help/taint.md
602
603
  - lib/terraspace/cli/help/test.md
603
604
  - lib/terraspace/cli/help/tfc/destroy.md
604
605
  - lib/terraspace/cli/help/tfc/list.md
605
606
  - lib/terraspace/cli/help/tfc/runs/list.md
606
607
  - lib/terraspace/cli/help/tfc/runs/prune.md
607
608
  - lib/terraspace/cli/help/tfc/sync.md
609
+ - lib/terraspace/cli/help/untaint.md
608
610
  - lib/terraspace/cli/help/up.md
609
611
  - lib/terraspace/cli/help/validate.md
610
612
  - lib/terraspace/cli/import.rb
@@ -640,10 +642,12 @@ files:
640
642
  - lib/terraspace/cli/setup.rb
641
643
  - lib/terraspace/cli/state.rb
642
644
  - lib/terraspace/cli/summary.rb
645
+ - lib/terraspace/cli/taint.rb
643
646
  - lib/terraspace/cli/test.rb
644
647
  - lib/terraspace/cli/tfc.rb
645
648
  - lib/terraspace/cli/tfc/runs.rb
646
649
  - lib/terraspace/cli/tfc_concern.rb
650
+ - lib/terraspace/cli/untaint.rb
647
651
  - lib/terraspace/cli/up.rb
648
652
  - lib/terraspace/cloud/api.rb
649
653
  - lib/terraspace/cloud/api/cani.rb
@@ -966,7 +970,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
966
970
  - !ruby/object:Gem::Version
967
971
  version: '0'
968
972
  requirements: []
969
- rubygems_version: 3.4.17
973
+ rubygems_version: 3.4.20
970
974
  signing_key:
971
975
  specification_version: 4
972
976
  summary: 'Terraspace: The Terraspace Framework'