ruby-terraform 0.65.0.pre.15 → 1.0.0.pre.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +15 -15
- data/README.md +148 -397
- data/Rakefile +25 -0
- data/lib/ruby_terraform.rb +707 -45
- data/lib/ruby_terraform/commands.rb +0 -2
- data/lib/ruby_terraform/commands/apply.rb +7 -7
- data/lib/ruby_terraform/commands/base.rb +4 -1
- data/lib/ruby_terraform/commands/destroy.rb +6 -5
- data/lib/ruby_terraform/commands/force_unlock.rb +6 -4
- data/lib/ruby_terraform/commands/format.rb +8 -4
- data/lib/ruby_terraform/commands/get.rb +6 -4
- data/lib/ruby_terraform/commands/graph.rb +11 -3
- data/lib/ruby_terraform/commands/import.rb +8 -7
- data/lib/ruby_terraform/commands/init.rb +16 -6
- data/lib/ruby_terraform/commands/login.rb +2 -2
- data/lib/ruby_terraform/commands/logout.rb +2 -2
- data/lib/ruby_terraform/commands/output.rb +2 -2
- data/lib/ruby_terraform/commands/plan.rb +6 -3
- data/lib/ruby_terraform/commands/providers.rb +9 -3
- data/lib/ruby_terraform/commands/providers_lock.rb +10 -7
- data/lib/ruby_terraform/commands/providers_mirror.rb +3 -3
- data/lib/ruby_terraform/commands/providers_schema.rb +21 -2
- data/lib/ruby_terraform/commands/refresh.rb +70 -3
- data/lib/ruby_terraform/commands/show.rb +26 -3
- data/lib/ruby_terraform/commands/state_list.rb +54 -3
- data/lib/ruby_terraform/commands/state_move.rb +64 -6
- data/lib/ruby_terraform/commands/state_pull.rb +24 -2
- data/lib/ruby_terraform/commands/state_push.rb +49 -3
- data/lib/ruby_terraform/commands/state_remove.rb +55 -7
- data/lib/ruby_terraform/commands/state_replace_provider.rb +39 -6
- data/lib/ruby_terraform/commands/state_show.rb +26 -2
- data/lib/ruby_terraform/commands/taint.rb +63 -2
- data/lib/ruby_terraform/commands/untaint.rb +55 -2
- data/lib/ruby_terraform/commands/validate.rb +51 -6
- data/lib/ruby_terraform/commands/workspace_delete.rb +29 -7
- data/lib/ruby_terraform/commands/workspace_list.rb +21 -6
- data/lib/ruby_terraform/commands/workspace_new.rb +28 -7
- data/lib/ruby_terraform/commands/workspace_select.rb +23 -7
- data/lib/ruby_terraform/commands/workspace_show.rb +17 -2
- data/lib/ruby_terraform/options.rb +1 -1
- data/lib/ruby_terraform/options/definition.rb +3 -1
- data/lib/ruby_terraform/options/definitions.rb +12 -3
- data/lib/ruby_terraform/options/{common.rb → global.rb} +1 -1
- data/lib/ruby_terraform/options/types.rb +0 -1
- data/lib/ruby_terraform/options/types/flag.rb +8 -4
- data/lib/ruby_terraform/options/types/standard.rb +20 -6
- data/lib/ruby_terraform/version.rb +1 -1
- data/ruby_terraform.gemspec +2 -2
- metadata +9 -12
- data/lib/ruby_terraform/commands/clean.rb +0 -26
- data/lib/ruby_terraform/commands/remote_config.rb +0 -25
- data/lib/ruby_terraform/options/types/base.rb +0 -19
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
require 'stringio'
|
4
4
|
require_relative 'base'
|
5
|
-
require_relative '../options/
|
5
|
+
require_relative '../options/global'
|
6
6
|
|
7
7
|
module RubyTerraform
|
8
8
|
module Commands
|
@@ -34,7 +34,7 @@ module RubyTerraform
|
|
34
34
|
# name: 'vpc_id')
|
35
35
|
#
|
36
36
|
class Output < Base
|
37
|
-
include RubyTerraform::Options::
|
37
|
+
include RubyTerraform::Options::Global
|
38
38
|
|
39
39
|
# @!visibility private
|
40
40
|
def stdout
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require_relative 'base'
|
4
|
-
require_relative '../options/
|
4
|
+
require_relative '../options/global'
|
5
5
|
|
6
6
|
module RubyTerraform
|
7
7
|
module Commands
|
@@ -17,7 +17,9 @@ module RubyTerraform
|
|
17
17
|
# When executing an instance of {Plan} via {#execute}, the following
|
18
18
|
# options are supported:
|
19
19
|
#
|
20
|
-
# * +:
|
20
|
+
# * +:directory+: the path to a directory containing terraform
|
21
|
+
# configuration (deprecated in terraform 0.14, removed in terraform 0.15,
|
22
|
+
# use +:chdir+ instead).
|
21
23
|
# * +:chdir+: the path of a working directory to switch to before executing
|
22
24
|
# the given subcommand.
|
23
25
|
# * +:compact_warnings+: when +true+, if terraform produces any warnings
|
@@ -39,6 +41,7 @@ module RubyTerraform
|
|
39
41
|
# color; defaults to +false+.
|
40
42
|
# * +:parallelism+: the number of parallel resource operations; defaults to
|
41
43
|
# +10+.
|
44
|
+
# * +:plan+: the path to output the plan if it should be saved to a file.
|
42
45
|
# * +:refresh+: when +true+, updates state prior to checking for
|
43
46
|
# differences; when +false+ uses locally available state; defaults to
|
44
47
|
# +true+; this has no effect when +:plan+ is provided.
|
@@ -64,7 +67,7 @@ module RubyTerraform
|
|
64
67
|
# })
|
65
68
|
#
|
66
69
|
class Plan < Base
|
67
|
-
include RubyTerraform::Options::
|
70
|
+
include RubyTerraform::Options::Global
|
68
71
|
|
69
72
|
# @!visibility private
|
70
73
|
def subcommands
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require_relative 'base'
|
4
|
-
require_relative '../options/
|
4
|
+
require_relative '../options/global'
|
5
5
|
|
6
6
|
module RubyTerraform
|
7
7
|
module Commands
|
@@ -18,6 +18,9 @@ module RubyTerraform
|
|
18
18
|
# When executing an instance of {Plan} via {#execute}, the following
|
19
19
|
# options are supported:
|
20
20
|
#
|
21
|
+
# * +:directory+: the path to a directory containing terraform
|
22
|
+
# configuration (deprecated in terraform 0.14, removed in terraform 0.15,
|
23
|
+
# use +:chdir+ instead).
|
21
24
|
# * +:chdir+: the path of a working directory to switch to before executing
|
22
25
|
# the given subcommand.
|
23
26
|
#
|
@@ -25,14 +28,17 @@ module RubyTerraform
|
|
25
28
|
# RubyTerraform::Commands::Providers.new.execute
|
26
29
|
#
|
27
30
|
class Providers < Base
|
28
|
-
include RubyTerraform::Options::
|
31
|
+
include RubyTerraform::Options::Global
|
29
32
|
|
30
33
|
# @!visibility private
|
31
34
|
def subcommands
|
32
35
|
%w[providers]
|
33
36
|
end
|
34
37
|
|
35
|
-
#
|
38
|
+
# @!visibility private
|
39
|
+
def arguments(parameters)
|
40
|
+
[parameters[:directory]]
|
41
|
+
end
|
36
42
|
end
|
37
43
|
end
|
38
44
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require_relative 'base'
|
4
|
-
require_relative '../options/
|
4
|
+
require_relative '../options/global'
|
5
5
|
|
6
6
|
module RubyTerraform
|
7
7
|
module Commands
|
@@ -31,8 +31,12 @@ module RubyTerraform
|
|
31
31
|
# When executing an instance of {ProvidersLock} via {#execute}, the
|
32
32
|
# following options are supported:
|
33
33
|
#
|
34
|
-
# * +:
|
35
|
-
# should be updated
|
34
|
+
# * +:provider+: the provider source address for which the lock file
|
35
|
+
# should be updated; if both +:provider+ and +:providers+ are provided,
|
36
|
+
# all providers will be passed to Terraform.
|
37
|
+
# * +:providers+: an array of provider source addresses for which the lock
|
38
|
+
# file should be updated; if both +:provider+ and +:providers+ are
|
39
|
+
# provided, all providers will be passed to Terraform.
|
36
40
|
# * +:chdir+: the path of a working directory to switch to before executing
|
37
41
|
# the given subcommand.
|
38
42
|
# * +:fs_mirror+: if provided, consults the given filesystem mirror
|
@@ -65,10 +69,10 @@ module RubyTerraform
|
|
65
69
|
# RubyTerraform::Commands::ProvidersLock.new.execute(
|
66
70
|
# fs_mirror: "/usr/local/terraform/providers",
|
67
71
|
# platforms: ["windows_amd64", "darwin_amd64", "linux_amd64"],
|
68
|
-
#
|
72
|
+
# provider: "tf.example.com/ourcompany/ourplatform")
|
69
73
|
#
|
70
74
|
class ProvidersLock < Base
|
71
|
-
include RubyTerraform::Options::
|
75
|
+
include RubyTerraform::Options::Global
|
72
76
|
|
73
77
|
# @!visibility private
|
74
78
|
def subcommands
|
@@ -85,9 +89,8 @@ module RubyTerraform
|
|
85
89
|
end
|
86
90
|
|
87
91
|
# @!visibility private
|
88
|
-
# @todo Flatten arguments array to allow array of providers.
|
89
92
|
def arguments(parameters)
|
90
|
-
[parameters[:providers]]
|
93
|
+
[parameters[:provider], parameters[:providers]]
|
91
94
|
end
|
92
95
|
end
|
93
96
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require_relative 'base'
|
4
|
-
require_relative '../options/
|
4
|
+
require_relative '../options/global'
|
5
5
|
|
6
6
|
module RubyTerraform
|
7
7
|
module Commands
|
@@ -40,12 +40,12 @@ module RubyTerraform
|
|
40
40
|
# are provided, all platforms will be passed to Terraform.
|
41
41
|
#
|
42
42
|
# @example Basic Invocation
|
43
|
-
# RubyTerraform::Commands::
|
43
|
+
# RubyTerraform::Commands::ProvidersMirror.new.execute(
|
44
44
|
# directory: './plugins',
|
45
45
|
# platforms: ["windows_amd64", "darwin_amd64", "linux_amd64"])
|
46
46
|
#
|
47
47
|
class ProvidersMirror < Base
|
48
|
-
include RubyTerraform::Options::
|
48
|
+
include RubyTerraform::Options::Global
|
49
49
|
|
50
50
|
# @!visibility private
|
51
51
|
def subcommands
|
@@ -1,21 +1,40 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require_relative 'base'
|
4
|
-
require_relative '../options/
|
4
|
+
require_relative '../options/global'
|
5
5
|
|
6
6
|
module RubyTerraform
|
7
7
|
module Commands
|
8
|
+
# Wraps the +terraform providers schema+ command which prints out a json
|
9
|
+
# representation of the schemas for all providers used in the current
|
10
|
+
# configuration.
|
11
|
+
#
|
12
|
+
# For options accepted on construction, see {#initialize}.
|
13
|
+
#
|
14
|
+
# When executing an instance of {ProvidersSchema} via {#execute}, the
|
15
|
+
# following options are supported:
|
16
|
+
#
|
17
|
+
# * +:chdir+: the path of a working directory to switch to before executing
|
18
|
+
# the given subcommand.
|
19
|
+
#
|
20
|
+
# @example Basic Invocation
|
21
|
+
# RubyTerraform::Commands::ProvidersSchema.new.execute(
|
22
|
+
# directory: 'infra/networking')
|
23
|
+
#
|
8
24
|
class ProvidersSchema < Base
|
9
|
-
include RubyTerraform::Options::
|
25
|
+
include RubyTerraform::Options::Global
|
10
26
|
|
27
|
+
# @!visibility private
|
11
28
|
def subcommands
|
12
29
|
%w[providers schema]
|
13
30
|
end
|
14
31
|
|
32
|
+
# @!visibility private
|
15
33
|
def options
|
16
34
|
%w[-json] + super
|
17
35
|
end
|
18
36
|
|
37
|
+
# @!visibility private
|
19
38
|
def parameter_overrides(_parameters)
|
20
39
|
# Terraform 0.15 - at this time, the -json flag is a required option.
|
21
40
|
{ json: true }
|
@@ -1,18 +1,80 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require_relative 'base'
|
4
|
-
require_relative '../options/
|
4
|
+
require_relative '../options/global'
|
5
5
|
|
6
6
|
module RubyTerraform
|
7
7
|
module Commands
|
8
|
+
# Wraps the +terraform refresh+ command which updates the state file of your
|
9
|
+
# infrastructure with metadata that matches the physical resources they are
|
10
|
+
# tracking.
|
11
|
+
#
|
12
|
+
# This will not modify your infrastructure, but it can modify your state
|
13
|
+
# file to update metadata. This metadata might cause new changes to occur
|
14
|
+
# when you generate a plan or call apply next.
|
15
|
+
#
|
16
|
+
# For options accepted on construction, see {#initialize}.
|
17
|
+
#
|
18
|
+
# When executing an instance of {Refresh} via {#execute}, the following
|
19
|
+
# options are supported:
|
20
|
+
#
|
21
|
+
# * +:directory+: the path to a directory containing terraform configuration
|
22
|
+
# (deprecated in terraform 0.14, removed in terraform 0.15, use +:chdir+
|
23
|
+
# instead).
|
24
|
+
# * +:chdir+: the path of a working directory to switch to before executing
|
25
|
+
# the given subcommand.
|
26
|
+
# * +:backup+: the path to backup the existing state file before modifying;
|
27
|
+
# defaults to the +:state_out+ path with +".backup"+ extension; set
|
28
|
+
# +:no_backup+ to +true+ to skip backups entirely (legacy).
|
29
|
+
# * +:compact_warnings+: when +true+, if terraform produces any warnings
|
30
|
+
# that are not accompanied by errors, they are shown in a more compact
|
31
|
+
# form that includes only the summary messages; defaults to +false+.
|
32
|
+
# * +:input+: when +false+, will not ask for input for variables not
|
33
|
+
# directly set; defaults to +true+.
|
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
|
+
# * +:no_backup+: when +true+, no backup file will be written; defaults to
|
38
|
+
# +false+ (legacy).
|
39
|
+
# * +:no_color+: whether or not the output from the command should be in
|
40
|
+
# color; defaults to +false+.
|
41
|
+
# * +:parallelism+: the number of parallel resource operations; defaults to
|
42
|
+
# +10+.
|
43
|
+
# * +:state+: the path to the state file from which to read state and in
|
44
|
+
# which to store state (unless +:state_out+ is specified); defaults to
|
45
|
+
# +"terraform.tfstate"+ (legacy).
|
46
|
+
# * +:state_out+: the path to write state to that is different than
|
47
|
+
# +:state+; this can be used to preserve the old state (legacy).
|
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::Refresh.new.execute(
|
61
|
+
# directory: 'infra/networking',
|
62
|
+
# vars: {
|
63
|
+
# region: 'eu-central'
|
64
|
+
# })
|
65
|
+
#
|
8
66
|
class Refresh < Base
|
9
|
-
include RubyTerraform::Options::
|
67
|
+
include RubyTerraform::Options::Global
|
10
68
|
|
69
|
+
# @!visibility private
|
11
70
|
def subcommands
|
12
71
|
%w[refresh]
|
13
72
|
end
|
14
73
|
|
15
|
-
|
74
|
+
# rubocop:disable Metrics/MethodLength
|
75
|
+
|
76
|
+
# @!visibility private
|
77
|
+
def options
|
16
78
|
%w[
|
17
79
|
-backup
|
18
80
|
-compact-warnings
|
@@ -29,14 +91,19 @@ module RubyTerraform
|
|
29
91
|
] + super
|
30
92
|
end
|
31
93
|
|
94
|
+
# rubocop:enable Metrics/MethodLength
|
95
|
+
|
96
|
+
# @!visibility private
|
32
97
|
def arguments(parameters)
|
33
98
|
[parameters[:directory]]
|
34
99
|
end
|
35
100
|
|
101
|
+
# @!visibility private
|
36
102
|
def parameter_defaults(_parameters)
|
37
103
|
{ vars: {}, var_files: [], targets: [] }
|
38
104
|
end
|
39
105
|
|
106
|
+
# @!visibility private
|
40
107
|
def parameter_overrides(parameters)
|
41
108
|
{ backup: parameters[:no_backup] ? '-' : parameters[:backup] }
|
42
109
|
end
|
@@ -1,17 +1,39 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require_relative 'base'
|
4
|
-
require_relative '../options/
|
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::
|
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]
|
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/
|
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::
|
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/
|
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::
|
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
|