kite 0.2.0 → 1.0.0

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.
Files changed (116) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +130 -66
  3. data/LICENSE.md +202 -0
  4. data/README.md +35 -11
  5. data/bin/concourse/out +16 -20
  6. data/docs/kite-concourse-resource.md +45 -0
  7. data/kite.gemspec +1 -0
  8. data/lib/kite.rb +3 -1
  9. data/lib/kite/cloud.rb +1 -0
  10. data/lib/kite/core.rb +8 -2
  11. data/lib/kite/generate.rb +12 -46
  12. data/lib/kite/helpers.rb +0 -72
  13. data/lib/kite/helpers/concourse.rb +3 -2
  14. data/lib/kite/module.rb +76 -0
  15. data/lib/kite/terraform.rb +45 -0
  16. data/lib/kite/version.rb +1 -1
  17. data/tpl/aws/environment/main.tf.tt +5 -0
  18. data/tpl/aws/environment/s3.tf.tt +13 -0
  19. data/tpl/gcp/environment/gcs.tf.tt +18 -0
  20. data/tpl/gcp/environment/main.tf.tt +5 -0
  21. data/tpl/gcp/environment/outputs.tf.tt +5 -0
  22. data/tpl/service/%output_path%/pipelines/review.yml.tt +55 -37
  23. data/tpl/service/%output_path%/pipelines/tasks/create-pull-requests-tag.yml.tt +1 -1
  24. data/tpl/service/%output_path%/pipelines/tasks/create-repository-tag.yml.tt +1 -1
  25. data/tpl/service/%output_path%/pipelines/tasks/run-unit.yml.tt +7 -0
  26. data/tpl/service/Makefile.tt +11 -7
  27. data/tpl/service/docs/getting-started.md +73 -0
  28. data/tpl/service/docs/service.md +101 -0
  29. data/tpl/skel/Gemfile.tt +0 -9
  30. data/tpl/skel/config/cloud.yml +11 -66
  31. metadata +29 -88
  32. data/lib/kite/render.rb +0 -116
  33. data/tpl/aws/README.md +0 -52
  34. data/tpl/aws/bin/base/bootstrap.sh +0 -35
  35. data/tpl/aws/bin/base/cleanup.sh.tt +0 -19
  36. data/tpl/aws/bin/base/set-env.sh.tt +0 -7
  37. data/tpl/aws/bin/base/setup-tunnel.sh.tt +0 -4
  38. data/tpl/aws/bin/bosh-install.sh.tt +0 -23
  39. data/tpl/aws/bin/concourse-deploy.sh.tt +0 -14
  40. data/tpl/aws/bin/ingress-deploy.sh.tt +0 -7
  41. data/tpl/aws/bin/ingress-update.sh.tt +0 -7
  42. data/tpl/aws/bin/kops-delete.sh.erb +0 -5
  43. data/tpl/aws/bin/kops-deploy.sh.erb +0 -11
  44. data/tpl/aws/bin/oauth-deploy.sh.tt +0 -17
  45. data/tpl/aws/bin/prometheus-deploy.sh.tt +0 -23
  46. data/tpl/aws/bin/vault-deploy.sh.tt +0 -10
  47. data/tpl/aws/bosh-vars.yml.erb +0 -12
  48. data/tpl/aws/config/oauth.yml +0 -59
  49. data/tpl/aws/deployments/bosh/bosh.yml +0 -144
  50. data/tpl/aws/deployments/bosh/cloud-config.yml.tt +0 -86
  51. data/tpl/aws/deployments/bosh/cpi.yml +0 -98
  52. data/tpl/aws/deployments/bosh/jumpbox-user.yml +0 -27
  53. data/tpl/aws/deployments/concourse/concourse.yml.tt +0 -98
  54. data/tpl/aws/deployments/ingress/ingress.yml.erb +0 -78
  55. data/tpl/aws/deployments/oauth/oauth.yml.tt +0 -95
  56. data/tpl/aws/deployments/prometheus/monitor-bosh.yml +0 -518
  57. data/tpl/aws/deployments/prometheus/monitor-kubernetes.yml +0 -30
  58. data/tpl/aws/deployments/prometheus/prometheus.yml.tt +0 -184
  59. data/tpl/aws/deployments/vault/vault.yml.erb +0 -38
  60. data/tpl/aws/docs/bosh.md +0 -31
  61. data/tpl/aws/docs/concourse.md +0 -41
  62. data/tpl/aws/docs/ingress.md +0 -14
  63. data/tpl/aws/docs/kops.md +0 -35
  64. data/tpl/aws/docs/oauth.md +0 -24
  65. data/tpl/aws/docs/prometheus.md +0 -31
  66. data/tpl/aws/docs/vault.md +0 -35
  67. data/tpl/aws/terraform/kite_bucket.tf +0 -8
  68. data/tpl/aws/terraform/main.tf.tt +0 -36
  69. data/tpl/aws/terraform/network.tf.tt +0 -252
  70. data/tpl/aws/terraform/outputs.tf +0 -19
  71. data/tpl/aws/terraform/terraform.tfvars.tt +0 -21
  72. data/tpl/aws/terraform/variables.tf +0 -73
  73. data/tpl/gcp/README.md +0 -54
  74. data/tpl/gcp/bin/base/bootstrap.sh +0 -35
  75. data/tpl/gcp/bin/base/cleanup.sh.tt +0 -20
  76. data/tpl/gcp/bin/base/set-env.sh.tt +0 -10
  77. data/tpl/gcp/bin/base/setup-tunnel.sh.tt +0 -13
  78. data/tpl/gcp/bin/bosh-install.sh.tt +0 -22
  79. data/tpl/gcp/bin/concourse-deploy.sh.tt +0 -14
  80. data/tpl/gcp/bin/ingress-deploy.sh.tt +0 -7
  81. data/tpl/gcp/bin/ingress-update.sh.tt +0 -7
  82. data/tpl/gcp/bin/oauth-deploy.sh.tt +0 -19
  83. data/tpl/gcp/bin/prometheus-deploy.sh.tt +0 -23
  84. data/tpl/gcp/bin/vault-deploy.sh.tt +0 -10
  85. data/tpl/gcp/bosh-vars.yml.erb +0 -9
  86. data/tpl/gcp/config/oauth.yml +0 -59
  87. data/tpl/gcp/deployments/bosh/bosh.yml +0 -144
  88. data/tpl/gcp/deployments/bosh/cloud-config.yml.tt +0 -73
  89. data/tpl/gcp/deployments/bosh/cpi.yml +0 -69
  90. data/tpl/gcp/deployments/bosh/jumpbox-user.yml +0 -27
  91. data/tpl/gcp/deployments/concourse/concourse.yml.tt +0 -104
  92. data/tpl/gcp/deployments/concourse/test/test-credentials.yml +0 -3
  93. data/tpl/gcp/deployments/concourse/test/test-pipeline.yml +0 -24
  94. data/tpl/gcp/deployments/ingress/ingress.yml.erb +0 -111
  95. data/tpl/gcp/deployments/oauth/oauth.yml.tt +0 -95
  96. data/tpl/gcp/deployments/prometheus/monitor-bosh.yml +0 -518
  97. data/tpl/gcp/deployments/prometheus/monitor-kubernetes.yml +0 -30
  98. data/tpl/gcp/deployments/prometheus/prometheus.yml +0 -183
  99. data/tpl/gcp/deployments/vault/vault.yml.erb +0 -37
  100. data/tpl/gcp/docs/bosh.md +0 -36
  101. data/tpl/gcp/docs/concourse.md +0 -41
  102. data/tpl/gcp/docs/ingress.md +0 -12
  103. data/tpl/gcp/docs/oauth.md +0 -24
  104. data/tpl/gcp/docs/prometheus.md +0 -27
  105. data/tpl/gcp/docs/vault.md +0 -36
  106. data/tpl/gcp/terraform/gcs.tf.tt +0 -18
  107. data/tpl/gcp/terraform/main.tf +0 -70
  108. data/tpl/gcp/terraform/network.tf +0 -52
  109. data/tpl/gcp/terraform/outputs.tf +0 -7
  110. data/tpl/gcp/terraform/terraform.tfvars.tt +0 -15
  111. data/tpl/gcp/terraform/variables.tf +0 -37
  112. data/tpl/service/%output_path%/pipelines/tasks/helm-deploy.yml.tt +0 -22
  113. data/tpl/service/%output_path%/pipelines/tasks/run-master-tests.yml.tt +0 -12
  114. data/tpl/service/%output_path%/pipelines/tasks/run-pr-tests.yml.tt +0 -12
  115. data/tpl/skel/docs/index.md.tt +0 -0
  116. data/tpl/skel/docs/quickstart.md.tt +0 -0
data/bin/concourse/out CHANGED
@@ -7,33 +7,29 @@ params = Kite::Helpers::Concourse.params(STDIN.read)
7
7
 
8
8
  Kite::Helpers::Concourse.fatal '`source` missing' unless params['source']
9
9
 
10
- key = params['source']['json_key']
11
- kubeconfig = params['source']['kubeconfig']
10
+ token = params['source']['token'] # kubectl service account token
11
+ endpoint = params['source']['endpoint']
12
+ cert = params['source']['certificate-authority']
12
13
  command = params['params']['command']
13
14
 
14
- Kite::Helpers::Concourse.fatal '`kubeconfig` missing' if kubeconfig.to_s.empty?
15
15
  Kite::Helpers::Concourse.fatal '`command` missing' if command.to_s.empty?
16
16
 
17
+ path_certificate = '/tmp/ca.crt'
17
18
  path_key = '/tmp/key.json'
18
19
  path_kubeconfig = '/tmp/kubeconfig'
20
+ cleaner = [/(token)=[^ ]*/, '\1=REDACTED']
19
21
 
20
- File.write(path_key, key) if key
21
- File.write(path_kubeconfig, kubeconfig)
22
-
23
- env = {
24
- 'KUBECONFIG' => path_kubeconfig,
25
- }
26
-
27
- if key
28
- env['GOOGLE_CREDENTIALS'] = path_key
29
- unless Kite::Helpers::Concourse.execute("gcloud auth activate-service-account --key-file=#{ path_key }", env)
30
- ::Kite::Helpers::Concourse.respond(
31
- version: { status: 'error' },
32
- metadata: ["Failed to execute command #{ command }"]
33
- )
34
- exit 1
35
- end
36
- end
22
+ env = {}
23
+
24
+ File.write(path_certificate, cert)
25
+ env['KUBECONFIG'] = path_kubeconfig
26
+
27
+ Kite::Helpers::Concourse.execute("kubectl config set-cluster concourse " \
28
+ "--embed-certs=true --server=#{ endpoint } " \
29
+ "--certificate-authority=#{ path_certificate }", env)
30
+ Kite::Helpers::Concourse.execute("kubectl config set-credentials concourse --token='#{ token }'", env, cleaner)
31
+ Kite::Helpers::Concourse.execute("kubectl config set-context concourse --cluster=concourse --user=concourse", env)
32
+ Kite::Helpers::Concourse.execute("kubectl config use-context concourse", env)
37
33
 
38
34
  if Kite::Helpers::Concourse.execute(command, env)
39
35
  ::Kite::Helpers::Concourse.respond(version: { status: 'ok' })
@@ -0,0 +1,45 @@
1
+ # Kite concourse resource
2
+
3
+ When you define kite resource you should defind `kubeconfig` or kite can generate it from defined `token`, `endpoint`, `user`, `cluster`, `certificate-authority` parameters.
4
+
5
+ Here is description of parameters:
6
+ - __token__ - service account token for your cluster
7
+ - __endpoint__ - cluster server adress
8
+ - __certificate-autority__ - service account certificate for cluster
9
+
10
+ ### Where to get this parameters ?
11
+
12
+ Get secret's name
13
+ ```shell
14
+ kubectl get serviceAccount <service_account_name> -oyaml
15
+ echo -n SECRET | base64 -d
16
+ ```
17
+
18
+ Then look on secret's yaml. Here you can find certificate-authority and token values:
19
+ ```shell
20
+ kubectl get secrets <secrets_name> -oyaml
21
+ echo -n SECRET | base64 -d
22
+ ```
23
+
24
+ Find server address:
25
+ ```shell
26
+ kubectl config view
27
+ ```
28
+
29
+ *Example*
30
+
31
+ ```yaml
32
+ resource_types:
33
+ - name: kite
34
+ type: docker-image
35
+ source:
36
+ repository: heliostech/kite
37
+
38
+ resources:
39
+ - name: kite-test
40
+ type: kite
41
+ source:
42
+ token: {{sa_token}}
43
+ endpoint: {{server_ip}}
44
+ certificate-autority: {{certificate-autority}}
45
+ ```
data/kite.gemspec CHANGED
@@ -25,6 +25,7 @@ Gem::Specification.new do |spec|
25
25
  spec.add_development_dependency "bundler", "~> 1.14"
26
26
  spec.add_development_dependency "rake", "~> 10.0"
27
27
  spec.add_development_dependency "rspec", "~> 3.0"
28
+ spec.add_development_dependency "git"
28
29
  spec.add_development_dependency "simplecov"
29
30
  spec.add_development_dependency "codecov"
30
31
  end
data/lib/kite.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require 'erb'
2
2
  require 'yaml'
3
3
  require 'ipaddr'
4
+ require 'git'
4
5
  require 'thor'
5
6
 
6
7
  require 'kite/version'
@@ -8,7 +9,8 @@ require 'kite/helpers'
8
9
  require 'kite/error'
9
10
 
10
11
  require 'kite/base'
11
- require 'kite/render'
12
12
  require 'kite/generate'
13
+ require 'kite/module'
14
+ require 'kite/terraform'
13
15
  require 'kite/core'
14
16
  require 'kite/cloud'
data/lib/kite/cloud.rb CHANGED
@@ -20,6 +20,7 @@ class Kite::Cloud
20
20
  core.inside(name) do
21
21
  core.chmod('bin/kite', 0755)
22
22
  end
23
+ Git.init(name)
23
24
  end
24
25
 
25
26
  end
data/lib/kite/core.rb CHANGED
@@ -13,8 +13,14 @@ module Kite
13
13
  desc "generate", "Generate IaC from configuration"
14
14
  subcommand "generate", Kite::Generate
15
15
 
16
- desc 'render MANIFEST', 'Render manifest file from configuration and Terraform output'
17
- subcommand "render", Kite::Render
16
+ desc 'module', 'Use kite modules with environments'
17
+ subcommand "module", Kite::Module
18
+
19
+ desc 'terraform', 'Run Terraform-related commands with environment variables loaded from module vars'
20
+ method_option :env, type: :string, desc: "Environment", required: true, default: ENV['KITE_ENV']
21
+ def terraform(command, *args)
22
+ Kite::Terraform.new(self, options).run(command, *args)
23
+ end
18
24
 
19
25
  desc "version", "Return kite version"
20
26
  # Return kite version
data/lib/kite/generate.rb CHANGED
@@ -1,46 +1,8 @@
1
1
  module Kite
2
- # Subcommand for rendering manifests, deployments etc.
2
+ # Subcommand for generating environments, services etc.
3
3
  class Generate < Base
4
4
  include Kite::Helpers
5
5
 
6
- method_option :provider, type: :string, desc: "Cloud provider", enum: %w{aws gcp}, required: true
7
- desc "cloud", "Generate cloud IaC from configuration"
8
- # Generates Infrastructure as Code and setup scripts for the given cloud using values from <b>config/cloud.yml</b>
9
- def cloud()
10
- say "Generating cloud #{ options[:provider] } IaC", :green
11
- @values = parse_cloud_config
12
-
13
- case options[:provider]
14
- when 'aws'
15
- directory('aws/terraform', 'terraform')
16
- copy_file('aws/README.md', 'README.md', force: true)
17
- copy_file('aws/docs/kops.md', 'docs/kops.md')
18
-
19
- directory('aws/bin/base', 'bin')
20
- template('aws/bin/kops-deploy.sh.erb', 'bin/kops-deploy.sh')
21
- template('aws/bin/kops-delete.sh.erb', 'bin/kops-delete.sh')
22
- chmod('bin/bootstrap.sh', 0755)
23
- chmod('bin/cleanup.sh', 0755)
24
- chmod('bin/setup-tunnel.sh', 0755)
25
- chmod('bin/kops-deploy.sh', 0755)
26
- chmod('bin/kops-delete.sh', 0755)
27
-
28
- when 'gcp'
29
- directory('gcp/terraform', 'terraform')
30
- copy_file('gcp/README.md', 'README.md', force: true)
31
-
32
-
33
- directory('gcp/bin/base', 'bin')
34
- chmod('bin/bootstrap.sh', 0755)
35
- chmod('bin/cleanup.sh', 0755)
36
- chmod('bin/setup-tunnel.sh', 0755)
37
-
38
- else
39
- say 'Cloud provider not specified'
40
-
41
- end
42
- end
43
-
44
6
  method_option :name, type: :string, desc: "Task name", required: true
45
7
  desc "task", "Generate task IaC from configuration"
46
8
  def task()
@@ -71,15 +33,19 @@ module Kite
71
33
  directory('service', path)
72
34
  end
73
35
 
74
- no_commands do
75
- def output_path
76
- @output ||= "config"
77
- end
36
+ method_option :provider, type: :string, desc: "Cloud provider", enum: %w{aws gcp}, required: true
37
+ desc 'environment NAME', 'Generate an environment with base terraform files'
38
+ def environment(name)
39
+ say "Generating environment for #{options[:provider]}"
78
40
 
79
- def app_name
80
- @name ||= "app-name"
41
+ unless parse_cloud_config.key? name
42
+ append_to_file 'config/cloud.yml', "\n#{name}:\n <<: *default\n"
81
43
  end
82
- end
83
44
 
45
+ @cloud = parse_cloud_config[name]
46
+ @env_name = name
47
+
48
+ directory("#{options[:provider]}/environment", "config/environments/#{name}")
49
+ end
84
50
  end
85
51
  end
data/lib/kite/helpers.rb CHANGED
@@ -4,22 +4,6 @@ module Kite::Helpers
4
4
  raise Kite::Error, 'The config/cloud.yml is not filled out!' unless config.find { |key, hash| hash.find { |k, v| v.nil? } }.nil?
5
5
  end
6
6
 
7
- # Check if Terraform IaC was applied
8
- def check_terraform_applied
9
- raise Kite::Error, 'Did you terraform apply? terraform.tfstate is missing!' unless File.file? "terraform/terraform.tfstate"
10
- end
11
-
12
- # Parse Terraform .tfstate file, returning the output hash
13
- def parse_tf_state(path)
14
- check_terraform_applied
15
-
16
- tf_state = YAML.load(File.read(path))
17
- tf_output = tf_state["modules"].first["outputs"]
18
- tf_output.map { |k, v| tf_output[k] = v["value"] }
19
-
20
- tf_output
21
- end
22
-
23
7
  # Parse config/cloud.yml, returning the output hash
24
8
  def parse_cloud_config
25
9
  cloud_config = YAML.load(File.read('config/cloud.yml'))
@@ -27,60 +11,4 @@ module Kite::Helpers
27
11
 
28
12
  cloud_config
29
13
  end
30
-
31
- # Return public subnet id depending on
32
- # whether it's declared in config/cloud.yml or not
33
- def conditional_subnet_id(values)
34
- subnet_id = values['aws']['public_subnet']['id']
35
-
36
- if subnet_id.empty?
37
- '${aws_subnet.platform_dmz.id}'
38
- else
39
- subnet_id
40
- end
41
- end
42
-
43
- # Return vpc id depending on
44
- # whether it's declared in config/cloud.yml or not
45
- def conditional_vpc_id(values)
46
- vpc_id = values['aws']['vpc_id']
47
-
48
- if vpc_id.empty?
49
- '${aws_vpc.platform.id}'
50
- else
51
- vpc_id
52
- end
53
- end
54
-
55
-
56
-
57
-
58
- # Returns subnet's IP range slice in a BOSH manifest-compatible way
59
- def ip_range(subnet, range)
60
-
61
- subnet = subnet.to_a # Turn subnet into array representation to be DRY
62
-
63
- case range
64
- when Integer
65
- raise Kite::Error, 'Range number less than one in ip_range()' if range < 1
66
-
67
- subnet[0].to_s + '-' + subnet[range].to_s
68
-
69
- when Array
70
- raise Kite::Error, 'Invalid number of elements in ip_range()' unless range.length == 2
71
- raise Kite::Error, 'Second index is less than the first one in ip_range()' if range.last < range.first
72
-
73
- subnet[range.first].to_s + '-' + subnet[range.last].to_s
74
-
75
- when Range
76
- raise Kite::Error, 'Second index is less than the first one in ip_range()' if range.last < range.first
77
-
78
- range = range.to_a
79
- subnet[range.first].to_s + '-' + subnet[range.last].to_s
80
-
81
- else
82
- raise Kite::Error, 'Unsupported range type for ip_range()'
83
- end
84
- end
85
-
86
14
  end
@@ -24,8 +24,9 @@ module Kite
24
24
  exit 1
25
25
  end
26
26
 
27
- def self.execute(command, env = {})
28
- log("+ #{ command }")
27
+ def self.execute(command, env = {}, gsub_log_args = nil)
28
+ command_log = gsub_log_args ? command.gsub(*gsub_log_args) : command
29
+ log("+ #{ command_log }")
29
30
  Open3.popen2e(env, command) do |stdin, stdout, wait_thr|
30
31
  ::Kite::Helpers::Concourse.log(stdout.read)
31
32
  return wait_thr.value.exitstatus.zero?
@@ -0,0 +1,76 @@
1
+ module Kite
2
+ class Module < Base
3
+ include Kite::Helpers
4
+
5
+ method_option :env, type: :string, desc: "Environment", required: true, default: ENV['KITE_ENV']
6
+ desc 'init https://github.com/foo/bar-module', 'Initialize a kite module and render its vars.module.yml'
7
+ def init(uri)
8
+ @uri = uri
9
+ @name = uri.gsub(/(.*:|.git)/, '').split('/').last
10
+ @path = "modules/#{@name}"
11
+ @env = options[:env]
12
+
13
+ say "Cloning the #{@name} module"
14
+ clone_module
15
+
16
+ say "Rendering vars"
17
+ render_vars
18
+
19
+ say "Use git submodule add #{@path} to be able to commit this module as a submodule", :yellow
20
+ say "Rendered successfully, please fill out config/environments/#{@env}/vars.#{@name}.yml with correct values", :green
21
+ end
22
+
23
+ method_option :env, type: :string, desc: "Environment", required: true, default: ENV['KITE_ENV']
24
+ desc 'render PATH', 'Render kite module files using vars.*module*.yml'
25
+ def render(path)
26
+ @path = path
27
+ @name = @path.split('/').last
28
+ @env = options[:env]
29
+ @vars = load_vars
30
+ @cloud = parse_cloud_config[@env]
31
+
32
+ say "Rendering files"
33
+ render_templates
34
+ end
35
+
36
+ no_commands do
37
+ def kite_env
38
+ @env
39
+ end
40
+
41
+ def clone_module
42
+ if File.exist? @path
43
+ overwrite = ask "#{@path} already contains a module! Overwrite? (y/N)"
44
+
45
+ if overwrite.downcase == 'y'
46
+ remove_dir @path
47
+ Git.clone(@uri, @path)
48
+ say "Successfully cloned the fresh version!", :green
49
+ else
50
+ say "Keeping the current module"
51
+ end
52
+ else
53
+ Git.clone(@uri, @path)
54
+ end
55
+ end
56
+
57
+ def render_vars
58
+ create_file "config/environments/#{@env}/vars.#{@name}.yml", YAML.dump(manifest['variables'])
59
+ end
60
+
61
+ def render_templates
62
+ directory "#{ENV['PWD']}/modules/#{@name}/templates", ".", mode: :preserve
63
+ chmod "bin", 0755
64
+ end
65
+
66
+ def load_vars
67
+ YAML.load(File.open("config/environments/#{@env}/vars.#{@name}.yml"))
68
+ end
69
+
70
+ def manifest
71
+ YAML.load(File.open("modules/#{@name}/manifest.yml"))
72
+ end
73
+ end
74
+
75
+ end
76
+ end
@@ -0,0 +1,45 @@
1
+ module Kite
2
+ class Terraform
3
+
4
+ def initialize(core, options)
5
+ @core = core
6
+ @env_name = options[:env]
7
+ end
8
+
9
+ def run(command, *args)
10
+ STDERR.puts "Loading env"
11
+ load_env
12
+ script = "terraform #{command} #{args.join " "}"
13
+ STDERR.puts script
14
+
15
+ Dir.chdir("config/environments/#{@env_name}") do
16
+ system(script)
17
+ end
18
+ end
19
+
20
+ def load_env
21
+ load_vars
22
+ @vars.each do |var, val|
23
+ key = "TF_VAR_#{var}"
24
+ ENV[key] = val
25
+ STDERR.puts "%-25s: %s" % [key, ENV["TF_VAR_#{var}"]]
26
+ end
27
+
28
+ # TODO: Need to be set only in case of GCP
29
+ # ENV['GOOGLE_APPLICATION_CREDENTIALS'] = @vars["credentials"]
30
+ end
31
+
32
+ def cloud
33
+ YAML.load(File.read('config/cloud.yml'))[@env_name]
34
+ end
35
+
36
+ def load_vars
37
+ vars_files = Dir["config/environments/#{@env_name}/vars.*.yml"]
38
+ @vars = Hash.new
39
+ vars_files.each do |f|
40
+ tf_vars = YAML.load(File.read(f))['terraform']
41
+ @vars.merge!(tf_vars) unless tf_vars.nil?
42
+ end
43
+ end
44
+ end
45
+ end