terraform-wrapper 1.3.1 → 1.3.3
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.
- checksums.yaml +4 -4
- data/lib/terraform-wrapper/shared/backends/aws.rb +61 -64
- data/lib/terraform-wrapper/shared/backends/azure.rb +17 -17
- data/lib/terraform-wrapper/shared/backends/common.rb +25 -31
- data/lib/terraform-wrapper/shared/backends/local.rb +38 -36
- data/lib/terraform-wrapper/shared/runner.rb +90 -88
- data/lib/terraform-wrapper/tasks/apply.rb +13 -19
- data/lib/terraform-wrapper/tasks/binary.rb +56 -58
- data/lib/terraform-wrapper/tasks/clean.rb +54 -60
- data/lib/terraform-wrapper/tasks/destroy.rb +13 -19
- data/lib/terraform-wrapper/tasks/fmt.rb +54 -0
- data/lib/terraform-wrapper/tasks/import.rb +13 -19
- data/lib/terraform-wrapper/tasks/init.rb +13 -19
- data/lib/terraform-wrapper/tasks/plan.rb +13 -19
- data/lib/terraform-wrapper/tasks/plandestroy.rb +13 -19
- data/lib/terraform-wrapper/tasks/taint.rb +13 -19
- data/lib/terraform-wrapper/tasks/upgrade.rb +11 -17
- data/lib/terraform-wrapper/tasks/validate.rb +14 -17
- data/lib/terraform-wrapper/tasks.rb +1 -0
- data/lib/terraform-wrapper/version.rb +3 -3
- data/lib/terraform-wrapper.rb +5 -4
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 22baabb5edc25221a988310ff2b77cf458770f3beb7cf6c7ca0fd684cfb6216e
|
4
|
+
data.tar.gz: 14f265238e48f3069fb4420b49cd9a63860a0f39d965328488def9a9cf7e0ec9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 04ac5b8332a7cb0cec87850e5d50a6ff31eff1aad2fc3adb36d9f63621fa3676e0a1b16fc79f3a254a5172237c25b34c4c545c4e3ad9a2fb22977b1017a1e9c4
|
7
|
+
data.tar.gz: 9aa9ce6282ca86c37eb527cef526fb6749e6a449c18d5f241dbcf426a775b8c2e2d270beff010f6f32d61efc796584705212ce9e6da40b16478751d997d4a5a7
|
@@ -1,108 +1,109 @@
|
|
1
1
|
###############################################################################
|
2
2
|
|
3
3
|
module TerraformWrapper
|
4
|
-
|
5
|
-
###############################################################################
|
4
|
+
#############################################################################
|
6
5
|
|
7
6
|
module Shared
|
8
|
-
|
9
|
-
###############################################################################
|
7
|
+
###########################################################################
|
10
8
|
|
11
9
|
module Backends
|
12
|
-
|
13
|
-
###############################################################################
|
10
|
+
#########################################################################
|
14
11
|
|
15
12
|
class AWS < Common
|
16
|
-
|
17
|
-
###############################################################################
|
13
|
+
#######################################################################
|
18
14
|
|
19
15
|
include TerraformWrapper::Shared::Logging
|
20
16
|
|
21
|
-
|
17
|
+
#######################################################################
|
22
18
|
|
23
|
-
@@default_class =
|
19
|
+
@@default_class = 'terraform-state'
|
24
20
|
|
25
|
-
|
21
|
+
#######################################################################
|
26
22
|
|
27
|
-
@@type =
|
23
|
+
@@type = 'aws'
|
28
24
|
|
29
|
-
|
25
|
+
#######################################################################
|
30
26
|
|
31
|
-
attr_reader :bucket
|
32
|
-
attr_reader :encrypt
|
33
|
-
attr_reader :key
|
34
|
-
attr_reader :region
|
27
|
+
attr_reader :bucket, :encrypt, :key, :region
|
35
28
|
|
36
|
-
|
29
|
+
#######################################################################
|
37
30
|
|
38
31
|
def initialize(options:, variables:)
|
39
32
|
construct(options: options, variables: variables)
|
40
33
|
end
|
41
34
|
|
42
|
-
|
35
|
+
#######################################################################
|
43
36
|
|
44
|
-
def hash
|
45
|
-
result =
|
37
|
+
def hash
|
38
|
+
result = {}
|
46
39
|
|
47
|
-
result[
|
48
|
-
result[
|
49
|
-
result[
|
50
|
-
result[
|
40
|
+
result['bucket'] = @bucket
|
41
|
+
result['region'] = @region
|
42
|
+
result['key'] = @key
|
43
|
+
result['encrypt'] = @encrypt.to_s
|
51
44
|
|
52
|
-
result[
|
53
|
-
result[
|
45
|
+
result['kms_key_id'] = @kms unless @kms.nil?
|
46
|
+
result['role_arn'] = @role unless @role.nil?
|
54
47
|
|
55
|
-
|
48
|
+
result
|
56
49
|
end
|
57
50
|
|
58
|
-
|
51
|
+
#######################################################################
|
59
52
|
|
60
53
|
private
|
61
54
|
|
62
|
-
|
55
|
+
#######################################################################
|
63
56
|
|
64
|
-
def specific
|
57
|
+
def specific
|
65
58
|
kms = nil
|
66
59
|
role = nil
|
67
60
|
|
68
|
-
logger.fatal("AWS backend mandatory option 'bucket' has not been set!") unless @options.key?(
|
69
|
-
logger.fatal("AWS backend mandatory option 'region' has not been set!") unless @options.key?(
|
61
|
+
logger.fatal("AWS backend mandatory option 'bucket' has not been set!") unless @options.key?('bucket')
|
62
|
+
logger.fatal("AWS backend mandatory option 'region' has not been set!") unless @options.key?('region')
|
70
63
|
|
71
|
-
bucket = @options[
|
64
|
+
bucket = @options['bucket']
|
72
65
|
|
73
|
-
logger.fatal(
|
74
|
-
logger.fatal(
|
66
|
+
logger.fatal('AWS backend S3 bucket name must be a string!') unless bucket.is_a?(String)
|
67
|
+
logger.fatal('AWS backend S3 bucket name must not be blank!') if bucket.strip.empty?
|
75
68
|
|
76
|
-
region = @options[
|
69
|
+
region = @options['region']
|
77
70
|
|
78
|
-
logger.fatal(
|
79
|
-
logger.fatal(
|
71
|
+
logger.fatal('AWS backend S3 bucket region must be a string!') unless region.is_a?(String)
|
72
|
+
logger.fatal('AWS backend S3 bucket region must not be blank!') if region.strip.empty?
|
80
73
|
|
81
|
-
key = @options.key?(
|
74
|
+
key = @options.key?('key') ? @options['key'] : File.join('%<service>s', '%<config>s', "%<component>s#{@@ext}")
|
82
75
|
|
83
|
-
logger.fatal(
|
84
|
-
logger.fatal(
|
76
|
+
logger.fatal('AWS backend S3 bucket key must be a string!') unless key.is_a?(String)
|
77
|
+
logger.fatal('AWS backend S3 bucket key must not be blank!') if key.strip.empty?
|
85
78
|
|
86
|
-
encrypt = @options.key?(
|
79
|
+
encrypt = @options.key?('encrypt') ? @options['encrypt'] : true
|
87
80
|
|
88
|
-
logger.fatal(
|
81
|
+
logger.fatal('AWS backend S3 bucket encryption enabled must be a Boolean!') unless [true,
|
82
|
+
false].include?(encrypt)
|
89
83
|
|
90
|
-
if @options.key?(
|
91
|
-
kms = @options[
|
84
|
+
if @options.key?('kms')
|
85
|
+
kms = @options['kms']
|
92
86
|
|
93
|
-
|
94
|
-
|
87
|
+
unless kms.is_a?(String)
|
88
|
+
logger.fatal('AWS backend S3 bucket encryption KMS key ARN must be a string if specified!')
|
89
|
+
end
|
90
|
+
if kms.strip.empty?
|
91
|
+
logger.fatal('AWS backend S3 bucket encryption KMS key ARN must not be blank if specified!')
|
92
|
+
end
|
95
93
|
end
|
96
94
|
|
97
|
-
if @options.key?(
|
98
|
-
role = @options[
|
95
|
+
if @options.key?('role')
|
96
|
+
role = @options['role']
|
99
97
|
|
100
|
-
logger.fatal(
|
101
|
-
logger.fatal(
|
98
|
+
logger.fatal('AWS backend role to assume ARN must be a string if specified!') unless role.is_a?(String)
|
99
|
+
logger.fatal('AWS backend role to assume ARN must not be blank if specified!') if role.strip.empty?
|
102
100
|
end
|
103
101
|
|
104
|
-
@variables.core.keys.map{ |sym| sym.to_s }.each do |core|
|
105
|
-
|
102
|
+
@variables.core.keys.map { |sym| sym.to_s }.each do |core|
|
103
|
+
unless bucket.include?("%<#{core}>s") || key.include?("%<#{core}>s") ||
|
104
|
+
bucket.include?("%{#{core}}") || key.include?("%{#{core}}")
|
105
|
+
logger.fatal("AWS backend S3 bucket name or key must include %<#{core}>s.")
|
106
|
+
end
|
106
107
|
end
|
107
108
|
|
108
109
|
begin
|
@@ -111,8 +112,8 @@ module TerraformWrapper
|
|
111
112
|
key = key % @variables.identifiers
|
112
113
|
kms = kms % @variables.identifiers unless kms.nil?
|
113
114
|
role = role % @variables.identifiers unless role.nil?
|
114
|
-
rescue
|
115
|
-
logger.fatal(
|
115
|
+
rescue StandardError
|
116
|
+
logger.fatal('AWS backend options contain identifiers that are not included in the configuration file!')
|
116
117
|
end
|
117
118
|
|
118
119
|
logger.fatal("Key: #{key} is too long for backend of type: #{@@type}") if key.length > 1024
|
@@ -125,20 +126,16 @@ module TerraformWrapper
|
|
125
126
|
@role = role
|
126
127
|
end
|
127
128
|
|
128
|
-
|
129
|
-
|
129
|
+
#######################################################################
|
130
130
|
end
|
131
131
|
|
132
|
-
|
133
|
-
|
132
|
+
#########################################################################
|
134
133
|
end
|
135
134
|
|
136
|
-
|
137
|
-
|
135
|
+
###########################################################################
|
138
136
|
end
|
139
137
|
|
140
|
-
|
141
|
-
|
138
|
+
#############################################################################
|
142
139
|
end
|
143
140
|
|
144
141
|
###############################################################################
|
@@ -1,34 +1,34 @@
|
|
1
1
|
###############################################################################
|
2
2
|
|
3
3
|
module TerraformWrapper
|
4
|
-
|
4
|
+
#############################################################################
|
5
5
|
|
6
6
|
module Shared
|
7
|
-
|
7
|
+
###########################################################################
|
8
8
|
|
9
9
|
module Backends
|
10
|
-
|
10
|
+
#########################################################################
|
11
11
|
|
12
12
|
class Azure < Common
|
13
|
-
|
13
|
+
#######################################################################
|
14
14
|
|
15
15
|
include TerraformWrapper::Shared::Logging
|
16
16
|
|
17
|
-
|
17
|
+
#######################################################################
|
18
18
|
|
19
19
|
@@type = 'azure'
|
20
20
|
|
21
|
-
|
21
|
+
#######################################################################
|
22
22
|
|
23
23
|
attr_reader :account, :container, :group, :key
|
24
24
|
|
25
|
-
|
25
|
+
#######################################################################
|
26
26
|
|
27
27
|
def initialize(options:, variables:)
|
28
28
|
construct(options: options, variables: variables)
|
29
29
|
end
|
30
30
|
|
31
|
-
|
31
|
+
#######################################################################
|
32
32
|
|
33
33
|
def hash
|
34
34
|
{
|
@@ -39,11 +39,11 @@ module TerraformWrapper
|
|
39
39
|
}
|
40
40
|
end
|
41
41
|
|
42
|
-
|
42
|
+
#######################################################################
|
43
43
|
|
44
44
|
private
|
45
45
|
|
46
|
-
|
46
|
+
#######################################################################
|
47
47
|
|
48
48
|
def specific
|
49
49
|
logger.fatal("Azure backend mandatory option 'group' has not been set!") unless @options.key?('group')
|
@@ -63,14 +63,14 @@ module TerraformWrapper
|
|
63
63
|
logger.fatal('Azure backend storage account container must be a string!') unless container.is_a?(String)
|
64
64
|
logger.fatal('Azure backend storage account container must not be blank!') if container.strip.empty?
|
65
65
|
|
66
|
-
key = @options.key?('key') ? @options['key'] : File.join('%<service>s', '%<config>s',
|
66
|
+
key = @options.key?('key') ? @options['key'] : File.join('%<service>s', '%<config>s', "%<component>s#{@@ext}")
|
67
67
|
|
68
68
|
logger.fatal('Azure backend storage account key must be a string!') unless key.is_a?(String)
|
69
69
|
logger.fatal('Azure backend storage account key must not be blank!') if key.strip.empty?
|
70
70
|
|
71
71
|
@variables.core.keys.map { |sym| sym.to_s }.each do |core|
|
72
|
-
unless container.include?("
|
73
|
-
container.include?("
|
72
|
+
unless container.include?("%<#{core}>s") || key.include?("%<#{core}>s") ||
|
73
|
+
container.include?("%{#{core}}") || key.include?("%{#{core}}")
|
74
74
|
logger.fatal("Azure backend container or key must include %<#{core}>s.")
|
75
75
|
end
|
76
76
|
end
|
@@ -96,16 +96,16 @@ module TerraformWrapper
|
|
96
96
|
@key = key
|
97
97
|
end
|
98
98
|
|
99
|
-
|
99
|
+
#######################################################################
|
100
100
|
end
|
101
101
|
|
102
|
-
|
102
|
+
#########################################################################
|
103
103
|
end
|
104
104
|
|
105
|
-
|
105
|
+
###########################################################################
|
106
106
|
end
|
107
107
|
|
108
|
-
|
108
|
+
#############################################################################
|
109
109
|
end
|
110
110
|
|
111
111
|
###############################################################################
|
@@ -1,58 +1,56 @@
|
|
1
1
|
###############################################################################
|
2
2
|
|
3
3
|
module TerraformWrapper
|
4
|
-
|
5
|
-
###############################################################################
|
4
|
+
#############################################################################
|
6
5
|
|
7
6
|
module Shared
|
8
|
-
|
9
|
-
###############################################################################
|
7
|
+
###########################################################################
|
10
8
|
|
11
9
|
module Backends
|
12
|
-
|
13
|
-
###############################################################################
|
10
|
+
#########################################################################
|
14
11
|
|
15
12
|
class Common
|
16
|
-
|
17
|
-
###############################################################################
|
13
|
+
#######################################################################
|
18
14
|
|
19
15
|
include TerraformWrapper::Shared::Logging
|
20
16
|
|
21
|
-
|
17
|
+
#######################################################################
|
22
18
|
|
23
|
-
@@ext =
|
19
|
+
@@ext = '.tfstate'
|
24
20
|
@@type
|
25
21
|
|
26
|
-
|
22
|
+
#######################################################################
|
27
23
|
|
28
24
|
@options
|
29
25
|
@variables
|
30
26
|
|
31
|
-
|
27
|
+
#######################################################################
|
32
28
|
|
33
29
|
def initialize(options:, variables:)
|
34
|
-
logger.fatal(
|
30
|
+
logger.fatal('This class should not be used directly! Please create a backend-specific class instead!')
|
35
31
|
end
|
36
32
|
|
37
|
-
|
33
|
+
#######################################################################
|
38
34
|
|
39
|
-
def hash
|
35
|
+
def hash
|
40
36
|
logger.fatal("The backend specific class should override the 'hash' method to return a hash of parameters for Terraform to set!")
|
41
37
|
end
|
42
38
|
|
43
|
-
|
39
|
+
#######################################################################
|
44
40
|
|
45
|
-
def type
|
46
|
-
|
41
|
+
def type
|
42
|
+
unless @@type.is_a?(String)
|
43
|
+
logger.fatal("The backend specific class should set the 'type' class variable to a string!")
|
44
|
+
end
|
47
45
|
|
48
|
-
|
46
|
+
@@type
|
49
47
|
end
|
50
48
|
|
51
|
-
|
49
|
+
#######################################################################
|
52
50
|
|
53
51
|
private
|
54
52
|
|
55
|
-
|
53
|
+
#######################################################################
|
56
54
|
|
57
55
|
def construct(options:, variables:)
|
58
56
|
@options = options
|
@@ -61,26 +59,22 @@ module TerraformWrapper
|
|
61
59
|
specific
|
62
60
|
end
|
63
61
|
|
64
|
-
|
62
|
+
#######################################################################
|
65
63
|
|
66
|
-
def specific
|
64
|
+
def specific
|
67
65
|
logger.fatal("The backend specific class should override the 'specific' method to include backend specific validation and setup, or simply return 'true' if it is not required.")
|
68
66
|
end
|
69
67
|
|
70
|
-
|
71
|
-
|
68
|
+
#######################################################################
|
72
69
|
end
|
73
70
|
|
74
|
-
|
75
|
-
|
71
|
+
#########################################################################
|
76
72
|
end
|
77
73
|
|
78
|
-
|
79
|
-
|
74
|
+
###########################################################################
|
80
75
|
end
|
81
76
|
|
82
|
-
|
83
|
-
|
77
|
+
#############################################################################
|
84
78
|
end
|
85
79
|
|
86
80
|
###############################################################################
|
@@ -1,89 +1,91 @@
|
|
1
1
|
###############################################################################
|
2
2
|
|
3
3
|
module TerraformWrapper
|
4
|
-
|
5
|
-
###############################################################################
|
4
|
+
#############################################################################
|
6
5
|
|
7
6
|
module Shared
|
8
|
-
|
9
|
-
###############################################################################
|
7
|
+
###########################################################################
|
10
8
|
|
11
9
|
module Backends
|
12
|
-
|
13
|
-
###############################################################################
|
10
|
+
#########################################################################
|
14
11
|
|
15
12
|
class Local < Common
|
16
|
-
|
17
|
-
###############################################################################
|
13
|
+
#######################################################################
|
18
14
|
|
19
15
|
include TerraformWrapper::Shared::Logging
|
20
16
|
|
21
|
-
|
17
|
+
#######################################################################
|
22
18
|
|
23
|
-
@@type =
|
19
|
+
@@type = 'local'
|
24
20
|
|
25
|
-
|
21
|
+
#######################################################################
|
26
22
|
|
27
23
|
attr_reader :path
|
28
24
|
|
29
|
-
|
25
|
+
#######################################################################
|
30
26
|
|
31
27
|
def initialize(options:, variables:)
|
32
28
|
construct(options: options, variables: variables)
|
33
29
|
end
|
34
30
|
|
35
|
-
|
31
|
+
#######################################################################
|
36
32
|
|
37
|
-
def hash
|
38
|
-
|
39
|
-
|
33
|
+
def hash
|
34
|
+
{
|
35
|
+
'path' => @path
|
40
36
|
}
|
41
37
|
end
|
42
38
|
|
43
|
-
|
39
|
+
#######################################################################
|
44
40
|
|
45
41
|
private
|
46
42
|
|
47
|
-
|
43
|
+
#######################################################################
|
44
|
+
|
45
|
+
def specific
|
46
|
+
path = if @options.key?('path')
|
47
|
+
@options['path']
|
48
|
+
else
|
49
|
+
File.join(Dir.pwd, 'state', 'terraform', '%<config>s',
|
50
|
+
"%<component>s#{@@ext}")
|
51
|
+
end
|
48
52
|
|
49
|
-
|
50
|
-
|
53
|
+
logger.fatal('Local backend path must be a string!') unless path.is_a?(String)
|
54
|
+
logger.fatal('Local backend path must not be blank!') if path.strip.empty?
|
51
55
|
|
52
|
-
|
53
|
-
|
56
|
+
@variables.core.keys.map { |sym| sym.to_s }.each do |core|
|
57
|
+
next if (core == 'service') && path.include?(Dir.pwd)
|
54
58
|
|
55
|
-
|
56
|
-
|
57
|
-
|
59
|
+
unless path.include?("%<#{core}>s") || path.include?("%{#{core}}")
|
60
|
+
logger.fatal("Local backend path must include %<#{core}>s.")
|
61
|
+
end
|
58
62
|
end
|
59
63
|
|
60
64
|
begin
|
61
65
|
path = path % @variables.identifiers
|
62
|
-
rescue
|
63
|
-
logger.fatal(
|
66
|
+
rescue StandardError
|
67
|
+
logger.fatal('Local backend options contain identifiers that are not included in the configuration file!')
|
64
68
|
end
|
65
69
|
|
66
70
|
directory = File.dirname(path)
|
67
71
|
|
68
|
-
logger.fatal("Failed to create state directory: #{directory}") unless ::TerraformWrapper.create_directory(
|
72
|
+
logger.fatal("Failed to create state directory: #{directory}") unless ::TerraformWrapper.create_directory(
|
73
|
+
directory: directory, purpose: 'state'
|
74
|
+
)
|
69
75
|
|
70
76
|
@path = path
|
71
77
|
end
|
72
78
|
|
73
|
-
|
74
|
-
|
79
|
+
#######################################################################
|
75
80
|
end
|
76
81
|
|
77
|
-
|
78
|
-
|
82
|
+
#########################################################################
|
79
83
|
end
|
80
84
|
|
81
|
-
|
82
|
-
|
85
|
+
###########################################################################
|
83
86
|
end
|
84
87
|
|
85
|
-
|
86
|
-
|
88
|
+
#############################################################################
|
87
89
|
end
|
88
90
|
|
89
91
|
###############################################################################
|