terraform-wrapper 1.0.0 → 1.2.0

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: cec70134c0df1674effb0b5e07ffaa3ff7d1a2ca034dd6452563f616e67e09c1
4
- data.tar.gz: b4c6416feea1f68b3db4f593f7e2692a7553869977dad45aa0da045477841add
3
+ metadata.gz: bafe8ef5b2dd58357fd8ac1eb741deb4ace78e02d374f1711c727e5835731715
4
+ data.tar.gz: 9899116a854e2ab82a4cfc6736f94321735593a7f03c6197715324415c8e5f30
5
5
  SHA512:
6
- metadata.gz: 0cb74ef36d96167259fec72539932d7614a25ad2f442fd75940bdaff3fe63b17aa7a793f17f90368c930112d7ab433950bf0c900ed46694d4dfd8e1cba3d311b
7
- data.tar.gz: '090b646a9d688e4e12149752cffa4f71414a47c70b4ec619a7a142e342e9ece421e929baf42045b767c896666406317f0aff602b12d35d123b767bf87793b303'
6
+ metadata.gz: 48a9f108a1b0dc5d111486d3f093b08c8e0a5d40f9a3d70211f537a1623dcb86019c39144177e774ee22e224fd23030e473bf3a5dd3b501131c3e6691312d83b
7
+ data.tar.gz: d0dd56c21bd7b6345913b3117aa1921118d9b60fc31cb8bcef72dc6556868e7aeff9497104bda31331ad3b30e7be02cf1c71814a3549b09a9bbdeedbbdfa2a8e
@@ -22,7 +22,7 @@ module TerraformWrapper
22
22
 
23
23
  ###############################################################################
24
24
 
25
- def self.define_tasks(component:, options: Hash.new, service:)
25
+ def self.deployment_tasks(component:, options: Hash.new, service:)
26
26
  @logger.info("Building tasks for service: #{service}, component: #{component}...")
27
27
 
28
28
  @logger.fatal("Options must be specified as a hash!") unless options.kind_of?(Hash)
@@ -28,7 +28,7 @@ module TerraformWrapper
28
28
  return path if File.file?(path)
29
29
  end
30
30
 
31
- logger.fatal("#{description} name: #{name} not found in location: #{base}!")
31
+ @logger.fatal("#{description} name: #{name} not found in location: #{base}!")
32
32
  end
33
33
 
34
34
  ###############################################################################
@@ -25,13 +25,13 @@ module TerraformWrapper
25
25
 
26
26
  ###############################################################################
27
27
 
28
- @password = nil
28
+ @keyvault = nil
29
+ @secret_username = nil
30
+ @secret_password = nil
29
31
 
30
32
  ###############################################################################
31
33
 
32
- attr_reader :subscription
33
- attr_reader :tenant
34
- attr_reader :username
34
+ @subscription
35
35
 
36
36
  ###############################################################################
37
37
 
@@ -42,10 +42,17 @@ module TerraformWrapper
42
42
  ###############################################################################
43
43
 
44
44
  def auth()
45
- ENV["ARM_SUBSCRIPTION_ID"] = @subscription
46
- ENV["ARM_TENANT_ID"] = @tenant
47
- ENV["ARM_CLIENT_ID"] = @username unless @username.nil?
48
- ENV["ARM_CLIENT_SECRET"] = @password unless @password.nil?
45
+ details = subscription_details(subscription: @subscription)
46
+
47
+ subscription = details["id"]
48
+ tenant = details["tenant"]
49
+ username = @keyvault.nil? ? nil : secret(vault: @keyvault, name: @secret_username)
50
+ password = @keyvault.nil? ? nil : secret(vault: @keyvault, name: @secret_password)
51
+
52
+ ENV["ARM_SUBSCRIPTION_ID"] = subscription
53
+ ENV["ARM_TENANT_ID"] = tenant
54
+ ENV["ARM_CLIENT_ID"] = username unless username.nil?
55
+ ENV["ARM_CLIENT_SECRET"] = password unless password.nil?
49
56
  logger.success("Azure authenticator environment variables set!")
50
57
  end
51
58
 
@@ -151,20 +158,13 @@ module TerraformWrapper
151
158
  end
152
159
 
153
160
  begin
154
- subscription = subscription % @variables.identifiers
155
- keyvault = keyvault % @variables.identifiers unless keyvault.nil?
156
- username = username % @variables.identifiers unless keyvault.nil?
157
- password = password % @variables.identifiers unless keyvault.nil?
161
+ @subscription = subscription % @variables.identifiers
162
+ @keyvault = keyvault % @variables.identifiers unless keyvault.nil?
163
+ @secret_username = username % @variables.identifiers unless keyvault.nil?
164
+ @secret_password = password % @variables.identifiers unless keyvault.nil?
158
165
  rescue
159
166
  logger.fatal("Azure authenticator options contain identifiers that are not included in the configuration file!")
160
167
  end
161
-
162
- details = subscription_details(subscription: subscription)
163
-
164
- @subscription = details["id"]
165
- @tenant = details["tenant"]
166
- @username = keyvault.nil? ? nil : secret(vault: keyvault, name: username)
167
- @password = keyvault.nil? ? nil : secret(vault: keyvault, name: password)
168
168
  end
169
169
 
170
170
  ###############################################################################
@@ -34,8 +34,6 @@ module TerraformWrapper
34
34
  @name = options["name"]
35
35
 
36
36
  @path = File.join(@base, @name)
37
-
38
- logger.fatal("Terraform code location: #{@path} does not exist!") unless exists
39
37
  end
40
38
 
41
39
  ###############################################################################
@@ -41,16 +41,16 @@ module TerraformWrapper
41
41
 
42
42
  @base = options["base"]
43
43
 
44
- logger.fatal("Configuration service name must be a string!") unless options["service"].kind_of?(String)
45
- logger.fatal("Configuration service name must not be blank!") if options["service"].strip.empty?
46
-
47
- @service = options["service"]
48
-
49
44
  logger.fatal("Configuration name must be a string!") unless options["name"].kind_of?(String)
50
45
  logger.fatal("Configuration name must not be blank!") if options["name"].strip.empty?
51
46
 
52
47
  @name = options["name"]
53
48
 
49
+ logger.fatal("Configuration service name must be a string!") unless options["service"].kind_of?(String)
50
+ logger.fatal("Configuration service name must not be blank!") if options["service"].strip.empty?
51
+
52
+ @service = options["service"]
53
+
54
54
  logger.fatal("Configuration authenticator for Azure enabled must be a Boolean!") unless [ true, false ].include?(options["auth-azure"])
55
55
 
56
56
  auth_azure = options["auth-azure"]
@@ -75,15 +75,28 @@ module TerraformWrapper
75
75
  logger.fatal("Invalid YAML in configuration file: #{@path}") unless yaml.kind_of?(Hash)
76
76
 
77
77
  identifiers = yaml.key?("identifiers") ? yaml["identifiers"] : Hash.new
78
- @variables = TerraformWrapper::Shared::Variables.new(config: @name, component: @code.name, service: @service, identifiers: identifiers)
79
- @variables.add_variables(variables: yaml["globals"]) if yaml.key?("globals")
78
+ @variables = TerraformWrapper::Shared::Variables.new(config: @name, component: @code.name, service: @service, identifiers: identifiers)
79
+
80
+ if yaml.key?("globals") then
81
+ logger.fatal("Key 'globals' is not a hash in configuration file: #{@path}") unless yaml["globals"].kind_of?(Hash)
82
+ globals = yaml["globals"]
83
+
84
+ @variables.add_variables(variables: globals["variables"]) if globals.key?("variables")
85
+ end
80
86
 
81
87
  if yaml.key?("terraform") then
82
88
  logger.fatal("Key 'terraform' is not a hash in configuration file: #{@path}") unless yaml["terraform"].kind_of?(Hash)
83
89
  terraform = yaml["terraform"]
84
90
 
85
- @variables.add_variables(variables: terraform["variables"]) if terraform.key?("variables")
86
- @variables.add_files(base: @base, files: terraform["files"]) if terraform.key?("files")
91
+ [ "globals", @code.name ].each do |extra|
92
+ if terraform.key?(extra) then
93
+ logger.fatal("Key '#{extra}' under 'terraform' is not a hash in configuration file: #{@path}") unless terraform[extra].kind_of?(Hash)
94
+ section = terraform[extra]
95
+
96
+ @variables.add_variables(variables: section["variables"]) if section.key?("variables")
97
+ @variables.add_files(base: @base, files: section["files"]) if section.key?("files")
98
+ end
99
+ end
87
100
  end
88
101
 
89
102
  @auths = Array.new
@@ -25,6 +25,8 @@ module TerraformWrapper
25
25
  ###############################################################################
26
26
 
27
27
  def initialize(binary:, code:)
28
+ logger.fatal("Terraform code location: #{code.path} does not exist!") unless code.check
29
+
28
30
  @binary = binary
29
31
  @code = code
30
32
 
@@ -36,11 +36,11 @@ module TerraformWrapper
36
36
  @core[:config] = config
37
37
  @core[:service] = service
38
38
 
39
- user = cleanse(variables: identifiers, reserved: @core.keys)
39
+ user = cleanse(variables: identifiers, reserved: @core.keys, downcase: true)
40
40
  merged = @core.merge(user)
41
41
 
42
42
  @identifiers = sort ? merged.sort.to_h : merged
43
- @values = @identifiers
43
+ @values = Hash.new
44
44
  @files = Array.new
45
45
  end
46
46
 
@@ -89,7 +89,7 @@ module TerraformWrapper
89
89
  ###############################################################################
90
90
 
91
91
  def clear_variables()
92
- @values = @identifers
92
+ @values = Hash.new
93
93
  end
94
94
 
95
95
  ###############################################################################
@@ -98,17 +98,20 @@ module TerraformWrapper
98
98
 
99
99
  ###############################################################################
100
100
 
101
- def cleanse(variables:, reserved:)
101
+ def cleanse(variables:, reserved:, downcase: false)
102
102
  result = Hash.new
103
103
 
104
104
  variables.keys.each do |key|
105
105
  logger.fatal("Could not clean variables hash. All keys MUST be strings!") unless key.kind_of?(String)
106
- logger.fatal("Could not clean variables hash, key: #{key.downcase} is reserved or already in use and cannot be used!") if reserved.include?(key.downcase.to_sym)
107
- logger.fatal("Could not clean variables hash, duplicate key found: #{key.downcase}!") if result.key?(key.downcase.to_sym)
108
- logger.fatal("Could not clean variables hash, value for: #{key.downcase} is not a string!") unless variables[key].kind_of?(String)
109
- logger.fatal("Could not clean variables hash, value for: #{key.downcase} is empty!") if variables[key].strip.empty?
110
106
 
111
- result[key.downcase.to_sym] = variables[key].strip
107
+ sym = downcase ? key.downcase.to_sym : key.to_sym
108
+
109
+ logger.fatal("Could not clean variables hash, key: #{sym.to_s} is reserved or already in use and cannot be used!") if reserved.include?(sym)
110
+ logger.fatal("Could not clean variables hash, duplicate key found: #{sym.to_s}!") if result.key?(sym)
111
+ logger.fatal("Could not clean variables hash, value for: #{sym.to_s} is not a string!") unless variables[key].kind_of?(String)
112
+ logger.fatal("Could not clean variables hash, value for: #{sym.to_s} is empty!") if variables[key].strip.empty?
113
+
114
+ result[sym] = variables[key].strip
112
115
  end
113
116
 
114
117
  return result
@@ -34,7 +34,7 @@ module TerraformWrapper
34
34
 
35
35
  def upgrade_task
36
36
  desc "Upgrades the Terraform infrastructure component modules, providers and lock file."
37
- task :upgrade => :binary do |t, args|
37
+ task :upgrade => [:binary, :clean] do |t, args|
38
38
  runner = TerraformWrapper::Shared::Runner.new(binary: @binary, code: @code)
39
39
 
40
40
  logger.info("Upgrading Terraform component: #{@code.name}...")
@@ -4,7 +4,7 @@ module TerraformWrapper
4
4
 
5
5
  ###############################################################################
6
6
 
7
- VERSION = "1.0.0"
7
+ VERSION = "1.2.0"
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: 1.0.0
4
+ version: 1.2.0
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-03-08 00:00:00.000000000 Z
11
+ date: 2021-03-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake