ruby-terraform 0.65.0.pre.12 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
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,17 +1,39 @@
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 show+ command which reads and outputs a Terraform
9
+ # state or plan file in a human-readable form. If no path is specified, the
10
+ # current state will be shown.
11
+ #
12
+ # For options accepted on construction, see {#initialize}.
13
+ #
14
+ # When executing an instance of {Show} via {#execute}, the following
15
+ # options are supported:
16
+ #
17
+ # * +:path+: the path to a state file or plan to show.
18
+ # * +:chdir+: the path of a working directory to switch to before executing
19
+ # the given subcommand.
20
+ # * +:no_color+: whether or not the output from the command should be in
21
+ # color; defaults to +false+.
22
+ # * +:json+: if +true+, outputs the Terraform plan or state in a
23
+ # machine-readable form; defaults to +false+.
24
+ #
25
+ # @example Basic Invocation
26
+ # RubyTerraform::Commands::Show.new.execute
27
+ #
8
28
  class Show < Base
9
- include RubyTerraform::Options::Common
29
+ include RubyTerraform::Options::Global
10
30
 
31
+ # @!visibility private
11
32
  def subcommands
12
33
  %w[show]
13
34
  end
14
35
 
36
+ # @!visibility private
15
37
  def options
16
38
  %w[
17
39
  -json
@@ -19,8 +41,9 @@ module RubyTerraform
19
41
  ] + super
20
42
  end
21
43
 
44
+ # @!visibility private
22
45
  def arguments(parameters)
23
- [parameters[:path] || parameters[:directory]]
46
+ [parameters[:path]]
24
47
  end
25
48
  end
26
49
  end
@@ -1,19 +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 state list+ command which lists resources in the
9
+ # Terraform state.
10
+ #
11
+ # This command lists resource instances in the Terraform state. The address
12
+ # option can be used to filter the instances by resource or module. If no
13
+ # pattern is given, all resource instances are listed.
14
+ #
15
+ # The addresses must either be module addresses or absolute resource
16
+ # addresses, such as:
17
+ #
18
+ # * +aws_instance.example+
19
+ # * +module.example+
20
+ # * +module.example.module.child+
21
+ # * +module.example.aws_instance.example+
22
+ #
23
+ # An {RubyTerraform::Errors::ExecutionError} will be raised if any of the
24
+ # resources or modules given as filter addresses do not exist in the state.
25
+ #
26
+ # For options accepted on construction, see {#initialize}.
27
+ #
28
+ # When executing an instance of {StateList} via {#execute}, the following
29
+ # options are supported:
30
+ #
31
+ # * +:address+: the module address or absolute resource address to filter
32
+ # by; if both +:address+ and +:addresses+ are provided, all addresses will
33
+ # be passed to Terraform.
34
+ # * +:addresses+: an array of module addresses or absolute resource
35
+ # addresses to filter by; if both +:address+ and +:addresses+ are
36
+ # provided, all addresses will be passed to Terraform.
37
+ # * +:chdir+: the path of a working directory to switch to before executing
38
+ # the given subcommand.
39
+ # * +:state+: the path to a Terraform state file to use to look up
40
+ # Terraform-managed resources; by default, Terraform will consult the
41
+ # state of the currently-selected workspace.
42
+ # * +:id+: when provided, filters the results to include only instances
43
+ # whose resource types have an attribute named "id" whose value equals the
44
+ # given id string.
45
+ #
46
+ # @example Basic Invocation
47
+ # RubyTerraform::Commands::StateList.new.execute
48
+ #
8
49
  class StateList < Base
9
- include RubyTerraform::Options::Common
50
+ include RubyTerraform::Options::Global
10
51
 
52
+ # @!visibility private
11
53
  def subcommands
12
54
  %w[state list]
13
55
  end
14
56
 
57
+ # @!visibility private
58
+ def options
59
+ %w[
60
+ -state
61
+ -id
62
+ ] + super
63
+ end
64
+
65
+ # @!visibility private
15
66
  def arguments(parameters)
16
- [parameters[:address]]
67
+ [parameters[:address], parameters[:addresses]]
17
68
  end
18
69
  end
19
70
  end
@@ -1,34 +1,92 @@
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 state mv+ command which moves an item in the state.
9
+ #
10
+ # This command will move an item matched by the address given to the
11
+ # destination address. This command can also move to a destination address
12
+ # in a completely different state file.
13
+ #
14
+ # This can be used for simple resource renaming, moving items to and from
15
+ # a module, moving entire modules, and more. And because this command can
16
+ # also move data to a completely new state, it can also be used for
17
+ # refactoring one configuration into multiple separately managed Terraform
18
+ # configurations.
19
+ #
20
+ # This command will output a backup copy of the state prior to saving any
21
+ # changes. The backup cannot be disabled. Due to the destructive nature
22
+ # of this command, backups are required.
23
+ #
24
+ # If you're moving an item to a different state file, a backup will be
25
+ # created for each state file.
26
+ #
27
+ # For options accepted on construction, see {#initialize}.
28
+ #
29
+ # When executing an instance of {StateMove} via {#execute}, the following
30
+ # options are supported:
31
+ #
32
+ # * +:source+: the source address of the item to move; required.
33
+ # * +:destination+: the destination address to move the item to; required.
34
+ # * +:chdir+: the path of a working directory to switch to before executing
35
+ # the given subcommand.
36
+ # * +:dry_run+: when +true+, prints out what would've been moved but doesn't
37
+ # actually move anything; defaults to +false+.
38
+ # * +:backup+: the path where Terraform should write the backup for the
39
+ # original state; this can't be disabled; if not set, Terraform will write
40
+ # it to the same path as the state file with a +".backup"+ extension.
41
+ # * +:backup_out+: the path where Terraform should write the backup for the
42
+ # destination state; this can't be disabled; if not set, Terraform will
43
+ # write it to the same path as the destination state file with a
44
+ # +".backup"+ extension; this only needs to be specified if +:state_out+
45
+ # is set to a different path than +:state+.
46
+ # * +:lock+: when +true+, locks the state file when locking is supported;
47
+ # when +false+, does not lock the state file; defaults to +true+.
48
+ # * +:lock_timeout+: the duration to retry a state lock; defaults to +"0s"+.
49
+ # * +:state+: the path to the source state file; defaults to the configured
50
+ # backend, or +"terraform.tfstate"+.
51
+ # * +:state_out+: the path to the destination state file to write to; if
52
+ # this isn't specified, the source state file will be used; this can be a
53
+ # new or existing path.
54
+ # * +:ignore_remote_version+: whether or not to continue even if remote and
55
+ # local Terraform versions are incompatible; this may result in an
56
+ # unusable workspace, and should be used with extreme caution; defaults to
57
+ # +false+.
58
+ #
59
+ # @example Basic Invocation
60
+ # RubyTerraform::Commands::StateMove.new.execute(
61
+ # source: 'packet_device.worker',
62
+ # destination: 'packet_device.helper')
63
+ #
8
64
  class StateMove < Base
9
- include RubyTerraform::Options::Common
65
+ include RubyTerraform::Options::Global
10
66
 
67
+ # @!visibility private
11
68
  def subcommands
12
69
  %w[state mv]
13
70
  end
14
71
 
72
+ # @!visibility private
15
73
  def options
16
74
  %w[
75
+ -dry-run
17
76
  -backup
18
77
  -backup-out
78
+ -lock
79
+ -lock-timeout
19
80
  -state
20
81
  -state-out
21
82
  -ignore-remote-version
22
83
  ] + super
23
84
  end
24
85
 
86
+ # @!visibility private
25
87
  def arguments(parameters)
26
88
  [parameters[:source], parameters[:destination]]
27
89
  end
28
-
29
- def parameter_overrides(parameters)
30
- { backup: parameters[:no_backup] ? '-' : parameters[:backup] }
31
- end
32
90
  end
33
91
  end
34
92
  end
@@ -1,13 +1,35 @@
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 state pull+ command which pulls the state from its
9
+ # location, upgrades the local copy, and outputs it to stdout.
10
+ #
11
+ # This command "pulls" the current state and outputs it to stdout. As part
12
+ # of this process, Terraform will upgrade the state format of the local copy
13
+ # to the current version.
14
+ #
15
+ # The primary use of this is for state stored remotely. This command will
16
+ # still work with local state but is less useful for this.
17
+ #
18
+ # For options accepted on construction, see {#initialize}.
19
+ #
20
+ # When executing an instance of {StatePull} via {#execute}, the following
21
+ # options are supported:
22
+ #
23
+ # * +:chdir+: the path of a working directory to switch to before executing
24
+ # the given subcommand.
25
+ #
26
+ # @example Basic Invocation
27
+ # RubyTerraform::Commands::StatePull.new.execute
28
+ #
8
29
  class StatePull < Base
9
- include RubyTerraform::Options::Common
30
+ include RubyTerraform::Options::Global
10
31
 
32
+ # @!visibility private
11
33
  def subcommands
12
34
  %w[state pull]
13
35
  end
@@ -1,21 +1,67 @@
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 state push+ command which updates remote state from
9
+ # a local state file.
10
+ #
11
+ # This command "pushes" a local state and overwrites remote state with a
12
+ # local state file. The command will protect you against writing
13
+ # an older serial or a different state file lineage unless you pass +true+
14
+ # for the +:force+ option.
15
+ #
16
+ # This command works with local state (it will overwrite the local state),
17
+ # but is less useful for this use case.
18
+ #
19
+ # If +:path+ is +"-"+, then this command will read the state to push from
20
+ # stdin. Data from stdin is not streamed to the backend: it is loaded
21
+ # completely (until pipe close), verified, and then pushed.
22
+ #
23
+ # For options accepted on construction, see {#initialize}.
24
+ #
25
+ # When executing an instance of {StatePush} via {#execute}, the following
26
+ # options are supported:
27
+ #
28
+ # * +:path+: the path to the state file to push; when passed +"-"+ will
29
+ # read state from standard input.
30
+ # * +:chdir+: the path of a working directory to switch to before executing
31
+ # the given subcommand.
32
+ # * +:force+: when +true+, writes the state even if lineages don't match or
33
+ # the remote serial is higher; defaults to +false+.
34
+ # * +:lock+: when +true+, locks the state file when locking is supported;
35
+ # when +false+, does not lock the state file; defaults to +true+.
36
+ # * +:lock_timeout+: the duration to retry a state lock; defaults to +"0s"+.
37
+ # * +:ignore_remote_version+: whether or not to continue even if remote and
38
+ # local Terraform versions are incompatible; this may result in an
39
+ # unusable workspace, and should be used with extreme caution; defaults to
40
+ # +false+.
41
+ #
42
+ # @example Basic Invocation
43
+ # RubyTerraform::Commands::StatePush.new.execute(
44
+ # path: 'some/statefile.tfstate')
45
+ #
8
46
  class StatePush < Base
9
- include RubyTerraform::Options::Common
47
+ include RubyTerraform::Options::Global
10
48
 
49
+ # @!visibility private
11
50
  def subcommands
12
51
  %w[state push]
13
52
  end
14
53
 
54
+ # @!visibility private
15
55
  def options
16
- %w[-ignore-remote-version] + super
56
+ %w[
57
+ -force
58
+ -lock
59
+ -lock-timeout
60
+ -ignore-remote-version
61
+ ] + super
17
62
  end
18
63
 
64
+ # @!visibility private
19
65
  def arguments(parameters)
20
66
  [parameters[:path]]
21
67
  end
@@ -1,31 +1,79 @@
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 state rm+ command which removes one or more items
9
+ # from the Terraform state, causing Terraform to "forget" those items
10
+ # without first destroying them in the remote system.
11
+ #
12
+ # This command removes one or more resource instances from the Terraform
13
+ # state based on the addresses given. You can view and list the available
14
+ # instances with {StateList}.
15
+ #
16
+ # If you give the address of an entire module then all of the instances in
17
+ # that module and any of its child modules will be removed from the state.
18
+ #
19
+ # If you give the address of a resource that has "count" or "for_each" set,
20
+ # all of the instances of that resource will be removed from the state.
21
+ #
22
+ # For options accepted on construction, see {#initialize}.
23
+ #
24
+ # When executing an instance of {StateRemove} via {#execute}, the following
25
+ # options are supported:
26
+ #
27
+ # * +:address+: the module address or absolute resource address of the
28
+ # resource instance to remove; required unless +:addresses+ is supplied;
29
+ # if both +:address+ and +:addresses+ are provided, all addresses will be
30
+ # passed to Terraform.
31
+ # * +:addresses+: an array of module addresses or absolute resource
32
+ # addresses of the resource instances to remove; required unless
33
+ # +:address+ is supplied; if both +:address+ and +:addresses+ are
34
+ # provided, all addresses will be passed to Terraform.
35
+ # * +:chdir+: the path of a working directory to switch to before executing
36
+ # the given subcommand.
37
+ # * +:dry+run+: when +true+, prints out what would've been removed but
38
+ # doesn't actually remove anything; defaults to +false+.
39
+ # * +:backup+: the path where Terraform should write the backup state.
40
+ # * +:lock+: when +true+, locks the state file when locking is supported;
41
+ # when +false+, does not lock the state file; defaults to +true+.
42
+ # * +:lock_timeout+: the duration to retry a state lock; defaults to +"0s"+.
43
+ # * +:state+: the path to the state file to update; defaults to the current
44
+ # workspace state.
45
+ # * +:ignore_remote_version+: whether or not to continue even if remote and
46
+ # local Terraform versions are incompatible; this may result in an
47
+ # unusable workspace, and should be used with extreme caution; defaults to
48
+ # +false+.
49
+ #
50
+ # @example Basic Invocation
51
+ # RubyTerraform::Commands::StateRemove.new.execute(
52
+ # address: 'packet_device.worker')
53
+ #
8
54
  class StateRemove < Base
9
- include RubyTerraform::Options::Common
55
+ include RubyTerraform::Options::Global
10
56
 
57
+ # @!visibility private
11
58
  def subcommands
12
59
  %w[state rm]
13
60
  end
14
61
 
62
+ # @!visibility private
15
63
  def options
16
64
  %w[
65
+ -dry-run
17
66
  -backup
67
+ -lock
68
+ -lock-timeout
18
69
  -state
19
70
  -ignore-remote-version
20
71
  ] + super
21
72
  end
22
73
 
74
+ # @!visibility private
23
75
  def arguments(parameters)
24
- [parameters[:address]]
25
- end
26
-
27
- def parameter_overrides(parameters)
28
- { backup: parameters[:no_backup] ? '-' : parameters[:backup] }
76
+ [parameters[:address], parameters[:addresses]]
29
77
  end
30
78
  end
31
79
  end
@@ -1,17 +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 state replace-provider+ command which replaces
9
+ # provider for resources in the Terraform state.
10
+ #
11
+ # For options accepted on construction, see {#initialize}.
12
+ #
13
+ # When executing an instance of {StateReplaceProvider} via {#execute}, the
14
+ # following options are supported:
15
+ #
16
+ # * +:from+: the fully qualified name of the provider to be replaced;
17
+ # required.
18
+ # * +:to+: the fully qualified name of the provider to replace with;
19
+ # required.
20
+ # * +:chdir+: the path of a working directory to switch to before executing
21
+ # the given subcommand.
22
+ # * +:auto_approve+: if +true+, skips interactive approval; defaults to
23
+ # +false+.
24
+ # * +:backup+: the path where Terraform should write the backup for the
25
+ # state file; this can't be disabled; if not set, Terraform will write it
26
+ # to the same path as the state file with a ".backup" extension.
27
+ # * +:lock+: when +true+, locks the state file when locking is supported;
28
+ # when +false+, does not lock the state file; defaults to +true+.
29
+ # * +:lock_timeout+: the duration to retry a state lock; defaults to +"0s"+.
30
+ # * +:state+: the path to the state file to update; defaults to the current
31
+ # workspace state.
32
+ # * +:ignore_remote_version+: whether or not to continue even if remote and
33
+ # local Terraform versions are incompatible; this may result in an
34
+ # unusable workspace, and should be used with extreme caution; defaults to
35
+ # +false+.
36
+ #
37
+ # @example Basic Invocation
38
+ # RubyTerraform::Commands::StateReplaceProvider.new.execute(
39
+ # from: 'hashicorp/aws',
40
+ # to: 'registry.acme.corp/acme/aws')
41
+ #
8
42
  class StateReplaceProvider < Base
9
- include RubyTerraform::Options::Common
43
+ include RubyTerraform::Options::Global
10
44
 
45
+ # @!visibility private
11
46
  def subcommands
12
47
  %w[state replace-provider]
13
48
  end
14
49
 
50
+ # @!visibility private
15
51
  def options
16
52
  %w[
17
53
  -auto-approve
@@ -23,13 +59,10 @@ module RubyTerraform
23
59
  ] + super
24
60
  end
25
61
 
62
+ # @!visibility private
26
63
  def arguments(parameters)
27
64
  [parameters[:from], parameters[:to]]
28
65
  end
29
-
30
- def parameter_overrides(parameters)
31
- { backup: parameters[:no_backup] ? '-' : parameters[:backup] }
32
- end
33
66
  end
34
67
  end
35
68
  end