dh-proteus 0.3.0 → 0.3.5

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: 263b0afd288fa51a29ea54621b191dd8cb86a4337456226694bf8c8047dd2534
4
- data.tar.gz: 202ba99d158dabcfb19db4bc583f9a7fe4657697f38f0f0923b240232f50524b
3
+ metadata.gz: aa12aa3c83be1ffe103180c3069d73f676b6ad4da32d9d283eeefdc3c14dcd85
4
+ data.tar.gz: '08b72501192990db34e12e3dd52be0001a708c559709a1e999da5557acf53a48'
5
5
  SHA512:
6
- metadata.gz: '09320cdfeb939b664384449b04496fd649886df20adab89c947b1c89b82cc94b91d2f9afd8c4749de3c9c93202b9aa71bb403e3f0f2e36d7bada77d41fb9c8ff'
7
- data.tar.gz: c2c3c0d51070d4db497cf14e1f3a1b00d8df9efc3e555c2f1feba7776e088436b066eca4f650615d02b44102a4a080b457610ba40814153b3aba45dae21b1cd9
6
+ metadata.gz: f4906493215ab3fc7ee3e3b871f05c83022eb36b388a3cb1cecd3d50a19d38cf794c83a7db1967870de103ee676ef61b82ba830bf06e924b7f1f8fa09378d234
7
+ data.tar.gz: 75200103d748eb3a4bf7150317d9e51cf08f0d820108ab69410010ffa0f3b126126967327f422ddabdd420fa49f6b6f81dcb897c499e4201d8bb6e6308dcdeb7
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,7 +49,7 @@ 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
@@ -59,13 +59,7 @@ module Proteus
59
59
  end
60
60
 
61
61
  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
- ""
62
+ "-var 'aws_profile=#{@backend.aws_profile}'"
69
63
  end
70
64
 
71
65
  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
@@ -14,8 +14,33 @@ module Proteus
14
14
  long_desc <<-LONGDESC
15
15
  Renders templates for all environments, reporting validation errors.
16
16
  LONGDESC
17
+ option :selective, type: :boolean, default: false
17
18
  def validate
19
+ # case 1: changes in root => run full validation
20
+ # case 2: no changes in root => run contexts only
21
+ status = `git --no-pager diff origin/master --stat --name-only`.split("\n")
22
+
23
+ run_full_validation = if status.map { |l| !l.include?('/') }.any? || !options[:selective]
24
+ say "Found changes in the root of the repository or --selective is not set. Running full validation.", :green
25
+ true
26
+ else
27
+ say "Running selective validation.", :green
28
+ false
29
+ end
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
35
+
18
36
  self.class.contexts.each do |context|
37
+ unless run_full_validation
38
+ if !selected_contexts.include?(context.name)
39
+ say "Skipping context #{context.name}.", :green
40
+ next
41
+ end
42
+ end
43
+
19
44
  context.environments.each do |environment|
20
45
  module_manager = Proteus::Modules::Manager.new(context: context.name, environment: environment)
21
46
  module_manager.render_modules
@@ -1,5 +1,5 @@
1
1
  module Proteus
2
- VERSION = "0.3.0"
2
+ VERSION = "0.3.5"
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.0
4
+ version: 0.3.5
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-02 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.