terraform-wrapper 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f7338d84681486fc0e4e0f7135bdbf48327ed5d074c545b16f4c934ed1601698
4
- data.tar.gz: 48a5e381f0dfa34084b65025a6cf2de67e017c1a52bf9fe7f29302a4a50b213a
3
+ metadata.gz: 55d9fe8e3823828068db9f36f402b43a3a163e13a21eeae6372f4f62d54c8b55
4
+ data.tar.gz: 815b07b1e492517c8712b9c2f4c604d73dfe30a5ad16c571e77b34bfe6fb6285
5
5
  SHA512:
6
- metadata.gz: 590c7262c9d433a058c300d5f5f11e5cdbf2f4722f7aa9ea5cb341923c14666cb8ad8dcbee92df81b5d3cd6d3868c4cf635a67ffbcbe8103fbe90e928bb28928
7
- data.tar.gz: 9f335a63961bed6a0a807d9ef504b2f44a76748ff7e4459d687d1f40c74085ad0e6dd1767fcd5b68c5bebef8bd7824415a6f17fac83b78075ef0792ee006d355
6
+ metadata.gz: ea5f272f105000df04c9681d06a46f3cc19e588eefda12560bc3c637f465b0195c94e64477e3a03fb1c4c74084aa0a0b3317ee28fbc27a3d692ad91ecc8022dc
7
+ data.tar.gz: 9e03e5875feb041349cf51b3ff40a6796d4e1dee8f8e1307b281bca8ab710803cd2d67fc0b83258a2c73048c06db484cb8cb6c8b6ad0ede2961b5c8c380131d5
@@ -78,7 +78,7 @@ module TerraformWrapper
78
78
  stdout = `#{cmdline}`
79
79
  code = $?.exitstatus
80
80
 
81
- logger.fatal("Failed to get secret: #{name} from key vault: #{vault}!") if (code != 0 and stdout.strip.empty?)
81
+ logger.fatal("Failed to get secret: #{name} from key vault: #{vault}!") if (code != 0 or stdout.strip.empty?)
82
82
 
83
83
  return(stdout.strip)
84
84
  end
@@ -97,11 +97,11 @@ module TerraformWrapper
97
97
  details = YAML.load(stdout.strip)
98
98
 
99
99
  logger.fatal("Returned details did not include the subscription ID!") unless details.key?("id")
100
- logger.fatal("Returned subscription ID is not a String!") unless details["id"].kind_of?(String)
100
+ logger.fatal("Returned subscription ID is not a string!") unless details["id"].kind_of?(String)
101
101
  logger.fatal("Returned subscription ID is empty!") if details["id"].strip.empty?
102
102
 
103
103
  logger.fatal("Returned details did not include the tenant ID!") unless details.key?("tenant")
104
- logger.fatal("Returned tenant ID is not a String!") unless details["tenant"].kind_of?(String)
104
+ logger.fatal("Returned tenant ID is not a string!") unless details["tenant"].kind_of?(String)
105
105
  logger.fatal("Returned tenant ID is empty!") if details["tenant"].strip.empty?
106
106
 
107
107
  details.transform_values! { |value| value.strip }
@@ -120,27 +120,34 @@ module TerraformWrapper
120
120
  logger.fatal("Azure CLI must be installed and accessible to use the Azure authenticator.") unless cli
121
121
 
122
122
  logger.fatal("Azure authenticator mandatory option 'subscription' has not been set!") unless @options.key?("subscription")
123
+ logger.fatal("Azure authenticator subscription must be a string!") unless @options["subscription"].kind_of?(String)
124
+ logger.fatal("Azure authenticator subscription must not be blank!") if @options["subscription"].strip.empty?
123
125
 
124
126
  subscription = @options["subscription"]
125
127
 
126
- logger.fatal("Azure authenticator subscription must be a String!") unless subscription.kind_of?(String)
127
- logger.fatal("Azure authenticator subscription must not be blank!") if subscription.strip.empty?
128
-
129
128
  if @options.key?("keyvault") then
130
- keyvault = @options["keyvault"]
129
+ logger.fatal("Azure authenticator keyvault name must be a string if specified!") unless @options["keyvault"].kind_of?(String)
130
+ logger.fatal("Azure authenticator keyvault name must not be blank if specified!") if @options["keyvault"].strip.empty?
131
131
 
132
- logger.fatal("Azure authenticator keyvault name must be a String if specified!") unless keyvault.kind_of?(String)
133
- logger.fatal("Azure authenticator keyvault name must not be blank if specified!") if keyvault.strip.empty?
132
+ keyvault = @options["keyvault"]
134
133
 
135
- username = @options.key?("username-secret") ? @options["username-secret"] : "terraform-username"
134
+ if @options.key?("username-secret") then
135
+ logger.fatal("Azure authenticator keyvault secret for username must be a string if keyvault name is specified!") unless @options["username-secret"].kind_of?(String)
136
+ logger.fatal("Azure authenticator keyvault secret for username must not be blank if keyvault name is specified!") if @options["username-secret"].strip.empty?
136
137
 
137
- logger.fatal("Azure authenticator keyvault secret for username must be a String if keyvault name is specified!") unless username.kind_of?(String)
138
- logger.fatal("Azure authenticator keyvault secret for username must not be blank if keyvault name is specified!") if username.strip.empty?
138
+ username = @options["username-secret"]
139
+ else
140
+ username = "terraform-username"
141
+ end
139
142
 
140
- password = @options.key?("username-password") ? @options["username-password"] : "terraform-password"
143
+ if @options.key?("password-secret") then
144
+ logger.fatal("Azure authenticator keyvault secret for password must be a string if keyvault name is specified!") unless @options["password-secret"].kind_of?(String)
145
+ logger.fatal("Azure authenticator keyvault secret for password must not be blank if keyvault name is specified!") if @options["password-secret"].strip.empty?
141
146
 
142
- logger.fatal("Azure authenticator keyvault secret for password must be a String if keyvault name is specified!") unless password.kind_of?(String)
143
- logger.fatal("Azure authenticator keyvault secret for password must not be blank if keyvault name is specified!") if password.strip.empty?
147
+ password = @options["password-secret"]
148
+ else
149
+ password = "terraform-password"
150
+ end
144
151
  end
145
152
 
146
153
  begin
@@ -70,17 +70,17 @@ module TerraformWrapper
70
70
 
71
71
  bucket = @options["bucket"]
72
72
 
73
- logger.fatal("AWS backend S3 bucket name must be a String!") unless bucket.kind_of?(String)
73
+ logger.fatal("AWS backend S3 bucket name must be a string!") unless bucket.kind_of?(String)
74
74
  logger.fatal("AWS backend S3 bucket name must not be blank!") if bucket.strip.empty?
75
75
 
76
76
  region = @options["region"]
77
77
 
78
- logger.fatal("AWS backend S3 bucket region must be a String!") unless region.kind_of?(String)
78
+ logger.fatal("AWS backend S3 bucket region must be a string!") unless region.kind_of?(String)
79
79
  logger.fatal("AWS backend S3 bucket region must not be blank!") if region.strip.empty?
80
80
 
81
81
  key = @options.key?("key") ? @options["key"] : File.join("%{service}", "%{config}", "%{component}" + @@ext)
82
82
 
83
- logger.fatal("AWS backend S3 bucket key must be a String!") unless key.kind_of?(String)
83
+ logger.fatal("AWS backend S3 bucket key must be a string!") unless key.kind_of?(String)
84
84
  logger.fatal("AWS backend S3 bucket key must not be blank!") if key.strip.empty?
85
85
 
86
86
  encrypt = @options.key?("encrypt") ? @options["encrypt"] : true
@@ -90,14 +90,14 @@ module TerraformWrapper
90
90
  if @options.key?("kms") then
91
91
  kms = @options["kms"]
92
92
 
93
- logger.fatal("AWS backend S3 bucket encryption KMS key ARN must be a String if specified!") unless kms.kind_of?(String)
93
+ logger.fatal("AWS backend S3 bucket encryption KMS key ARN must be a string if specified!") unless kms.kind_of?(String)
94
94
  logger.fatal("AWS backend S3 bucket encryption KMS key ARN must not be blank if specified!") if kms.strip.empty?
95
95
  end
96
96
 
97
97
  if @options.key?("role") then
98
98
  role = @options["role"]
99
99
 
100
- logger.fatal("AWS backend role to assume ARN must be a String if specified!") unless role.kind_of?(String)
100
+ logger.fatal("AWS backend role to assume ARN must be a string if specified!") unless role.kind_of?(String)
101
101
  logger.fatal("AWS backend role to assume ARN must not be blank if specified!") if role.strip.empty?
102
102
  end
103
103
 
@@ -57,22 +57,22 @@ module TerraformWrapper
57
57
 
58
58
  group = @options["group"]
59
59
 
60
- logger.fatal("Azure backend group must be a String!") unless group.kind_of?(String)
60
+ logger.fatal("Azure backend group must be a string!") unless group.kind_of?(String)
61
61
  logger.fatal("Azure backend group must not be blank!") if group.strip.empty?
62
62
 
63
63
  account = @options.key?("account") ? @options["account"] : group + "tf"
64
64
 
65
- logger.fatal("Azure backend storage account must be a String!") unless account.kind_of?(String)
65
+ logger.fatal("Azure backend storage account must be a string!") unless account.kind_of?(String)
66
66
  logger.fatal("Azure backend storage account must not be blank!") if account.strip.empty?
67
67
 
68
68
  container = @options.key?("container") ? @options["container"] : "default"
69
69
 
70
- logger.fatal("Azure backend storage account container must be a String!") unless container.kind_of?(String)
70
+ logger.fatal("Azure backend storage account container must be a string!") unless container.kind_of?(String)
71
71
  logger.fatal("Azure backend storage account container must not be blank!") if container.strip.empty?
72
72
 
73
73
  key = @options.key?("key") ? @options["key"] : File.join("%{service}", "%{config}", "%{component}" + @@ext)
74
74
 
75
- logger.fatal("Azure backend storage account key must be a String!") unless key.kind_of?(String)
75
+ logger.fatal("Azure backend storage account key must be a string!") unless key.kind_of?(String)
76
76
  logger.fatal("Azure backend storage account key must not be blank!") if key.strip.empty?
77
77
 
78
78
  logger.fatal("Azure backend container or key must include %{service}.") unless (container.include?("%{service}") or key.include?("%{service}"))
@@ -49,7 +49,7 @@ module TerraformWrapper
49
49
  def specific()
50
50
  path = @options.key?("path") ? @options["path"] : File.join(Dir.pwd, "state", "terraform", "%{config}", "%{component}" + @@ext)
51
51
 
52
- logger.fatal("Local backend path must be a String!") unless path.kind_of?(String)
52
+ logger.fatal("Local backend path must be a string!") unless path.kind_of?(String)
53
53
  logger.fatal("Local backend path must not be blank!") if path.strip.empty?
54
54
 
55
55
  logger.fatal("Local backend path must include %{service} or the path to this repository.") unless (path.include?("%{service}") or path.include?(Dir.pwd))
@@ -28,12 +28,12 @@ module TerraformWrapper
28
28
  ###############################################################################
29
29
 
30
30
  def initialize(options:)
31
- logger.fatal("Binary base path must be a String!") unless options["base"].kind_of?(String)
31
+ logger.fatal("Binary base path must be a string!") unless options["base"].kind_of?(String)
32
32
  logger.fatal("Binary base path must not be blank!") if options["base"].strip.empty?
33
33
 
34
34
  @base = options["base"]
35
35
 
36
- logger.fatal("Binary version must be a String!") unless options["version"].kind_of?(String)
36
+ logger.fatal("Binary version must be a string!") unless options["version"].kind_of?(String)
37
37
  logger.fatal("Binary version must not be blank!") if options["version"].strip.empty?
38
38
 
39
39
  @version = options["version"]
@@ -23,12 +23,12 @@ module TerraformWrapper
23
23
  ###############################################################################
24
24
 
25
25
  def initialize(options:)
26
- logger.fatal("Code base path must be a String!") unless options["base"].kind_of?(String)
26
+ logger.fatal("Code base path must be a string!") unless options["base"].kind_of?(String)
27
27
  logger.fatal("Code base path must not be blank!") if options["base"].strip.empty?
28
28
 
29
29
  @base = options["base"]
30
30
 
31
- logger.fatal("Code component name must be a String!") unless options["name"].kind_of?(String)
31
+ logger.fatal("Code component name must be a string!") unless options["name"].kind_of?(String)
32
32
  logger.fatal("Code component name must not be blank!") if options["name"].strip.empty?
33
33
 
34
34
  @name = options["name"]
@@ -24,8 +24,8 @@ module TerraformWrapper
24
24
 
25
25
  ###############################################################################
26
26
 
27
- @@variable_files_name = "tfvars"
28
- @@variable_files_ext = ".tfvars"
27
+ @@variable_files_name = "tfvars"
28
+ @@variable_files_exts = [ ".tfvars" ]
29
29
 
30
30
  ###############################################################################
31
31
 
@@ -42,17 +42,17 @@ module TerraformWrapper
42
42
  ###############################################################################
43
43
 
44
44
  def initialize(code:, options:)
45
- logger.fatal("Configuration base path must be a String!") unless options["base"].kind_of?(String)
45
+ logger.fatal("Configuration base path must be a string!") unless options["base"].kind_of?(String)
46
46
  logger.fatal("Configuration base path must not be blank!") if options["base"].strip.empty?
47
47
 
48
48
  @base = options["base"]
49
49
 
50
- logger.fatal("Configuration service name must be a String!") unless options["service"].kind_of?(String)
50
+ logger.fatal("Configuration service name must be a string!") unless options["service"].kind_of?(String)
51
51
  logger.fatal("Configuration service name must not be blank!") if options["service"].strip.empty?
52
52
 
53
53
  @service = options["service"]
54
54
 
55
- logger.fatal("Configuration name must be a String!") unless options["name"].kind_of?(String)
55
+ logger.fatal("Configuration name must be a string!") unless options["name"].kind_of?(String)
56
56
  logger.fatal("Configuration name must not be blank!") if options["name"].strip.empty?
57
57
 
58
58
  @name = options["name"]
@@ -65,7 +65,7 @@ module TerraformWrapper
65
65
 
66
66
  auth_azure_options = options["auth-azure-options"]
67
67
 
68
- logger.fatal("Configuration backend name must be a String!") unless options["backend"].kind_of?(String)
68
+ logger.fatal("Configuration backend name must be a string!") unless options["backend"].kind_of?(String)
69
69
  logger.fatal("Configuration backend name must not be blank!") if options["backend"].strip.empty?
70
70
 
71
71
  backend = options["backend"]
@@ -75,10 +75,9 @@ module TerraformWrapper
75
75
  backend_options = options["backend-options"]
76
76
 
77
77
  @code = code
78
- @path = find
78
+ @path = find(base: @base, name: @name, exts: @@config_exts, description: "Configuration")
79
79
 
80
80
  yaml = YAML.load(File.read(@path))
81
-
82
81
  logger.fatal("Invalid YAML in configuration file: #{@path}") unless yaml.kind_of?(Hash)
83
82
 
84
83
  if yaml.key?("variables") then
@@ -110,13 +109,13 @@ module TerraformWrapper
110
109
 
111
110
  ###############################################################################
112
111
 
113
- def find
112
+ def find(base:, name:, exts:, description: "File")
114
113
  @@config_exts.each do |config_ext|
115
- path = File.join(@base, @name + config_ext)
114
+ path = File.join(base, name + config_ext)
116
115
  return path if File.file?(path)
117
116
  end
118
117
 
119
- logger.fatal("Terraform configuration name: #{@name} not found in location: #{@base}!")
118
+ logger.fatal("#{description} name: #{@name} not found in location: #{@base}!")
120
119
  end
121
120
 
122
121
  ###############################################################################
@@ -127,14 +126,9 @@ module TerraformWrapper
127
126
  result = Array.new
128
127
 
129
128
  variable_files.each do |variable_file|
130
- logger.fatal("All elements of 'variable_files' must be strings!") unless variable_file.kind_of?(String)
131
- logger.fatal("All elements of 'variable_files' must not be blank!") if variable_file.strip.empty?
132
- path = File.join(@base, @@variable_files_name, variable_file.strip + @@variable_files_ext)
133
- if File.file?(path) then
134
- result.append(path)
135
- else
136
- logger.fatal("Terraform variables file: #{variable_file}, path: #{path} does not exist!")
137
- end
129
+ logger.fatal("All elements of 'terraform' must be strings!") unless variable_file.kind_of?(String)
130
+ logger.fatal("All elements of 'terraform' must not be blank!") if variable_file.strip.empty?
131
+ result.append(find(base: File.join(@base, @@variable_files_name), name: variable_file.strip, exts: @@variable_files_exts, description: "Terraform values file"))
138
132
  end
139
133
 
140
134
  return result
@@ -29,7 +29,6 @@ module TerraformWrapper
29
29
  @code = code
30
30
 
31
31
  @initialised = false
32
- @ready = false
33
32
  end
34
33
 
35
34
  ###############################################################################
@@ -48,11 +47,11 @@ module TerraformWrapper
48
47
  def import(address: nil, id: nil)
49
48
  logger.fatal("Cannot Terraform import before initialising backend!") unless initialised
50
49
 
51
- logger.fatal("Terraform state address for import must be a String!") unless address.kind_of?(String)
52
- logger.fatal("Terraform state address for import must be a String!") unless address.kind_of?(String)
50
+ logger.fatal("Terraform state address for import must be a string!") unless address.kind_of?(String)
51
+ logger.fatal("Terraform state address for import must be a string!") unless address.kind_of?(String)
53
52
  logger.fatal("Terraform state address for import must not be blank!") if address.strip.empty?
54
53
 
55
- logger.fatal("Identification for infrastructure to import must be a String!") unless id.kind_of?(String)
54
+ logger.fatal("Identification for infrastructure to import must be a string!") unless id.kind_of?(String)
56
55
  logger.fatal("Identification for infrastructure to import must not be blank!") if id.strip.empty?
57
56
 
58
57
  parameters = Array.new
@@ -4,7 +4,7 @@ module TerraformWrapper
4
4
 
5
5
  ###############################################################################
6
6
 
7
- VERSION = "0.2.0"
7
+ VERSION = "0.2.1"
8
8
 
9
9
  ###############################################################################
10
10
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: terraform-wrapper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Richard Lees
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-02-19 00:00:00.000000000 Z
11
+ date: 2021-03-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake