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

Sign up to get free protection for your applications and to get access to all the features.
@@ -23,13 +23,13 @@ module RubyTerraform
23
23
  # required unless +:plan+ is provided.
24
24
  # * +:plan+: the path to a pre-computed plan to be applied;
25
25
  # required unless +:directory+ is provided.
26
+ # * +:chdir+: the path of a working directory to switch to before executing
27
+ # the given subcommand.
26
28
  # * +:auto_approve+: if +true+, skips interactive approval of the generated
27
29
  # plan before applying; defaults to +false+.
28
30
  # * +:backup+: the path to backup the existing state file before modifying;
29
31
  # defaults to the +:state_out+ path with +".backup"+ extension; set
30
32
  # +:no_backup+ to +true+ to skip backups entirely.
31
- # * +:chdir+: the path of a working directory to switch to before executing
32
- # the given subcommand.
33
33
  # * +:compact_warnings+: when +true+, if terraform produces any warnings
34
34
  # that are not accompanied by errors, they are shown in a more compact
35
35
  # form that includes only the summary messages; defaults to +false+.
@@ -5,14 +5,75 @@ require_relative '../options/common'
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 directory containing terraform configuration;
17
+ # required.
18
+ # * +:chdir+: the path of a working directory to switch to before executing
19
+ # the given subcommand.
20
+ # * +:auto_approve+: if +true+, skips interactive approval before
21
+ # destroying; defaults to +false+.
22
+ # * +:backup+: (legacy) the path to backup the existing state file before
23
+ # modifying; defaults to the +:state_out+ path with +".backup"+ extension;
24
+ # set +:no_backup+ to +true+ to skip backups entirely.
25
+ # * +:compact_warnings+: when +true+, if terraform produces any warnings
26
+ # that are not accompanied by errors, they are shown in a more compact
27
+ # form that includes only the summary messages; defaults to +false+.
28
+ # * +:input+: when +false+, will not ask for input for variables not
29
+ # directly set; defaults to +true+.
30
+ # * +:lock+: when +true+, locks the state file when locking is supported;
31
+ # when +false+, does not lock the state file; defaults to +true+.
32
+ # * +:lock_timeout+: the duration to retry a state lock; defaults to +"0s"+.
33
+ # * +:no_backup+: when +true+, no backup file will be written; defaults to
34
+ # +false+.
35
+ # * +:no_color+: whether or not the output from the command should be in
36
+ # color; defaults to +false+.
37
+ # * +:parallelism+: the number of parallel resource operations; defaults to
38
+ # +10+.
39
+ # * +:refresh+: when +true+, updates state prior to checking for
40
+ # differences; when +false+ uses locally available state; defaults to
41
+ # +true+.
42
+ # * +:state+: (legacy) the path to the state file from which to read state
43
+ # and in which to store state (unless +:state_out+ is specified); defaults
44
+ # to +"terraform.tfstate"+.
45
+ # * +:state_out+: (legacy) the path to write state to that is different than
46
+ # +:state+; this can be used to preserve the old state.
47
+ # * +:target+: the address of a resource to target; if both +:target+ and
48
+ # +:targets+ are provided, all targets will be passed to terraform.
49
+ # * +:targets+: an array of resource addresses to target; if both +:target+
50
+ # and +:targets+ are provided, all targets will be passed to terraform.
51
+ # * +:vars+: a map of variables to be passed to the terraform configuration.
52
+ # * +:var_file+: the path to a terraform var file; if both +:var_file+ and
53
+ # +:var_files+ are provided, all var files will be passed to terraform.
54
+ # * +:var_files+: an array of paths to terraform var files; if both
55
+ # +:var_file+ and +:var_files+ are provided, all var files will be passed
56
+ # to terraform.
57
+ #
58
+ # @example Basic Invocation
59
+ # RubyTerraform::Commands::Destroy.new.execute(
60
+ # directory: 'infra/networking',
61
+ # vars: {
62
+ # region: 'eu-central'
63
+ # })
64
+ #
8
65
  class Destroy < Base
9
66
  include RubyTerraform::Options::Common
10
67
 
68
+ # @!visibility private
11
69
  def subcommands
12
70
  %w[destroy]
13
71
  end
14
72
 
15
- def options # rubocop:disable Metrics/MethodLength
73
+ # rubocop:disable Metrics/MethodLength
74
+
75
+ # @!visibility private
76
+ def options
16
77
  %w[
17
78
  -backup
18
79
  -compact-warnings
@@ -31,14 +92,19 @@ module RubyTerraform
31
92
  ] + super
32
93
  end
33
94
 
95
+ # rubocop:enable Metrics/MethodLength
96
+
97
+ # @!visibility private
34
98
  def arguments(parameters)
35
99
  [parameters[:directory]]
36
100
  end
37
101
 
102
+ # @!visibility private
38
103
  def parameter_defaults(_parameters)
39
104
  { vars: {}, var_files: [], targets: [] }
40
105
  end
41
106
 
107
+ # @!visibility private
42
108
  def parameter_overrides(parameters)
43
109
  { backup: parameters[:no_backup] ? '-' : parameters[:backup] }
44
110
  end
@@ -5,17 +5,45 @@ require_relative '../options/common'
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
+ # * +:chdir+: the path of a working directory to switch to before executing
24
+ # the given subcommand.
25
+ # * +:force+: If +true+, does not ask for input for unlock confirmation;
26
+ # defaults to +false+.
27
+ #
28
+ # @example Basic Invocation
29
+ # RubyTerraform::Commands::ForceUnlock.new.execute(
30
+ # lock_id: '50e844a7-ebb0-fcfd-da85-5cce5bd1ec90')
31
+ #
8
32
  class ForceUnlock < Base
9
33
  include RubyTerraform::Options::Common
10
34
 
35
+ # @!visibility private
11
36
  def subcommands
12
37
  %w[force-unlock]
13
38
  end
14
39
 
40
+ # @!visibility private
15
41
  def options
16
42
  %w[-force] + super
17
43
  end
18
44
 
45
+ # @!visibility private
46
+ # @todo Add directory option.
19
47
  def arguments(parameters)
20
48
  [parameters[:lock_id]]
21
49
  end
@@ -5,13 +5,51 @@ require_relative '../options/common'
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 directory containing terraform configuration.
25
+ # * +:chdir+: the path of a working directory to switch to before executing
26
+ # the given subcommand.
27
+ # * +:list+: If +true+, lists files whose formatting differs; defaults to
28
+ # +false+; always disabled if using standard input.
29
+ # * +:write+: If +true+, writes to source files; defaults to +false+; always
30
+ # disabled if using standard input or +:check+ is +true+.
31
+ # * +:diff+: If +true+, displays diffs of formatting changes; defaults to
32
+ # +false+.
33
+ # * +:check+: If +true+, checks if the input is formatted; if any input is
34
+ # not properly formatted, an {RubyTerraform::Errors::ExecutionError} will
35
+ # be thrown; defaults to +false+.
36
+ # * +:recursive+: If +true+, also processes files in subdirectories;
37
+ # defaults to +false+ such that only the provided +:directory+ is
38
+ # processed.
39
+ #
40
+ # @example Basic Invocation
41
+ # RubyTerraform::Commands::Format.new.execute(
42
+ # directory: 'infra/networking')
8
43
  class Format < Base
9
44
  include RubyTerraform::Options::Common
10
45
 
46
+ # @!visibility private
11
47
  def subcommands
12
48
  %w[fmt]
13
49
  end
14
50
 
51
+ # @!visibility private
52
+ # @todo Add no_color option.
15
53
  def options
16
54
  %w[
17
55
  -list
@@ -22,6 +60,7 @@ module RubyTerraform
22
60
  ] + super
23
61
  end
24
62
 
63
+ # @!visibility private
25
64
  def arguments(parameters)
26
65
  [parameters[:directory]]
27
66
  end
@@ -5,13 +5,43 @@ require_relative '../options/common'
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 directory containing terraform configuration;
25
+ # required.
26
+ # * +:chdir+: the path of a working directory to switch to before executing
27
+ # the given subcommand.
28
+ # * +:update+: if +true+, checks already-downloaded modules for available
29
+ # updates and installs the newest versions available; defaults to +false+.
30
+ # * +:no_color+: whether or not the output from the command should be in
31
+ # color; defaults to +false+.
32
+ #
33
+ # @example Basic Invocation
34
+ # RubyTerraform::Commands::Get.new.execute(
35
+ # directory: 'infra/networking')
8
36
  class Get < Base
9
37
  include RubyTerraform::Options::Common
10
38
 
39
+ # @!visibility private
11
40
  def subcommands
12
41
  %w[get]
13
42
  end
14
43
 
44
+ # @!visibility private
15
45
  def options
16
46
  %w[
17
47
  -no-color
@@ -19,6 +49,7 @@ module RubyTerraform
19
49
  ] + super
20
50
  end
21
51
 
52
+ # @!visibility private
22
53
  def arguments(parameters)
23
54
  [parameters[:directory]]
24
55
  end
@@ -5,13 +5,51 @@ require_relative '../options/common'
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
+ # * +:chdir+: the path of a working directory to switch to before executing
28
+ # the given subcommand.
29
+ # * +:plan+: render the graph using the specified plan file instead of the
30
+ # configuration in the current directory.
31
+ # * +:draw_cycles+: if +true+, highlights any cycles in the graph with
32
+ # colored edges; this helps when diagnosing cycle errors; defaults to
33
+ # +false+.
34
+ # * +:type+: the type of graph to output; can be: +"plan"+,
35
+ # +"plan-destroy"+, +"apply"+, +"validate"+, +"input"+, +"refresh"+;
36
+ # defaults to +"apply"+ if +:plan+ is provided, +"plan"+ otherwise.
37
+ # * +:module_depth+: (deprecated) in prior versions of terraform, specified
38
+ # the depth of modules to show in the output.
39
+ #
40
+ # @example Basic Invocation
41
+ # RubyTerraform::Commands::Graph.new.execute
42
+ #
8
43
  class Graph < Base
9
44
  include RubyTerraform::Options::Common
10
45
 
46
+ # @!visibility private
11
47
  def subcommands
12
48
  %w[graph]
13
49
  end
14
50
 
51
+ # @!visibility private
52
+ # @todo Add plan option.
15
53
  def options
16
54
  %w[
17
55
  -draw-cycles
@@ -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