terraspace 2.2.13 → 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: f242387d972b87d0666dad454bdb234aa5fbcca7d86a26e375fc4c299552d62e
4
- data.tar.gz: a6e65f5895a931997557240cb3383079de7d3881606aad105557904985f330b0
3
+ metadata.gz: 967dc53b88e3a6e310eb1cac59b9247e54f77e097ee8eb98ab5d129a44550705
4
+ data.tar.gz: 36c77aac237a37b26a96e018f51d6b885528cb69d8ca2bf6f40e8e0c638d4001
5
5
  SHA512:
6
- metadata.gz: a605f54903b5ec72bb2d6af4c1d5bb2b8cc1b7a2a5581e1cd4c9b8f9af5c803841c827933cc901428d874ab38808f1f0097418f643e9a6da05212fab46f3f7dc
7
- data.tar.gz: ca57e137d5187fc481f9fd46a221aff1f2599c3d69f0f914bd7e701cc9e5a67603d8966f88ac14e78a9fb39913cbe2ab2bb595f9751a3f79ad7ab2a6ee46011a
6
+ metadata.gz: 98366017d1a0e256d101d3cbc2361c93f948ec056b39893296a83256efc09e6df8daaf07109a94d539f367932d80f12a5ed1267b84592340bb12232783b9e275
7
+ data.tar.gz: 68c8327b6d66aceeec12dc3ffacc0324df964495cecccbcd37a3e517bbf3ab2c19e49314a2819ff95fc0ce3ac376ee01a5008af8792b34a4098b6ee0171162a1
data/CHANGELOG.md CHANGED
@@ -3,6 +3,18 @@
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
+
15
+ ## [2.2.14] - 2023-09-12
16
+ - [#329](https://github.com/boltops-tools/terraspace/pull/329) fix terraspace check
17
+
6
18
  ## [2.2.13] - 2023-08-23
7
19
  - [#327](https://github.com/boltops-tools/terraspace/pull/327) terraspace check improvements: only show check when fails
8
20
 
@@ -38,9 +38,9 @@ module Terraspace
38
38
  See: https://terraspace.cloud/docs/terraform/license/
39
39
  EOL
40
40
 
41
- puts "ERROR: #{name} requires Terraform between v#{@min_terraform_version}.x and #{@max_terraform_version}".color(:red)
41
+ puts "ERROR: #{name} requires Terraform between #{@min_terraform_version}.x and #{@max_terraform_version}".color(:red)
42
42
  puts <<~EOL
43
- This is because newer versions of Terraform has a BSL license
43
+ This is because newer versions of Terraform have a BSL license
44
44
  If your usage is allowed by the license, you can bypass this check with:
45
45
 
46
46
  export TS_VERSION_CHECK=0
@@ -62,6 +62,7 @@ module Terraspace
62
62
  min_ok = major > min_major ||
63
63
  (major == min_major && minor >= min_minor)
64
64
  max_ok = major < max_major ||
65
+ (major == max_major && minor < max_minor) ||
65
66
  (major == max_major && minor == max_minor && patch <= max_patch)
66
67
 
67
68
  min_ok && max_ok
@@ -76,11 +77,10 @@ module Terraspace
76
77
  EOL
77
78
  end
78
79
 
79
- # Note opentf is not an official fork yet. Mocked it out for testing.
80
- # Should be ready to swap out the official fork name when it is ready.
81
- BINS = %w[opentf terraform]
80
+ BINS = %w[tofu terraform]
82
81
  @@terraform_bin = nil
83
82
  def terraform_bin
83
+ return ENV['TS_TERRAFORM_BIN'] if ENV['TS_TERRAFORM_BIN']
84
84
  return @@terraform_bin if @@terraform_bin.present?
85
85
  BINS.each do |bin|
86
86
  if Gem.win_platform?
@@ -114,8 +114,8 @@ module Terraspace
114
114
  #
115
115
  # Another example
116
116
  #
117
- # $ opentf --version
118
- # OpenTF v0.12.24
117
+ # $ tofu --version
118
+ # OpenTofu v1.6.0
119
119
  #
120
120
  # Note: The -json option is only available in v0.13+
121
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.13"
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.13
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-08-23 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'