ruby-terraform 0.65.0.pre.12 → 1.0.0

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.
Files changed (53) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +23 -17
  3. data/README.md +148 -414
  4. data/Rakefile +25 -0
  5. data/lib/ruby_terraform.rb +1365 -41
  6. data/lib/ruby_terraform/commands.rb +0 -2
  7. data/lib/ruby_terraform/commands/apply.rb +78 -4
  8. data/lib/ruby_terraform/commands/base.rb +13 -2
  9. data/lib/ruby_terraform/commands/destroy.rb +71 -4
  10. data/lib/ruby_terraform/commands/force_unlock.rb +33 -3
  11. data/lib/ruby_terraform/commands/format.rb +45 -2
  12. data/lib/ruby_terraform/commands/get.rb +35 -2
  13. data/lib/ruby_terraform/commands/graph.rb +48 -2
  14. data/lib/ruby_terraform/commands/import.rb +98 -3
  15. data/lib/ruby_terraform/commands/init.rb +84 -3
  16. data/lib/ruby_terraform/commands/login.rb +26 -2
  17. data/lib/ruby_terraform/commands/logout.rb +23 -2
  18. data/lib/ruby_terraform/commands/output.rb +34 -2
  19. data/lib/ruby_terraform/commands/plan.rb +72 -3
  20. data/lib/ruby_terraform/commands/providers.rb +30 -2
  21. data/lib/ruby_terraform/commands/providers_lock.rb +72 -3
  22. data/lib/ruby_terraform/commands/providers_mirror.rb +44 -2
  23. data/lib/ruby_terraform/commands/providers_schema.rb +21 -2
  24. data/lib/ruby_terraform/commands/refresh.rb +70 -3
  25. data/lib/ruby_terraform/commands/show.rb +26 -3
  26. data/lib/ruby_terraform/commands/state_list.rb +54 -3
  27. data/lib/ruby_terraform/commands/state_move.rb +64 -6
  28. data/lib/ruby_terraform/commands/state_pull.rb +24 -2
  29. data/lib/ruby_terraform/commands/state_push.rb +49 -3
  30. data/lib/ruby_terraform/commands/state_remove.rb +55 -7
  31. data/lib/ruby_terraform/commands/state_replace_provider.rb +39 -6
  32. data/lib/ruby_terraform/commands/state_show.rb +26 -2
  33. data/lib/ruby_terraform/commands/taint.rb +63 -2
  34. data/lib/ruby_terraform/commands/untaint.rb +55 -2
  35. data/lib/ruby_terraform/commands/validate.rb +51 -6
  36. data/lib/ruby_terraform/commands/workspace_delete.rb +29 -7
  37. data/lib/ruby_terraform/commands/workspace_list.rb +21 -6
  38. data/lib/ruby_terraform/commands/workspace_new.rb +28 -7
  39. data/lib/ruby_terraform/commands/workspace_select.rb +23 -7
  40. data/lib/ruby_terraform/commands/workspace_show.rb +17 -2
  41. data/lib/ruby_terraform/options.rb +1 -1
  42. data/lib/ruby_terraform/options/definition.rb +6 -2
  43. data/lib/ruby_terraform/options/definitions.rb +12 -3
  44. data/lib/ruby_terraform/options/{common.rb → global.rb} +2 -1
  45. data/lib/ruby_terraform/options/types.rb +0 -1
  46. data/lib/ruby_terraform/options/types/flag.rb +8 -4
  47. data/lib/ruby_terraform/options/types/standard.rb +20 -6
  48. data/lib/ruby_terraform/version.rb +1 -1
  49. data/ruby_terraform.gemspec +3 -2
  50. metadata +25 -14
  51. data/lib/ruby_terraform/commands/clean.rb +0 -26
  52. data/lib/ruby_terraform/commands/remote_config.rb +0 -25
  53. data/lib/ruby_terraform/options/types/base.rb +0 -19
@@ -1,7 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative 'commands/apply'
4
- require_relative 'commands/clean'
5
4
  require_relative 'commands/destroy'
6
5
  require_relative 'commands/force_unlock'
7
6
  require_relative 'commands/format'
@@ -18,7 +17,6 @@ require_relative 'commands/providers_lock'
18
17
  require_relative 'commands/providers_mirror'
19
18
  require_relative 'commands/providers_schema'
20
19
  require_relative 'commands/refresh'
21
- require_relative 'commands/remote_config'
22
20
  require_relative 'commands/show'
23
21
  require_relative 'commands/state_list'
24
22
  require_relative 'commands/state_move'
@@ -1,25 +1,94 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative 'base'
4
- require_relative '../options/common'
4
+ require_relative '../options/global'
5
5
 
6
6
  module RubyTerraform
7
7
  module Commands
8
+ # Wraps the +terraform apply+ command which creates or updates
9
+ # infrastructure according to terraform configuration files in the provided
10
+ # directory.
11
+ #
12
+ # By default, terraform will generate a new plan and present it for approval
13
+ # before taking any action. Alternatively, the command accepts a plan file
14
+ # created by a previous invocation, in which case terraform will take the
15
+ # actions described in that plan without any confirmation prompt.
16
+ #
17
+ # For options accepted on construction, see {#initialize}.
18
+ #
19
+ # When executing an instance of {Apply} via {#execute}, the following
20
+ # options are supported:
21
+ #
22
+ # * +:directory+: the path to a directory containing terraform
23
+ # configuration (deprecated in terraform 0.14, removed in terraform 0.15,
24
+ # use +:chdir+ instead).
25
+ # * +:plan+: the path to a pre-computed plan to be applied.
26
+ # * +:chdir+: the path of a working directory to switch to before executing
27
+ # the given subcommand.
28
+ # * +:auto_approve+: if +true+, skips interactive approval of the generated
29
+ # plan before applying; defaults to +false+.
30
+ # * +:backup+: the path to backup the existing state file before modifying;
31
+ # defaults to the +:state_out+ path with +".backup"+ extension; set
32
+ # +:no_backup+ to +true+ to skip backups entirely.
33
+ # * +:compact_warnings+: when +true+, if terraform produces any warnings
34
+ # that are not accompanied by errors, they are shown in a more compact
35
+ # form that includes only the summary messages; defaults to +false+.
36
+ # * +:input+: when +false+, will not ask for input for variables not
37
+ # directly set; defaults to +true+.
38
+ # * +:lock+: when +true+, locks the state file when locking is supported;
39
+ # when +false+, does not lock the state file; defaults to +true+.
40
+ # * +:lock_timeout+: the duration to retry a state lock; defaults to +"0s"+.
41
+ # * +:no_backup+: when +true+, no backup file will be written; defaults to
42
+ # +false+.
43
+ # * +:no_color+: whether or not the output from the command should be in
44
+ # color; defaults to +false+.
45
+ # * +:parallelism+: the number of parallel resource operations; defaults to
46
+ # +10+.
47
+ # * +:refresh+: when +true+, updates state prior to checking for
48
+ # differences; when +false+ uses locally available state; defaults to
49
+ # +true+; this has no effect when +:plan+ is provided.
50
+ # * +:state+: the path to the state file from which to read state and in
51
+ # which to store state (unless +:state_out+ is specified); defaults to
52
+ # +"terraform.tfstate"+.
53
+ # * +:state_out+: the path to write state to that is different than
54
+ # +:state+; this can be used to preserve the old state.
55
+ # * +:target+: the address of a resource to target; if both +:target+ and
56
+ # +:targets+ are provided, all targets will be passed to terraform.
57
+ # * +:targets+: an array of resource addresses to target; if both +:target+
58
+ # and +:targets+ are provided, all targets will be passed to terraform.
59
+ # * +:vars+: a map of variables to be passed to the terraform configuration.
60
+ # * +:var_file+: the path to a terraform var file; if both +:var_file+ and
61
+ # +:var_files+ are provided, all var files will be passed to terraform.
62
+ # * +:var_files+: an array of paths to terraform var files; if both
63
+ # +:var_file+ and +:var_files+ are provided, all var files will be passed
64
+ # to terraform.
65
+ #
66
+ # @example Basic Invocation
67
+ # RubyTerraform::Commands::Apply.new.execute(
68
+ # directory: 'infra/networking',
69
+ # vars: {
70
+ # region: 'eu-central'
71
+ # })
72
+ #
8
73
  class Apply < Base
9
- include RubyTerraform::Options::Common
74
+ include RubyTerraform::Options::Global
10
75
 
76
+ # @!visibility private
11
77
  def subcommands
12
78
  %w[apply]
13
79
  end
14
80
 
15
- def options # rubocop:disable Metrics/MethodLength
81
+ # rubocop:disable Metrics/MethodLength
82
+
83
+ # @!visibility private
84
+ def options
16
85
  %w[
86
+ -auto-approve
17
87
  -backup
18
88
  -compact-warnings
19
89
  -lock
20
90
  -lock-timeout
21
91
  -input
22
- -auto-approve
23
92
  -no-color
24
93
  -parallelism
25
94
  -refresh
@@ -31,14 +100,19 @@ module RubyTerraform
31
100
  ] + super
32
101
  end
33
102
 
103
+ # rubocop:enable Metrics/MethodLength
104
+
105
+ # @!visibility private
34
106
  def arguments(parameters)
35
107
  [parameters[:plan] || parameters[:directory]]
36
108
  end
37
109
 
110
+ # @!visibility private
38
111
  def parameter_defaults(_parameters)
39
112
  { vars: {}, var_files: [], targets: [] }
40
113
  end
41
114
 
115
+ # @!visibility private
42
116
  def parameter_overrides(parameters)
43
117
  { backup: parameters[:no_backup] ? '-' : parameters[:backup] }
44
118
  end
@@ -7,7 +7,11 @@ require_relative '../errors'
7
7
  module RubyTerraform
8
8
  module Commands
9
9
  class Base
10
- def initialize(**opts) # rubocop:disable Metrics/AbcSize
10
+ # rubocop:disable Metrics/AbcSize
11
+
12
+ # Constructs an instance of the command.
13
+ #
14
+ def initialize(**opts)
11
15
  @binary = opts[:binary] || RubyTerraform.configuration.binary
12
16
  @logger = opts[:logger] || RubyTerraform.configuration.logger
13
17
  @options = opts[:options] || RubyTerraform.configuration.options
@@ -16,6 +20,13 @@ module RubyTerraform
16
20
  @stderr = opts[:stderr] || RubyTerraform.configuration.stderr
17
21
  end
18
22
 
23
+ # rubocop:enable Metrics/AbcSize
24
+
25
+ # Executes the command instance.
26
+ #
27
+ # @param [Hash<String, Object>] parameters The parameters used to
28
+ # invoke the command. See subclass documentation for details of
29
+ # supported options.
19
30
  def execute(parameters = {})
20
31
  do_before(parameters)
21
32
  build_and_execute_command(parameters)
@@ -60,7 +71,7 @@ module RubyTerraform
60
71
  .with_option_separator('=')
61
72
  .with_appliables(@options.resolve(options, parameters))
62
73
  .with_subcommands(subcommands)
63
- .with_arguments(arguments(parameters)).build
74
+ .with_arguments(arguments(parameters).compact.flatten).build
64
75
  end
65
76
 
66
77
  def resolve_parameters(parameters)
@@ -1,25 +1,87 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative 'base'
4
- require_relative '../options/common'
4
+ require_relative '../options/global'
5
5
 
6
6
  module RubyTerraform
7
7
  module Commands
8
+ # Wraps the +terraform destroy+ command which destroys terraform managed
9
+ # infrastructure.
10
+ #
11
+ # For options accepted on construction, see {#initialize}.
12
+ #
13
+ # When executing an instance of {Destroy} via {#execute}, the following
14
+ # options are supported:
15
+ #
16
+ # * +:directory+: the path to a directory containing terraform
17
+ # configuration (deprecated in terraform 0.14, removed in terraform 0.15,
18
+ # use +:chdir+ instead).
19
+ # * +:chdir+: the path of a working directory to switch to before executing
20
+ # the given subcommand.
21
+ # * +:auto_approve+: if +true+, skips interactive approval before
22
+ # destroying; defaults to +false+.
23
+ # * +:backup+: (legacy) the path to backup the existing state file before
24
+ # modifying; defaults to the +:state_out+ path with +".backup"+ extension;
25
+ # set +:no_backup+ to +true+ to skip backups entirely.
26
+ # * +:compact_warnings+: when +true+, if terraform produces any warnings
27
+ # that are not accompanied by errors, they are shown in a more compact
28
+ # form that includes only the summary messages; defaults to +false+.
29
+ # * +:input+: when +false+, will not ask for input for variables not
30
+ # directly set; defaults to +true+.
31
+ # * +:lock+: when +true+, locks the state file when locking is supported;
32
+ # when +false+, does not lock the state file; defaults to +true+.
33
+ # * +:lock_timeout+: the duration to retry a state lock; defaults to +"0s"+.
34
+ # * +:no_backup+: when +true+, no backup file will be written; defaults to
35
+ # +false+.
36
+ # * +:no_color+: whether or not the output from the command should be in
37
+ # color; defaults to +false+.
38
+ # * +:parallelism+: the number of parallel resource operations; defaults to
39
+ # +10+.
40
+ # * +:refresh+: when +true+, updates state prior to checking for
41
+ # differences; when +false+ uses locally available state; defaults to
42
+ # +true+.
43
+ # * +:state+: (legacy) the path to the state file from which to read state
44
+ # and in which to store state (unless +:state_out+ is specified); defaults
45
+ # to +"terraform.tfstate"+.
46
+ # * +:state_out+: (legacy) the path to write state to that is different than
47
+ # +:state+; this can be used to preserve the old state.
48
+ # * +:target+: the address of a resource to target; if both +:target+ and
49
+ # +:targets+ are provided, all targets will be passed to terraform.
50
+ # * +:targets+: an array of resource addresses to target; if both +:target+
51
+ # and +:targets+ are provided, all targets will be passed to terraform.
52
+ # * +:vars+: a map of variables to be passed to the terraform configuration.
53
+ # * +:var_file+: the path to a terraform var file; if both +:var_file+ and
54
+ # +:var_files+ are provided, all var files will be passed to terraform.
55
+ # * +:var_files+: an array of paths to terraform var files; if both
56
+ # +:var_file+ and +:var_files+ are provided, all var files will be passed
57
+ # to terraform.
58
+ #
59
+ # @example Basic Invocation
60
+ # RubyTerraform::Commands::Destroy.new.execute(
61
+ # directory: 'infra/networking',
62
+ # vars: {
63
+ # region: 'eu-central'
64
+ # })
65
+ #
8
66
  class Destroy < Base
9
- include RubyTerraform::Options::Common
67
+ include RubyTerraform::Options::Global
10
68
 
69
+ # @!visibility private
11
70
  def subcommands
12
71
  %w[destroy]
13
72
  end
14
73
 
15
- def options # rubocop:disable Metrics/MethodLength
74
+ # rubocop:disable Metrics/MethodLength
75
+
76
+ # @!visibility private
77
+ def options
16
78
  %w[
79
+ -auto-approve
17
80
  -backup
18
81
  -compact-warnings
19
82
  -lock
20
83
  -lock-timeout
21
84
  -input
22
- -auto-approve
23
85
  -no-color
24
86
  -parallelism
25
87
  -refresh
@@ -31,14 +93,19 @@ module RubyTerraform
31
93
  ] + super
32
94
  end
33
95
 
96
+ # rubocop:enable Metrics/MethodLength
97
+
98
+ # @!visibility private
34
99
  def arguments(parameters)
35
100
  [parameters[:directory]]
36
101
  end
37
102
 
103
+ # @!visibility private
38
104
  def parameter_defaults(_parameters)
39
105
  { vars: {}, var_files: [], targets: [] }
40
106
  end
41
107
 
108
+ # @!visibility private
42
109
  def parameter_overrides(parameters)
43
110
  { backup: parameters[:no_backup] ? '-' : parameters[:backup] }
44
111
  end
@@ -1,23 +1,53 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative 'base'
4
- require_relative '../options/common'
4
+ require_relative '../options/global'
5
5
 
6
6
  module RubyTerraform
7
7
  module Commands
8
+ # Wraps the +terraform force-unlock+ command which manually unlocks the
9
+ # state for the defined configuration.
10
+ #
11
+ # This will not modify your infrastructure. This command removes the lock on
12
+ # the state for the current workspace. The behavior of this lock is
13
+ # dependent on the backend being used. Local state files cannot be unlocked
14
+ # by another process.
15
+ #
16
+ # For options accepted on construction, see {#initialize}.
17
+ #
18
+ # When executing an instance of {ForceUnlock} via {#execute}, the following
19
+ # options are supported:
20
+ #
21
+ # * +:lock_id+: the lock ID output when attempting an operation that failed
22
+ # due to a lock; required.
23
+ # * +:directory+: the path to a directory containing terraform
24
+ # configuration (deprecated in terraform 0.14, removed in terraform 0.15,
25
+ # use +:chdir+ instead).
26
+ # * +:chdir+: the path of a working directory to switch to before executing
27
+ # the given subcommand.
28
+ # * +:force+: If +true+, does not ask for input for unlock confirmation;
29
+ # defaults to +false+.
30
+ #
31
+ # @example Basic Invocation
32
+ # RubyTerraform::Commands::ForceUnlock.new.execute(
33
+ # lock_id: '50e844a7-ebb0-fcfd-da85-5cce5bd1ec90')
34
+ #
8
35
  class ForceUnlock < Base
9
- include RubyTerraform::Options::Common
36
+ include RubyTerraform::Options::Global
10
37
 
38
+ # @!visibility private
11
39
  def subcommands
12
40
  %w[force-unlock]
13
41
  end
14
42
 
43
+ # @!visibility private
15
44
  def options
16
45
  %w[-force] + super
17
46
  end
18
47
 
48
+ # @!visibility private
19
49
  def arguments(parameters)
20
- [parameters[:lock_id]]
50
+ [parameters[:lock_id], parameters[:directory]]
21
51
  end
22
52
  end
23
53
  end
@@ -1,27 +1,70 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative 'base'
4
- require_relative '../options/common'
4
+ require_relative '../options/global'
5
5
 
6
6
  module RubyTerraform
7
7
  module Commands
8
+ # Wraps the +terraform fmt+ command which rewrites all terraform
9
+ # configuration files to a canonical format.
10
+ #
11
+ # Both configuration files (.tf) and variables files (.tfvars) are updated.
12
+ # JSON files (.tf.json or .tfvars.json) are not modified.
13
+ #
14
+ # If +:directory+ is not specified in the parameters map then the current
15
+ # working directory will be used. If +:directory+ is +"-"+ then content will
16
+ # be read from the standard input. The given content must be in the
17
+ # terraform language native syntax; JSON is not supported.
18
+ #
19
+ # For options accepted on construction, see {#initialize}.
20
+ #
21
+ # When executing an instance of {Format} via {#execute}, the following
22
+ # options are supported:
23
+ #
24
+ # * +:directory+: the path to a directory containing terraform
25
+ # configuration (deprecated in terraform 0.14, removed in terraform 0.15,
26
+ # use +:chdir+ instead).
27
+ # * +:chdir+: the path of a working directory to switch to before executing
28
+ # the given subcommand.
29
+ # * +:list+: If +true+, lists files whose formatting differs; defaults to
30
+ # +false+; always disabled if using standard input.
31
+ # * +:write+: If +true+, writes to source files; defaults to +false+; always
32
+ # disabled if using standard input or +:check+ is +true+.
33
+ # * +:diff+: If +true+, displays diffs of formatting changes; defaults to
34
+ # +false+.
35
+ # * +:check+: If +true+, checks if the input is formatted; if any input is
36
+ # not properly formatted, an {RubyTerraform::Errors::ExecutionError} will
37
+ # be thrown; defaults to +false+.
38
+ # * +:no_color+: whether or not the output from the command should be in
39
+ # color; defaults to +false+.
40
+ # * +:recursive+: If +true+, also processes files in subdirectories;
41
+ # defaults to +false+ such that only the provided +:directory+ is
42
+ # processed.
43
+ #
44
+ # @example Basic Invocation
45
+ # RubyTerraform::Commands::Format.new.execute(
46
+ # directory: 'infra/networking')
8
47
  class Format < Base
9
- include RubyTerraform::Options::Common
48
+ include RubyTerraform::Options::Global
10
49
 
50
+ # @!visibility private
11
51
  def subcommands
12
52
  %w[fmt]
13
53
  end
14
54
 
55
+ # @!visibility private
15
56
  def options
16
57
  %w[
17
58
  -list
18
59
  -write
19
60
  -diff
20
61
  -check
62
+ -no-color
21
63
  -recursive
22
64
  ] + super
23
65
  end
24
66
 
67
+ # @!visibility private
25
68
  def arguments(parameters)
26
69
  [parameters[:directory]]
27
70
  end
@@ -1,17 +1,49 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative 'base'
4
- require_relative '../options/common'
4
+ require_relative '../options/global'
5
5
 
6
6
  module RubyTerraform
7
7
  module Commands
8
+ # Wraps the +terraform get+ command which downloads and installs modules
9
+ # needed for the given configuration.
10
+ #
11
+ # This recursively downloads all modules needed, such as modules imported by
12
+ # the root and so on. If a module is already downloaded, it will not be
13
+ # redownloaded or checked for updates unless +:update+ is +true+.
14
+ #
15
+ # Module installation also happens automatically by default as part of
16
+ # the {Init} command, so you should rarely need to run this
17
+ # command separately.
18
+ #
19
+ # For options accepted on construction, see {#initialize}.
20
+ #
21
+ # When executing an instance of {Get} via {#execute}, the following options
22
+ # are supported:
23
+ #
24
+ # * +:directory+: the path to a directory containing terraform
25
+ # configuration (deprecated in terraform 0.14, removed in terraform 0.15,
26
+ # use +:chdir+ instead).
27
+ # * +:chdir+: the path of a working directory to switch to before executing
28
+ # the given subcommand.
29
+ # * +:update+: if +true+, checks already-downloaded modules for available
30
+ # updates and installs the newest versions available; defaults to +false+.
31
+ # * +:no_color+: whether or not the output from the command should be in
32
+ # color; defaults to +false+.
33
+ #
34
+ # @example Basic Invocation
35
+ # RubyTerraform::Commands::Get.new.execute(
36
+ # directory: 'infra/networking')
37
+ #
8
38
  class Get < Base
9
- include RubyTerraform::Options::Common
39
+ include RubyTerraform::Options::Global
10
40
 
41
+ # @!visibility private
11
42
  def subcommands
12
43
  %w[get]
13
44
  end
14
45
 
46
+ # @!visibility private
15
47
  def options
16
48
  %w[
17
49
  -no-color
@@ -19,6 +51,7 @@ module RubyTerraform
19
51
  ] + super
20
52
  end
21
53
 
54
+ # @!visibility private
22
55
  def arguments(parameters)
23
56
  [parameters[:directory]]
24
57
  end