dh-proteus 0.3.2 → 0.3.7

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: db62c1bb1740497f53c9a44f65f17caa5f9f87e4ae4a9de7c01feab1b5caec23
4
- data.tar.gz: fabed14cd58cf6072f7743525c016f8c117cd83b86265e568852ba6f766a41ef
3
+ metadata.gz: 9cdd09685fbb59a3fba9da1b7b1e0b1f84bdbaec975dccd6eb3148526ab7ae05
4
+ data.tar.gz: 631163e0ae642ae6328eff584a7be1eafb1fbf8d1f0de7fab19e52d45832dc15
5
5
  SHA512:
6
- metadata.gz: '0487e5755a6407b3911004992422c40c769c9aef39aeab266bdd09a5a3c4b26d74ba5986159ff05248247595339f23545ee87891cc90ee3261c85c405742d763'
7
- data.tar.gz: ddbb13d16550d53bafc1256408d588ffef72e691f2f863e55bfcb07c0c59f440172d588c07ea97d9148e93dde35158f369b33e017491e0e5ed0a1426e1264754
6
+ metadata.gz: c62a0a514498abeef4f19cf913920f98802726ba83694bebc8dd03ece8cbfb4a70a11b2304b44ba4bfae2e95049e58de8c36fb54f37cd0cfe753e2d6681310ff
7
+ data.tar.gz: f010f09c3129f436ae3bd728020ee395c3fdbd22c42ef7dec4dc8371f7c6f7a7b864bdedb0fe19b2b2e24c797d11cb5ab8667c0ef3634dd14d0a18094ca3c7cc
data/Gemfile.lock CHANGED
@@ -1,12 +1,10 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- dh-proteus (0.1.4)
4
+ dh-proteus (0.3.4)
5
5
  activesupport (~> 5.1.1)
6
- aws-sdk-elasticsearchservice (~> 1.4.0)
7
- aws-sdk-rds (~> 1.11.0)
8
- aws-sdk-route53 (~> 1.7.0)
9
6
  erubis (~> 2.7.0)
7
+ terminal-table (~> 3.0.0)
10
8
  thor (~> 0.20.0)
11
9
 
12
10
  GEM
@@ -17,33 +15,14 @@ GEM
17
15
  i18n (>= 0.7, < 2)
18
16
  minitest (~> 5.1)
19
17
  tzinfo (~> 1.1)
20
- aws-eventstream (1.0.3)
21
- aws-partitions (1.189.0)
22
- aws-sdk-core (3.59.0)
23
- aws-eventstream (~> 1.0, >= 1.0.2)
24
- aws-partitions (~> 1.0)
25
- aws-sigv4 (~> 1.1)
26
- jmespath (~> 1.0)
27
- aws-sdk-elasticsearchservice (1.4.0)
28
- aws-sdk-core (~> 3)
29
- aws-sigv4 (~> 1.0)
30
- aws-sdk-rds (1.11.0)
31
- aws-sdk-core (~> 3)
32
- aws-sigv4 (~> 1.0)
33
- aws-sdk-route53 (1.7.0)
34
- aws-sdk-core (~> 3)
35
- aws-sigv4 (~> 1.0)
36
- aws-sigv4 (1.1.0)
37
- aws-eventstream (~> 1.0, >= 1.0.2)
38
18
  coderay (1.1.1)
39
- concurrent-ruby (1.1.5)
19
+ concurrent-ruby (1.1.8)
40
20
  diff-lcs (1.3)
41
21
  erubis (2.7.0)
42
- i18n (1.6.0)
22
+ i18n (1.8.9)
43
23
  concurrent-ruby (~> 1.0)
44
- jmespath (1.4.0)
45
24
  method_source (0.8.2)
46
- minitest (5.11.3)
25
+ minitest (5.14.4)
47
26
  pry (0.10.4)
48
27
  coderay (~> 1.1.0)
49
28
  method_source (~> 0.8.1)
@@ -63,10 +42,13 @@ GEM
63
42
  rspec-support (~> 3.8.0)
64
43
  rspec-support (3.8.0)
65
44
  slop (3.6.0)
45
+ terminal-table (3.0.0)
46
+ unicode-display_width (~> 1.1, >= 1.1.1)
66
47
  thor (0.20.3)
67
48
  thread_safe (0.3.6)
68
- tzinfo (1.2.5)
49
+ tzinfo (1.2.9)
69
50
  thread_safe (~> 0.1)
51
+ unicode-display_width (1.7.0)
70
52
 
71
53
  PLATFORMS
72
54
  ruby
@@ -79,4 +61,4 @@ DEPENDENCIES
79
61
  rspec (~> 3.0)
80
62
 
81
63
  BUNDLED WITH
82
- 2.0.1
64
+ 2.2.3
data/dh-proteus.gemspec CHANGED
@@ -43,4 +43,5 @@ Gem::Specification.new do |spec|
43
43
  spec.add_runtime_dependency 'activesupport', '~> 5.1.1'
44
44
  spec.add_runtime_dependency 'thor', '~> 0.20.0'
45
45
  spec.add_runtime_dependency 'erubis', '~> 2.7.0'
46
+ spec.add_runtime_dependency 'terminal-table', '~> 3.0.0'
46
47
  end
data/lib/proteus/app.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require 'proteus/common'
2
2
  require 'proteus/generate'
3
3
  require 'proteus/init'
4
+ require 'proteus/backend_info'
4
5
  require 'proteus/global_commands/validate'
5
6
  require 'proteus/global_commands/version'
6
7
  require 'proteus/context_management/context'
@@ -22,7 +23,7 @@ module Proteus
22
23
  extend Proteus::ContextManagement::Helpers
23
24
 
24
25
  class_option :dryrun, type: :boolean, default: false, aliases: '-d'
25
- class_option :verbose, type: :boolean, default: false, aliases: '-v'
26
+ class_option :verbose, type: :boolean, default: true, aliases: '-v'
26
27
 
27
28
  contexts.each do |context|
28
29
 
@@ -113,6 +114,9 @@ module Proteus
113
114
  desc 'init', 'Initializes a new proteus root directory in the current working directory'
114
115
  subcommand('init', Proteus::Init)
115
116
 
117
+ desc 'backend_info', 'Shows information about backends'
118
+ subcommand('backend_info', Proteus::BackendInfo)
119
+
116
120
  include Proteus::GlobalCommands::Validate
117
121
  include Proteus::GlobalCommands::Version
118
122
  end
@@ -13,17 +13,7 @@ module Proteus
13
13
  @context = context
14
14
  @environment = environment
15
15
 
16
- @config[:providers].each do |provider|
17
- provider[:environments].each do |env|
18
- env[:match].each do |m|
19
- if @environment == m
20
- @provider_environment = env
21
- end
22
- end
23
- end
24
- end
25
-
26
- @backend_key = @provider_environment[:backend]
16
+ find_backend_key
27
17
  end
28
18
 
29
19
  def render
@@ -36,8 +26,51 @@ module Proteus
36
26
  exit 1
37
27
  end
38
28
 
29
+ def show_backends
30
+ require 'terminal-table'
31
+ table = Terminal::Table.new do |t|
32
+ t << ['Context', 'Environment', 'Profile', 'Bucket']
33
+
34
+ @config[:contexts].each do |ctx|
35
+ ctx[:environments].each do |env|
36
+ env[:match].each do |m|
37
+ t << [
38
+ ctx[:name],
39
+ m,
40
+ @config[:backend][env[:backend]][:profile],
41
+ @config[:backend][env[:backend]][:bucket][:name]
42
+ ]
43
+ end
44
+ end
45
+ end
46
+ end
47
+
48
+ say table, :green
49
+
50
+ end
51
+
52
+ def aws_profile
53
+ @config[:backend][@backend_key][:profile]
54
+ end
55
+
39
56
  protected
40
57
 
58
+ def find_backend_key
59
+ @config[:contexts].each do |ctx|
60
+ if ctx[:name] == @context
61
+ ctx[:environments].each do |env|
62
+ env[:match].each do |m|
63
+ if @environment == m
64
+ @backend_key = env[:backend]
65
+ say "Using backend #{@backend_key}", :green
66
+ return
67
+ end
68
+ end
69
+ end
70
+ end
71
+ end
72
+ end
73
+
41
74
  def template
42
75
  <<~TEMPLATE
43
76
  terraform {
@@ -45,7 +78,7 @@ module Proteus
45
78
  bucket = "<%= @config[:backend][@backend_key][:bucket][:name] %>"
46
79
  key = "<%= @config[:backend][@backend_key][:key_prefix] %>#{@context}-#{@environment}.tfstate"
47
80
  region = "<%= @config[:backend][@backend_key][:bucket][:region] %>"
48
- profile = "<%= @config[:backend][@backend_key][:bucket][:profile]%>"
81
+ profile = "<%= @config[:backend][@backend_key][:profile]%>"
49
82
  }
50
83
  }
51
84
  TEMPLATE
@@ -0,0 +1,19 @@
1
+ require 'proteus/backend/backend'
2
+
3
+ module Proteus
4
+ class BackendInfo < Thor
5
+ include Thor::Actions
6
+ include Helpers
7
+ include Config
8
+
9
+ desc "backend-info", "Shows information about backend configuration"
10
+ long_desc <<-LONGDESC
11
+ Shows information about backend configuration
12
+ LONGDESC
13
+ def backend_info
14
+ Proteus::Backend::Backend.new(config: config, context: nil, environment: nil).show_backends
15
+ end
16
+
17
+ default_task :backend_info
18
+ end
19
+ end
@@ -7,10 +7,7 @@ module Proteus
7
7
  desc 'apply', 'Applies the current terraform code'
8
8
  long_desc <<-LONGDESC
9
9
  Applies the current terraform code
10
-
11
- With --limit option, Terraform will only apply changes for the the specified resources
12
10
  LONGDESC
13
- option :limit, type: :array, aliases: "-l", required: false, default: nil
14
11
  def apply
15
12
  init(verbose: parent_options[:verbose])
16
13
 
@@ -30,7 +27,6 @@ module Proteus
30
27
  terraform apply \
31
28
  -input=true \
32
29
  -refresh=true \
33
- #{limit(options[:limit])} \
34
30
  #{plan_file(context, environment)}
35
31
  APPLY_COMMAND
36
32
 
@@ -10,6 +10,7 @@ module Proteus
10
10
  long_desc <<-LONGDESC
11
11
  Renders the module templates without running Terraform
12
12
  LONGDESC
13
+ option :init, type: :boolean, default: false
13
14
  def render
14
15
  render_backend
15
16
  module_manager = Proteus::Modules::Manager.new(context: context, environment: environment)
@@ -26,6 +27,8 @@ module Proteus
26
27
  suppress: true
27
28
  )
28
29
 
30
+ init(verbose: parent_options[:verbose]) if options[:init]
31
+
29
32
  say "Formatted files:", :green
30
33
  say fmt_output, :green
31
34
  end
@@ -30,17 +30,17 @@ module Proteus
30
30
  end
31
31
 
32
32
  def render_backend
33
- backend = Proteus::Backend::Backend.new(config: config, context: context, environment: environment)
34
- backend.render
33
+ @backend = Proteus::Backend::Backend.new(config: config, context: context, environment: environment)
34
+ @backend.render
35
35
 
36
- backend
36
+ @backend
37
37
  end
38
38
 
39
39
  def init(verbose: false)
40
40
  say "initializing", :green
41
41
  say "environment: #{environment}", :green
42
42
 
43
- backend = render_backend
43
+ @backend = render_backend
44
44
 
45
45
  `rm -rf #{context_path(context)}/.terraform/*.tf*`
46
46
  `rm -rf #{context_path(context)}/.terraform/modules`
@@ -49,23 +49,16 @@ module Proteus
49
49
  terraform_command = <<~TERRAFORM_COMMAND
50
50
  cd #{context_path(context)} && \
51
51
  terraform init \
52
- -backend-config='key=#{config[:backend][backend.backend_key][:key_prefix]}#{context}-#{environment}.tfstate' \
52
+ -backend-config='key=#{config[:backend][@backend.backend_key][:key_prefix]}#{context}-#{environment}.tfstate' \
53
53
  #{aws_profile} \
54
54
  #{context_path(context)}
55
55
  TERRAFORM_COMMAND
56
56
 
57
- output = syscall terraform_command.squeeze(' '), suppress: true, capture: true
58
- say(output, :green) if verbose
57
+ syscall terraform_command.squeeze(' ')
59
58
  end
60
59
 
61
60
  def aws_profile
62
- config[:providers].select {|p| p[:name] == 'aws' }.first[:environments].each do |env|
63
- env[:match].each do |m|
64
- return "-var 'aws_profile=#{env[:profile]}'" if environment == m
65
- end
66
- end
67
-
68
- ""
61
+ "-var 'aws_profile=#{@backend.aws_profile}'"
69
62
  end
70
63
 
71
64
  def dryrun
@@ -16,17 +16,19 @@ module Proteus
16
16
 
17
17
  class ConfigValidator < Proteus::Validators::BaseValidator
18
18
  def validate
19
- within :providers do
19
+ within :contexts do
20
20
  ensure_data_type Array
21
+ ensure_uniqueness_across :name
21
22
 
22
23
  each do
23
24
  ensure_keys :name
25
+ ensure_uniqueness_across :name
24
26
 
25
27
  within :environments do
26
28
  ensure_uniqueness_across :match
27
29
 
28
30
  each do
29
- ensure_keys :profile, :backend
31
+ ensure_keys :backend
30
32
  end
31
33
  end
32
34
  end
@@ -42,10 +44,10 @@ module Proteus
42
44
 
43
45
  within :backend do
44
46
  each_key do
45
- ensure_presence :key_prefix
47
+ ensure_keys :key_prefix, :profile
46
48
 
47
49
  within :bucket do
48
- ensure_keys :name, :region, :profile
50
+ ensure_keys :name, :region
49
51
  end
50
52
  end
51
53
  end
@@ -35,7 +35,9 @@ module Proteus
35
35
  if tfvars_content.empty?
36
36
  terraform_variables = []
37
37
  else
38
- terraform_variables = JSON.parse(parse_tfvars(tfvars: tfvars_content))
38
+ terraform_variables = JSON.parse(parse_tfvars(tfvars: tfvars_content)).merge({
39
+ 'proteus_environment' => @environment
40
+ })
39
41
  end
40
42
 
41
43
  @modules = []
@@ -1,5 +1,5 @@
1
1
  module Proteus
2
- VERSION = "0.3.2"
2
+ VERSION = "0.3.7"
3
3
  end
4
4
 
5
5
  if $0 == __FILE__
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dh-proteus
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.3.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Simon Albrecht
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-09-15 00:00:00.000000000 Z
11
+ date: 2021-06-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -108,6 +108,20 @@ dependencies:
108
108
  - - "~>"
109
109
  - !ruby/object:Gem::Version
110
110
  version: 2.7.0
111
+ - !ruby/object:Gem::Dependency
112
+ name: terminal-table
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: 3.0.0
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: 3.0.0
111
125
  description:
112
126
  email:
113
127
  - simon.albrecht@deliveryhero.com
@@ -132,6 +146,7 @@ files:
132
146
  - lib/proteus.rb
133
147
  - lib/proteus/app.rb
134
148
  - lib/proteus/backend/backend.rb
149
+ - lib/proteus/backend_info.rb
135
150
  - lib/proteus/commands/apply.rb
136
151
  - lib/proteus/commands/clean.rb
137
152
  - lib/proteus/commands/destroy.rb
@@ -199,8 +214,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
199
214
  - !ruby/object:Gem::Version
200
215
  version: '0'
201
216
  requirements: []
202
- rubyforge_project:
203
- rubygems_version: 2.7.6.2
217
+ rubygems_version: 3.2.15
204
218
  signing_key:
205
219
  specification_version: 4
206
220
  summary: Proteus is a Terraform wrapper application.