dh-proteus 0.3.1 → 0.3.6

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: 8fb5e638db16f99a0788b308916d6788599591155e71f0b3112ba14efa899c03
4
- data.tar.gz: 5b76029b2b37a7db6c28ffef458514f84eee2a3a08f05376d7f5e199de2ce96d
3
+ metadata.gz: ee44660b54c99fcc0430739f91d7c983be8ae26dc5f7dd6bd240a8faf1419e94
4
+ data.tar.gz: 3321c7016cde53892060b64e05cc26a55e14a6cdfd66584bb38297fbc059fe57
5
5
  SHA512:
6
- metadata.gz: 27daef8b98d42b544611c2f411cd7b454b4e4706b4acbf263e0cd716c6d46ce37927ec86aa61acba8aa8923dc6e5eea9d382ddc812737e49d393c4c212faa7de
7
- data.tar.gz: aca86a828d979fff964167e593a74d1e0eb416feeb10a8391b1c4fe6e340cd57d4c32fc3e7f0a6a50eb8e352ff9606599dad228440b3770215b94fc969ed159f
6
+ metadata.gz: efe2adfa660b4e6e05760301eefc5fe382906bf76d3f38e6aca879eb9772ccd6a5f1f955904fd936862fe460ae8b77c8f920ed03ffde71806a2e94aa9d98d9bc
7
+ data.tar.gz: a131676d34b70fbaa94a0e02e317ba26f64f32f9d5a309494f7959ccb753d588463cc5b6a5b57299dafa7360d874ed27fd0210c1ccf4759102f13b29d73e69be
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
 
@@ -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
@@ -20,14 +20,18 @@ module Proteus
20
20
  # case 2: no changes in root => run contexts only
21
21
  status = `git --no-pager diff origin/master --stat --name-only`.split("\n")
22
22
 
23
- run_full_validation = if status.map {|l| !l.include?('/') }.any? || !options[:selective]
23
+ run_full_validation = if status.map { |l| !l.include?('/') }.any? || !options[:selective]
24
24
  say "Found changes in the root of the repository or --selective is not set. Running full validation.", :green
25
25
  true
26
26
  else
27
27
  say "Running selective validation.", :green
28
28
  false
29
29
  end
30
- selected_contexts = status.map { |s| s.scan(/contexts\/([a-zA-Z0-9_]+)\/((.+)\/)?/).flatten.first }.reject { |s| s.nil? }.uniq!
30
+
31
+ selected_contexts = status.collect do |s|
32
+ parts = s.split("/")
33
+ parts.size > 1 ? parts[1] : nil
34
+ end.reject { |s| s.nil? }.uniq
31
35
 
32
36
  self.class.contexts.each do |context|
33
37
  unless run_full_validation
@@ -1,5 +1,5 @@
1
1
  module Proteus
2
- VERSION = "0.3.1"
2
+ VERSION = "0.3.6"
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.1
4
+ version: 0.3.6
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-03-26 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.3
204
218
  signing_key:
205
219
  specification_version: 4
206
220
  summary: Proteus is a Terraform wrapper application.