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,24 +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 graph+ command which outputs the visual execution
9
+ # graph of terraform resources according to either the current configuration
10
+ # or an execution plan.
11
+ #
12
+ # The graph is outputted in DOT format. The typical program that can
13
+ # read this format is GraphViz, but many web services are also available to
14
+ # read this format.
15
+ #
16
+ # The +:type+ option can be used to control the type of graph shown.
17
+ # Terraform creates different graphs for different operations. See the
18
+ # options below for the list of types supported. The default type is
19
+ # +"plan"+ if a configuration is given, and +"apply"+ if a plan file is
20
+ # passed as an argument.
21
+ #
22
+ # For options accepted on construction, see {#initialize}.
23
+ #
24
+ # When executing an instance of {Graph} via {#execute}, the following
25
+ # options are supported:
26
+ #
27
+ # * +:directory+: the path to a directory containing terraform
28
+ # configuration (deprecated in terraform 0.14, removed in terraform 0.15,
29
+ # use +:chdir+ instead).
30
+ # * +:chdir+: the path of a working directory to switch to before executing
31
+ # the given subcommand.
32
+ # * +:plan+: render the graph using the specified plan file instead of the
33
+ # configuration in the current directory.
34
+ # * +:draw_cycles+: if +true+, highlights any cycles in the graph with
35
+ # colored edges; this helps when diagnosing cycle errors; defaults to
36
+ # +false+.
37
+ # * +:type+: the type of graph to output; can be: +"plan"+,
38
+ # +"plan-destroy"+, +"apply"+, +"validate"+, +"input"+, +"refresh"+;
39
+ # defaults to +"apply"+ if +:plan+ is provided, +"plan"+ otherwise.
40
+ # * +:module_depth+: (deprecated) in prior versions of terraform, specified
41
+ # the depth of modules to show in the output.
42
+ #
43
+ # @example Basic Invocation
44
+ # RubyTerraform::Commands::Graph.new.execute
45
+ #
8
46
  class Graph < Base
9
- include RubyTerraform::Options::Common
47
+ include RubyTerraform::Options::Global
10
48
 
49
+ # @!visibility private
11
50
  def subcommands
12
51
  %w[graph]
13
52
  end
14
53
 
54
+ # @!visibility private
15
55
  def options
16
56
  %w[
57
+ -plan
17
58
  -draw-cycles
18
59
  -type
19
60
  -module-depth
20
61
  ] + super
21
62
  end
63
+
64
+ # @!visibility private
65
+ def arguments(parameters)
66
+ [parameters[:directory]]
67
+ end
22
68
  end
23
69
  end
24
70
  end
@@ -1,20 +1,110 @@
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 import+ command which imports existing infrastructure
9
+ # into your terraform state.
10
+ #
11
+ # This will find and import the specified resource into your terraform
12
+ # state, allowing existing infrastructure to come under terraform
13
+ # management without having to be initially created by terraform.
14
+ #
15
+ # The +:address+ specified is the address to import the resource to. Please
16
+ # see the documentation online for resource addresses. The +:id+ is a
17
+ # resource-specific ID to identify that resource being imported. Please
18
+ # reference the documentation for the resource type you're importing to
19
+ # determine the ID syntax to use. It typically matches directly to the ID
20
+ # that the provider uses.
21
+ #
22
+ # The current implementation of terraform import can only import resources
23
+ # into the state. It does not generate configuration. A future version of
24
+ # terraform will also generate configuration.
25
+ #
26
+ # Because of this, prior to running terraform import it is necessary to
27
+ # write a resource configuration block for the resource manually, to which
28
+ # the imported object will be attached.
29
+ #
30
+ # This command will not modify your infrastructure, but it will make network
31
+ # requests to inspect parts of your infrastructure relevant to the resource
32
+ # being imported.
33
+ #
34
+ # For options accepted on construction, see {#initialize}.
35
+ #
36
+ # When executing an instance of {Import} via {#execute}, the following
37
+ # options are supported:
38
+ #
39
+ # * +:directory+: the path to a directory containing terraform configuration
40
+ # (deprecated in terraform 0.14, removed in terraform 0.15, use +:chdir+
41
+ # instead).
42
+ # * +:address+: the address to import the resource to; required.
43
+ # * +:id+: the resource-specific ID identifying the resource being imported;
44
+ # required.
45
+ # * +:chdir+: the path of a working directory to switch to before executing
46
+ # the given subcommand.
47
+ # * +:backup+: (legacy) the path to backup the existing state file before
48
+ # modifying; defaults to the +:state_out+ path with +".backup"+ extension;
49
+ # set +:no_backup+ to +true+ to skip backups entirely.
50
+ # * +:allow_missing_config+: whether or not to allow import when no resource
51
+ # configuration block exists; defaults to +false+.
52
+ # * +:input+: when +false+, will not ask for input for variables not
53
+ # directly set; defaults to +true+.
54
+ # * +:lock+: when +true+, locks the state file when locking is supported;
55
+ # when +false+, does not lock the state file; defaults to +true+.
56
+ # * +:lock_timeout+: the duration to retry a state lock; defaults to +"0s"+.
57
+ # * +:no_backup+: (legacy) when +true+, no backup file will be written;
58
+ # defaults to +false+.
59
+ # * +:no_color+: whether or not the output from the command should be in
60
+ # color; defaults to +false+.
61
+ # * +:parallelism+: the number of parallel resource operations; defaults to
62
+ # +10+.
63
+ # * +:provider+: (deprecated) the provider configuration to use when
64
+ # importing the object; by default, terraform uses the provider specified
65
+ # in the configuration for the target resource, and that is the best
66
+ # behavior in most cases.
67
+ # * +:state+: (legacy) the path to the state file from which to read state
68
+ # and in which to store state (unless +:state_out+ is specified); defaults
69
+ # to +"terraform.tfstate"+.
70
+ # * +:state_out+: (legacy) the path to write state to that is different than
71
+ # +:state+; this can be used to preserve the old state.
72
+ # * +:vars+: a map of variables to be passed to the terraform configuration.
73
+ # * +:var_file+: the path to a terraform var file; if both +:var_file+ and
74
+ # +:var_files+ are provided, all var files will be passed to terraform.
75
+ # * +:var_files+: an array of paths to terraform var files; if both
76
+ # +:var_file+ and +:var_files+ are provided, all var files will be passed
77
+ # to terraform.
78
+ # * +:ignore_remote_version+: If +true+, when using the enhanced remote
79
+ # backend with Terraform Cloud, continue even if remote and local
80
+ # Terraform versions differ; this may result in an unusable Terraform
81
+ # Cloud workspace, and should be used with extreme caution; defaults to
82
+ # +false+.
83
+ #
84
+ # @example Basic Invocation
85
+ # RubyTerraform::Commands::Import.new.execute(
86
+ # directory: 'infra/networking',
87
+ # address: 'a.resource.address',
88
+ # id: 'a-resource-id',
89
+ # vars: {
90
+ # region: 'eu-central'
91
+ # })
92
+ #
8
93
  class Import < Base
9
- include RubyTerraform::Options::Common
94
+ include RubyTerraform::Options::Global
10
95
 
96
+ # @!visibility private
11
97
  def subcommands
12
98
  %w[import]
13
99
  end
14
100
 
15
- def options # rubocop:disable Metrics/MethodLength
101
+ # rubocop:disable Metrics/MethodLength
102
+
103
+ # @!visibility private
104
+ def options
16
105
  %w[
17
106
  -config
107
+ -allow-missing-config
18
108
  -backup
19
109
  -input
20
110
  -lock
@@ -30,14 +120,19 @@ module RubyTerraform
30
120
  ] + super
31
121
  end
32
122
 
123
+ # rubocop:enable Metrics/MethodLength
124
+
125
+ # @!visibility private
33
126
  def arguments(parameters)
34
127
  [parameters[:address], parameters[:id]]
35
128
  end
36
129
 
130
+ # @!visibility private
37
131
  def parameter_defaults(_parameters)
38
132
  { vars: {}, var_files: [] }
39
133
  end
40
134
 
135
+ # @!visibility private
41
136
  def parameter_overrides(parameters)
42
137
  { backup: parameters[:no_backup] ? '-' : parameters[:backup] }
43
138
  end
@@ -1,18 +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 init+ command which initializes a new or existing
9
+ # Terraform working directory by creating initial files, loading any remote
10
+ # state, downloading modules, etc.
11
+ #
12
+ # This is the first command that should be run for any new or existing
13
+ # Terraform configuration per machine. This sets up all the local data
14
+ # necessary to run Terraform that is typically not committed to version
15
+ # control.
16
+ #
17
+ # This command is always safe to run multiple times. Though subsequent runs
18
+ # may give errors, this command will never delete your configuration or
19
+ # state. Even so, if you have important information, please back it up prior
20
+ # to running this command, just in case.
21
+ #
22
+ # For options accepted on construction, see {#initialize}.
23
+ #
24
+ # When executing an instance of {Init} via {#execute}, the following
25
+ # options are supported:
26
+ #
27
+ # * +:path+: the path to initialize; defaults to the current directory
28
+ # (deprecated in terraform 0.14, removed in terraform 0.15, use +:chdir+
29
+ # instead).
30
+ # * +:chdir+: the path of a working directory to switch to before executing
31
+ # the given subcommand.
32
+ # * +:backend+: whether or not to configure the backend for this
33
+ # configuration; defaults to +true+.
34
+ # * +:backend_config+: a map of backend specific configuration parameters.
35
+ # * +:force_copy+: if +true+, suppresses prompts about copying state data;
36
+ # this is equivalent to providing a "yes" to all confirmation prompts;
37
+ # defaults to +false+.
38
+ # * +:from_module+: copies the contents of the given module into the target
39
+ # directory before initialization.
40
+ # * +:get+: whether or not to download any modules for this configuration;
41
+ # defaults to +true+.
42
+ # * +:get_plugins+: whether or not to install plugins for this
43
+ # configuration; defaults to +true+ (deprecated, removed in terraform
44
+ # 0.15).
45
+ # * +:input+: when +false+, will not ask for input for variables not
46
+ # directly set; defaults to +true+.
47
+ # * +:lock+: when +true+, locks the state file when locking is supported;
48
+ # when +false+, does not lock the state file; defaults to +true+
49
+ # (deprecated, removed in terraform 0.15).
50
+ # * +:lock_timeout+: the duration to retry a state lock; defaults to +"0s"+;
51
+ # (deprecated, removed in terraform 0.15).
52
+ # * +:no_color+: whether or not the output from the command should be in
53
+ # color; defaults to +false+.
54
+ # * +:plugin_dir+: the path to a directory containing plugin binaries; this
55
+ # overrides all default search paths for plugins, and prevents the
56
+ # automatic installation of plugins; if both +:plugin_dir+ and
57
+ # +:plugin_dirs+ are provided, all plugin directories will be passed to
58
+ # Terraform.
59
+ # * +:plugin_dirs+: an array of paths to directories containing plugin
60
+ # binaries; this overrides all default search paths for plugins, and
61
+ # prevents the automatic installation of plugins; if both +:plugin_dir+
62
+ # and +:plugin_dirs+ are provided, all plugin directories will be passed
63
+ # to Terraform.
64
+ # * +:reconfigure+: if +true+, reconfigures the backend, ignoring any saved
65
+ # configuration; defaults to +false+.
66
+ # * +:upgrade+: if +true+, when installing modules or plugins, ignores
67
+ # previously-downloaded objects and installs the latest version allowed
68
+ # within configured constraints; defaults to +false+.
69
+ # * +:verify_plugins+: whether or not to verify plugins for this
70
+ # configuration; defaults to +true+ (deprecated, removed in terraform
71
+ # 0.15).
72
+ # * +:lockfile+: sets a dependency lockfile mode; currently only "readonly"
73
+ # is valid.
74
+ #
75
+ # @example Basic Invocation
76
+ # RubyTerraform::Commands::Init.new.execute(
77
+ # from_module: 'some/module/path',
78
+ # path: 'infra/module')
79
+ #
8
80
  class Init < Base
9
- include RubyTerraform::Options::Common
81
+ include RubyTerraform::Options::Global
10
82
 
83
+ # @!visibility private
11
84
  def subcommands
12
85
  %w[init]
13
86
  end
14
87
 
15
- def options # rubocop:disable Metrics/MethodLength
88
+ # rubocop:disable Metrics/MethodLength
89
+
90
+ # @!visibility private
91
+ def options
16
92
  %w[
17
93
  -backend
18
94
  -backend-config
@@ -28,13 +104,18 @@ module RubyTerraform
28
104
  -reconfigure
29
105
  -upgrade
30
106
  -verify-plugins
107
+ -lockfile
31
108
  ] + super
32
109
  end
33
110
 
111
+ # rubocop:enable Metrics/MethodLength
112
+
113
+ # @!visibility private
34
114
  def arguments(parameters)
35
115
  [parameters[:path]]
36
116
  end
37
117
 
118
+ # @!visibility private
38
119
  def parameter_defaults(_parameters)
39
120
  { backend_config: {} }
40
121
  end
@@ -1,17 +1,41 @@
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 login+ command which retrieves an authentication
9
+ # token for the given hostname, if it supports automatic login, and saves it
10
+ # in a credentials file in your home directory.
11
+ #
12
+ # If no hostname is provided, the default hostname is app.terraform.io, to
13
+ # log in to Terraform Cloud.
14
+ #
15
+ # If not overridden by credentials helper settings in the CLI configuration,
16
+ # the credentials will be written to the following local file:
17
+ # ~/.terraform.d/credentials.tfrc.json
18
+ #
19
+ # For options accepted on construction, see {#initialize}.
20
+ #
21
+ # When executing an instance of {Login} via {#execute}, the following
22
+ # options are supported:
23
+ #
24
+ # * +:chdir+: the path of a working directory to switch to before executing
25
+ # the given subcommand.
26
+ #
27
+ # @example Basic Invocation
28
+ # RubyTerraform::Commands::Login.new.execute
29
+ #
8
30
  class Login < Base
9
- include RubyTerraform::Options::Common
31
+ include RubyTerraform::Options::Global
10
32
 
33
+ # @!visibility private
11
34
  def subcommands
12
35
  %w[login]
13
36
  end
14
37
 
38
+ # @!visibility private
15
39
  def arguments(parameters)
16
40
  [parameters[:hostname]]
17
41
  end
@@ -1,17 +1,38 @@
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 logout+ command which removes locally-stored
9
+ # credentials for specified hostname.
10
+ #
11
+ # Note: the API token is only removed from local storage, not destroyed on
12
+ # the remote server, so it will remain valid until manually revoked.
13
+ #
14
+ # If no hostname is provided, the default hostname is app.terraform.io.
15
+ #
16
+ # For options accepted on construction, see {#initialize}.
17
+ #
18
+ # When executing an instance of {Logout} via {#execute}, the following
19
+ # options are supported:
20
+ #
21
+ # * +:chdir+: the path of a working directory to switch to before executing
22
+ # the given subcommand.
23
+ #
24
+ # @example Basic Invocation
25
+ # RubyTerraform::Commands::Logout.new.execute
26
+ #
8
27
  class Logout < Base
9
- include RubyTerraform::Options::Common
28
+ include RubyTerraform::Options::Global
10
29
 
30
+ # @!visibility private
11
31
  def subcommands
12
32
  %w[logout]
13
33
  end
14
34
 
35
+ # @!visibility private
15
36
  def arguments(parameters)
16
37
  [parameters[:hostname]]
17
38
  end
@@ -2,21 +2,51 @@
2
2
 
3
3
  require 'stringio'
4
4
  require_relative 'base'
5
- require_relative '../options/common'
5
+ require_relative '../options/global'
6
6
 
7
7
  module RubyTerraform
8
8
  module Commands
9
+ # Wraps the +terraform output+ command which reads an output variable from a
10
+ # Terraform state file and prints the value. With no additional arguments,
11
+ # output will display all the outputs for the root module. If +:name+ is not
12
+ # specified, all outputs are printed.
13
+ #
14
+ # For options accepted on construction, see {#initialize}.
15
+ #
16
+ # When executing an instance of {Output} via {#execute}, the following
17
+ # options are supported:
18
+ #
19
+ # * +:name+: The name of the output to read.
20
+ # * +:chdir+: the path of a working directory to switch to before executing
21
+ # the given subcommand.
22
+ # * +:state+: the path to the state file to read; defaults to
23
+ # +"terraform.tfstate"+.
24
+ # * +:no_color+: whether or not the output from the command should be in
25
+ # color; defaults to +false+.
26
+ # * +:json+: If +true+, machine readable output will be printed in JSON
27
+ # format; defaults to +false+.
28
+ # * +:raw+: If +true+, for value types that can be automatically converted
29
+ # to a string, will print the raw string directly, rather than a
30
+ # human-oriented representation of the value.
31
+ #
32
+ # @example Basic Invocation
33
+ # RubyTerraform::Commands::Output.new.execute(
34
+ # name: 'vpc_id')
35
+ #
9
36
  class Output < Base
10
- include RubyTerraform::Options::Common
37
+ include RubyTerraform::Options::Global
11
38
 
39
+ # @!visibility private
12
40
  def stdout
13
41
  @stdout.respond_to?(:string) ? @stdout : (@stdout = StringIO.new)
14
42
  end
15
43
 
44
+ # @!visibility private
16
45
  def subcommands
17
46
  %w[output]
18
47
  end
19
48
 
49
+ # @!visibility private
20
50
  def options
21
51
  %w[
22
52
  -json
@@ -26,10 +56,12 @@ module RubyTerraform
26
56
  ] + super
27
57
  end
28
58
 
59
+ # @!visibility private
29
60
  def arguments(parameters)
30
61
  [parameters[:name]]
31
62
  end
32
63
 
64
+ # @!visibility private
33
65
  def do_after(parameters)
34
66
  result = stdout.string
35
67
  parameters[:name] ? result.chomp : result