ruby-terraform 0.65.0.pre.10 → 0.65.0.pre.15

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 (41) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +18 -10
  3. data/README.md +2 -19
  4. data/lib/ruby_terraform.rb +691 -18
  5. data/lib/ruby_terraform/commands/apply.rb +75 -1
  6. data/lib/ruby_terraform/commands/base.rb +18 -15
  7. data/lib/ruby_terraform/commands/destroy.rb +67 -1
  8. data/lib/ruby_terraform/commands/force_unlock.rb +28 -0
  9. data/lib/ruby_terraform/commands/format.rb +39 -0
  10. data/lib/ruby_terraform/commands/get.rb +31 -0
  11. data/lib/ruby_terraform/commands/graph.rb +38 -0
  12. data/lib/ruby_terraform/commands/import.rb +95 -1
  13. data/lib/ruby_terraform/commands/init.rb +72 -1
  14. data/lib/ruby_terraform/commands/login.rb +24 -0
  15. data/lib/ruby_terraform/commands/logout.rb +21 -0
  16. data/lib/ruby_terraform/commands/output.rb +34 -4
  17. data/lib/ruby_terraform/commands/plan.rb +67 -1
  18. data/lib/ruby_terraform/commands/providers.rb +22 -0
  19. data/lib/ruby_terraform/commands/providers_lock.rb +66 -0
  20. data/lib/ruby_terraform/commands/providers_mirror.rb +42 -0
  21. data/lib/ruby_terraform/commands/taint.rb +2 -1
  22. data/lib/ruby_terraform/options.rb +25 -3
  23. data/lib/ruby_terraform/options/common.rb +1 -0
  24. data/lib/ruby_terraform/options/definition.rb +172 -0
  25. data/lib/ruby_terraform/options/definitions.rb +103 -0
  26. data/lib/ruby_terraform/options/factory.rb +10 -102
  27. data/lib/ruby_terraform/options/name.rb +11 -19
  28. data/lib/ruby_terraform/options/types.rb +27 -0
  29. data/lib/ruby_terraform/options/types/base.rb +6 -13
  30. data/lib/ruby_terraform/options/types/flag.rb +1 -3
  31. data/lib/ruby_terraform/options/types/standard.rb +1 -27
  32. data/lib/ruby_terraform/options/values.rb +38 -0
  33. data/lib/ruby_terraform/options/values/base.rb +15 -0
  34. data/lib/ruby_terraform/options/values/boolean.rb +13 -11
  35. data/lib/ruby_terraform/options/values/complex.rb +19 -0
  36. data/lib/ruby_terraform/options/values/key_value.rb +21 -0
  37. data/lib/ruby_terraform/options/values/string.rb +17 -0
  38. data/lib/ruby_terraform/version.rb +1 -1
  39. data/ruby_terraform.gemspec +3 -1
  40. metadata +40 -5
  41. data/lib/ruby_terraform/options/types/boolean.rb +0 -18
@@ -5,14 +5,103 @@ require_relative '../options/common'
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 of terraform configuration files
40
+ # to use to configure the provider; defaults to the current directory; if
41
+ # no config files are present, they must be provided via the input prompts
42
+ # or env vars.
43
+ # * +:address+: the address to import the resource to; required.
44
+ # * +:id+: the resource-specific ID identifying the resource being imported;
45
+ # required.
46
+ # * +:chdir+: the path of a working directory to switch to before executing
47
+ # the given subcommand.
48
+ # * +:backup+: (legacy) the path to backup the existing state file before
49
+ # modifying; defaults to the +:state_out+ path with +".backup"+ extension;
50
+ # set +:no_backup+ to +true+ to skip backups entirely.
51
+ # * +:input+: when +false+, will not ask for input for variables not
52
+ # directly set; defaults to +true+.
53
+ # * +:lock+: when +true+, locks the state file when locking is supported;
54
+ # when +false+, does not lock the state file; defaults to +true+.
55
+ # * +:lock_timeout+: the duration to retry a state lock; defaults to +"0s"+.
56
+ # * +:no_backup+: (legacy) when +true+, no backup file will be written;
57
+ # defaults to +false+.
58
+ # * +:no_color+: whether or not the output from the command should be in
59
+ # color; defaults to +false+.
60
+ # * +:parallelism+: the number of parallel resource operations; defaults to
61
+ # +10+.
62
+ # * +:provider+: (deprecated) the provider configuration to use when
63
+ # importing the object; by default, terraform uses the provider specified
64
+ # in the configuration for the target resource, and that is the best
65
+ # behavior in most cases.
66
+ # * +:state+: (legacy) the path to the state file from which to read state
67
+ # and in which to store state (unless +:state_out+ is specified); defaults
68
+ # to +"terraform.tfstate"+.
69
+ # * +:state_out+: (legacy) the path to write state to that is different than
70
+ # +:state+; this can be used to preserve the old state.
71
+ # * +:vars+: a map of variables to be passed to the terraform configuration.
72
+ # * +:var_file+: the path to a terraform var file; if both +:var_file+ and
73
+ # +:var_files+ are provided, all var files will be passed to terraform.
74
+ # * +:var_files+: an array of paths to terraform var files; if both
75
+ # +:var_file+ and +:var_files+ are provided, all var files will be passed
76
+ # to terraform.
77
+ # * +:ignore_remote_version+: If +true+, when using the enhanced remote
78
+ # backend with Terraform Cloud, continue even if remote and local
79
+ # Terraform versions differ; this may result in an unusable Terraform
80
+ # Cloud workspace, and should be used with extreme caution; defaults to
81
+ # +false+.
82
+ #
83
+ # @example Basic Invocation
84
+ # RubyTerraform::Commands::Import.new.execute(
85
+ # directory: 'infra/networking',
86
+ # address: 'a.resource.address',
87
+ # id: 'a-resource-id',
88
+ # vars: {
89
+ # region: 'eu-central'
90
+ # })
91
+ #
8
92
  class Import < Base
9
93
  include RubyTerraform::Options::Common
10
94
 
95
+ # @!visibility private
11
96
  def subcommands
12
97
  %w[import]
13
98
  end
14
99
 
15
- def options # rubocop:disable Metrics/MethodLength
100
+ # rubocop:disable Metrics/MethodLength
101
+
102
+ # @!visibility private
103
+ # @todo Add allow_missing_config option.
104
+ def options
16
105
  %w[
17
106
  -config
18
107
  -backup
@@ -30,14 +119,19 @@ module RubyTerraform
30
119
  ] + super
31
120
  end
32
121
 
122
+ # rubocop:enable Metrics/MethodLength
123
+
124
+ # @!visibility private
33
125
  def arguments(parameters)
34
126
  [parameters[:address], parameters[:id]]
35
127
  end
36
128
 
129
+ # @!visibility private
37
130
  def parameter_defaults(_parameters)
38
131
  { vars: {}, var_files: [] }
39
132
  end
40
133
 
134
+ # @!visibility private
41
135
  def parameter_overrides(parameters)
42
136
  { backup: parameters[:no_backup] ? '-' : parameters[:backup] }
43
137
  end
@@ -5,14 +5,81 @@ require_relative '../options/common'
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
+ # * +:chdir+: the path of a working directory to switch to before executing
29
+ # the given subcommand.
30
+ # * +:backend+: whether or not to configure the backend for this
31
+ # configuration; defaults to +true+.
32
+ # * +:backend_config+: a map of backend specific configuration parameters.
33
+ # * +:force_copy+: if +true+, suppresses prompts about copying state data;
34
+ # this is equivalent to providing a "yes" to all confirmation prompts;
35
+ # defaults to +false+.
36
+ # * +:from_module+: copies the contents of the given module into the target
37
+ # directory before initialization.
38
+ # * +:get+: whether or not to download any modules for this configuration;
39
+ # defaults to +true+.
40
+ # * +:get_plugins+: whether or not to install plugins for this
41
+ # configuration; defaults to +true+ (deprecated, removed in terraform
42
+ # 0.15).
43
+ # * +:input+: when +false+, will not ask for input for variables not
44
+ # directly set; defaults to +true+.
45
+ # * +:lock+: when +true+, locks the state file when locking is supported;
46
+ # when +false+, does not lock the state file; defaults to +true+
47
+ # (deprecated, removed in terraform 0.15).
48
+ # * +:lock_timeout+: the duration to retry a state lock; defaults to +"0s"+;
49
+ # (deprecated, removed in terraform 0.15).
50
+ # * +:no_color+: whether or not the output from the command should be in
51
+ # color; defaults to +false+.
52
+ # * +:plugin_dir+: the path to a directory containing plugin binaries; this
53
+ # overrides all default search paths for plugins, and prevents the
54
+ # automatic installation of plugins.
55
+ # * +:reconfigure+: if +true+, reconfigures the backend, ignoring any saved
56
+ # configuration; defaults to +false+.
57
+ # * +:upgrade+: if +true+, when installing modules or plugins, ignores
58
+ # previously-downloaded objects and installs the latest version allowed
59
+ # within configured constraints; defaults to +false+.
60
+ # * +:verify_plugins+: whether or not to verify plugins for this
61
+ # configuration; defaults to +true+ (deprecated, removed in terraform
62
+ # 0.15).
63
+ #
64
+ # @example Basic Invocation
65
+ # RubyTerraform::Commands::Init.new.execute(
66
+ # from_module: 'some/module/path',
67
+ # path: 'infra/module')
68
+ #
8
69
  class Init < Base
9
70
  include RubyTerraform::Options::Common
10
71
 
72
+ # @!visibility private
11
73
  def subcommands
12
74
  %w[init]
13
75
  end
14
76
 
15
- def options # rubocop:disable Metrics/MethodLength
77
+ # rubocop:disable Metrics/MethodLength
78
+
79
+ # @!visibility private
80
+ # @todo Add lockfile option.
81
+ # @todo Make plugin_dir option plural
82
+ def options
16
83
  %w[
17
84
  -backend
18
85
  -backend-config
@@ -31,10 +98,14 @@ module RubyTerraform
31
98
  ] + super
32
99
  end
33
100
 
101
+ # rubocop:enable Metrics/MethodLength
102
+
103
+ # @!visibility private
34
104
  def arguments(parameters)
35
105
  [parameters[:path]]
36
106
  end
37
107
 
108
+ # @!visibility private
38
109
  def parameter_defaults(_parameters)
39
110
  { backend_config: {} }
40
111
  end
@@ -5,13 +5,37 @@ require_relative '../options/common'
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
31
  include RubyTerraform::Options::Common
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
@@ -5,13 +5,34 @@ require_relative '../options/common'
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
28
  include RubyTerraform::Options::Common
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
@@ -6,19 +6,47 @@ require_relative '../options/common'
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
37
  include RubyTerraform::Options::Common
11
38
 
12
- def initialize_command
13
- return if defined?(@stdout) && @stdout.respond_to?(:string)
14
-
15
- @stdout = StringIO.new
39
+ # @!visibility private
40
+ def stdout
41
+ @stdout.respond_to?(:string) ? @stdout : (@stdout = StringIO.new)
16
42
  end
17
43
 
44
+ # @!visibility private
18
45
  def subcommands
19
46
  %w[output]
20
47
  end
21
48
 
49
+ # @!visibility private
22
50
  def options
23
51
  %w[
24
52
  -json
@@ -28,10 +56,12 @@ module RubyTerraform
28
56
  ] + super
29
57
  end
30
58
 
59
+ # @!visibility private
31
60
  def arguments(parameters)
32
61
  [parameters[:name]]
33
62
  end
34
63
 
64
+ # @!visibility private
35
65
  def do_after(parameters)
36
66
  result = stdout.string
37
67
  parameters[:name] ? result.chomp : result
@@ -5,14 +5,76 @@ require_relative '../options/common'
5
5
 
6
6
  module RubyTerraform
7
7
  module Commands
8
+ # Wraps the +terraform plan+ command which generates a speculative execution
9
+ # plan, showing what actions Terraform would take to apply the current
10
+ # configuration. This command will not actually perform the planned actions.
11
+ #
12
+ # You can optionally save the plan to a file, which you can then pass to
13
+ # the {Apply} command to perform exactly the actions described in the plan.
14
+ #
15
+ # For options accepted on construction, see {#initialize}.
16
+ #
17
+ # When executing an instance of {Plan} via {#execute}, the following
18
+ # options are supported:
19
+ #
20
+ # * +:plan+: the path to output the plan if it should be saved to a file.
21
+ # * +:chdir+: the path of a working directory to switch to before executing
22
+ # the given subcommand.
23
+ # * +:compact_warnings+: when +true+, if terraform produces any warnings
24
+ # that are not accompanied by errors, they are shown in a more compact
25
+ # form that includes only the summary messages; defaults to +false+.
26
+ # * +:destroy+: when +true+, a plan will be generated to destroy all
27
+ # resources managed by the given configuration and state; defaults to
28
+ # +false+.
29
+ # * +:detailed_exitcode+: whether or not to return detailed exit codes when
30
+ # the command exits; this will change the meaning of exit codes to:
31
+ # 0 - Succeeded, diff is empty (no changes); 1 - Errored; 2 - Succeeded,
32
+ # there is a diff; defaults to +false+.
33
+ # * +:input+: when +false+, will not ask for input for variables not
34
+ # directly set; defaults to +true+.
35
+ # * +:lock+: when +true+, locks the state file when locking is supported;
36
+ # when +false+, does not lock the state file; defaults to +true+.
37
+ # * +:lock_timeout+: the duration to retry a state lock; defaults to +"0s"+.
38
+ # * +:no_color+: whether or not the output from the command should be in
39
+ # color; defaults to +false+.
40
+ # * +:parallelism+: the number of parallel resource operations; defaults to
41
+ # +10+.
42
+ # * +:refresh+: when +true+, updates state prior to checking for
43
+ # differences; when +false+ uses locally available state; defaults to
44
+ # +true+; this has no effect when +:plan+ is provided.
45
+ # * +:state+: the path to the state file from which to read state and in
46
+ # which to store state (unless +:state_out+ is specified); defaults to
47
+ # +"terraform.tfstate"+.
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::Plan.new.execute(
61
+ # directory: 'infra/networking',
62
+ # vars: {
63
+ # region: 'eu-central'
64
+ # })
65
+ #
8
66
  class Plan < Base
9
67
  include RubyTerraform::Options::Common
10
68
 
69
+ # @!visibility private
11
70
  def subcommands
12
71
  %w[plan]
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[
17
79
  -compact-warnings
18
80
  -destroy
@@ -31,10 +93,14 @@ 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