terraspace 2.1.3 → 2.1.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: 821596efa82fca834084cd1ff1128f2d19e12fcf6b29143eac95c0b160d0724d
4
- data.tar.gz: f423fb9b8958619a342783e5bbcd07f61e39301d6faa8b7af7c1c53d59fcccc4
3
+ metadata.gz: 449ffd121de77d38b64d44f30a56639714f27fd3b0a7c50b00c4f897157c9ef5
4
+ data.tar.gz: 815fddcc7cfa9b01e335de6d160d941c6d1b4a025b6bab902a1aa4552752b9df
5
5
  SHA512:
6
- metadata.gz: dec9d3e94b3b3e2ab3eea0c14392729eef461cc2a2c451365a158aaf2f6fe7e619b961dc9ccee3f6a18ed329a6eba199d33164c1857df8d469b4fe0f7b034193
7
- data.tar.gz: 3608ca4855cf1a30feb7aa2e2287c97a2f80fbcd5c74e8339076180f34ae54c93eefc13dc57ab6cc74829f9d46b3389ef534659e6804cf98c3d2d21021a61470
6
+ metadata.gz: dc167ec202e62e70dd129d4ac85dc30a4179576315b880303205569434d7e31a35e5d331df64b2e478efb0459fcb902764ec6c860af650ea7ec8dcbc7caefe47
7
+ data.tar.gz: da40e6f0760f535a0e604aad16b31ddd708090521c070469739a0e13d0129542676951892e1859fd779b4bcbbda15a168e260cd43dc4e41964bbc0a0a28ffb48
data/CHANGELOG.md CHANGED
@@ -3,6 +3,17 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  This project *loosely tries* to adhere to [Semantic Versioning](http://semver.org/), even before v1.0.
5
5
 
6
+ ## [2.1.6] - 2022-08-19
7
+ - [#258](https://github.com/boltops-tools/terraspace/pull/258) Fix terraform apply/destroy missing some passthrough options
8
+
9
+ ## [2.1.5] - 2022-07-21
10
+ - [#255](https://github.com/boltops-tools/terraspace/pull/255) dont compute git info when not cloud not enabled and warn message improvement
11
+ - pin terraspace to major version in initially generated Gemfile
12
+
13
+ ## [2.1.4] - 2022-07-16
14
+ - [#252](https://github.com/boltops-tools/terraspace/pull/252) puts friendlier user message with terraspace force_unlock suggestion
15
+ - [#253](https://github.com/boltops-tools/terraspace/pull/253) azure repo local git support
16
+
6
17
  ## [2.1.3] - 2022-07-13
7
18
  - [#251](https://github.com/boltops-tools/terraspace/pull/251) deprecation warning for `:CACHE_ROOT` in `config.build.cache_dir`
8
19
 
@@ -10,5 +10,5 @@ build_gemfile(
10
10
 
11
11
  # Uncomment the ci and vcs provider you wish to use. Should use both ci and vcs gem
12
12
  # Docs: https://terraspace.cloud/docs/ci/
13
- # gem "terraspace_ci_github"
14
- # gem "terraspace_vcs_github"
13
+ # gem "terraspace_ci_github" # gathers info from ci env
14
+ # gem "terraspace_vcs_github" # post comment on pr
@@ -13,7 +13,8 @@ class Terraspace::CLI::New
13
13
 
14
14
  def gem_line(name)
15
15
  if name == "terraspace"
16
- %Q|gem "#{name}", '~> #{Terraspace::VERSION}'|
16
+ major_version = Terraspace::VERSION.split('.').first
17
+ %Q|gem "#{name}", '~> #{major_version}'|
17
18
  else
18
19
  %Q|gem "#{name}"|
19
20
  end
@@ -46,6 +46,7 @@ class Terraspace::Cloud::Vcs
46
46
  # pr_url
47
47
  #
48
48
  def vcs_vars
49
+ return {} unless Terraspace.cloud?
49
50
  ci_env = CiEnv.new
50
51
  local_git = LocalGit.new
51
52
  local_env = LocalEnv.new
@@ -0,0 +1,62 @@
1
+ class Terraspace::Cloud::Vcs::LocalGit
2
+ class Azure < Base
3
+ def vars
4
+ super.merge(
5
+ host: host,
6
+ full_repo: full_repo,
7
+ )
8
+ end
9
+
10
+ def commit_url
11
+ # IE: https://dev.azure.com/tongueroo/infra-project/_git/infra-ci/commit/aaa74f96d76053672ff1b91995c903605cd8a245
12
+ "#{base_repo_url}/commits/#{sha}" if sha
13
+ end
14
+
15
+ def base_repo_url
16
+ "#{host}/#{org}/#{project}/_git/#{repo}"
17
+ end
18
+
19
+ def branch_url
20
+ # IE: https://dev.azure.com/tongueroo/infra-project/_git/infra-ci?version=GBmerge
21
+ "#{base_repo_url}?verison=GB#{sha}" if sha
22
+ end
23
+
24
+ # Also computed in ci plugins which detects it from the ci env.
25
+ # Also handling here for case when user provides PR_NUMBER and GIT_REPO outside of normal CI env.
26
+ def pr_url
27
+ "#{host}/#{full_repo}/pull-requests/#{pr_number}" if pr_number
28
+ end
29
+
30
+ # override to remove ssh
31
+ # https://ssh.dev.azure.com => https://dev.azure.com
32
+ def host
33
+ "https://dev.azure.com"
34
+ end
35
+
36
+ def url_info
37
+ uri = URI(git_url)
38
+ # IE: v3/tongueroo/infra-project/infra-ci
39
+ uri.path.sub(/^\//,'').split('/') # [version, org, project, repo]
40
+ end
41
+
42
+ def org
43
+ version, org, project, repo = url_info
44
+ org
45
+ end
46
+
47
+ def repo
48
+ version, org, project, repo = url_info
49
+ repo
50
+ end
51
+
52
+ def full_repo
53
+ version, org, project, repo = url_info
54
+ "#{org}/#{repo}"
55
+ end
56
+
57
+ def project
58
+ version, org, project, repo = url_info
59
+ project
60
+ end
61
+ end
62
+ end
@@ -2,8 +2,9 @@ class Terraspace::Cloud::Vcs::LocalGit
2
2
  class Base
3
3
  extend Memoist
4
4
 
5
- def initialize(vars)
6
- @vars = vars
5
+ attr_reader :git_url
6
+ def initialize(vars, git_url)
7
+ @vars, @git_url = vars, git_url
7
8
  end
8
9
 
9
10
  def vars
@@ -1,8 +1,8 @@
1
1
  class Terraspace::Cloud::Vcs
2
2
  class LocalGit < Base
3
3
  def vars
4
- if git_repo? && git_installed?
5
- provider_vars = vcs_class ? vcs_class.new(base_vars).vars : {}
4
+ if git_repo? && git_installed? && host
5
+ provider_vars = vcs_class ? vcs_class.new(base_vars, git_url).vars : {}
6
6
  base_vars.merge(provider_vars).compact # remove items with nil values
7
7
  else
8
8
  { build_system: "manual" }
@@ -11,9 +11,10 @@ class Terraspace::Cloud::Vcs
11
11
 
12
12
  def vcs_class
13
13
  case host
14
- when /github/ then Github
15
- when /gitlab/ then Gitlab
16
- when /bitbucket/ then Bitbucket
14
+ when /github\.com/ then Github
15
+ when /gitlab\.com/ then Gitlab
16
+ when /bitbucket\.org/ then Bitbucket
17
+ when /ssh\.dev\.azure\.com/ then Azure
17
18
  end
18
19
  end
19
20
 
@@ -35,6 +36,15 @@ class Terraspace::Cloud::Vcs
35
36
  return nil if git_url.blank?
36
37
  uri = URI(git_url)
37
38
  "#{uri.scheme}://#{uri.host}"
39
+ rescue URI::InvalidURIError => e
40
+ logger.info "WARN: #{e.class} #{e.message}".color(:yellow)
41
+ logger.info <<~EOL
42
+ Unable to get the host info from your local .git/config
43
+ Will not be able to determine local git info.
44
+ If possible, it would be a useful to provide the remote.url in your .git/config
45
+ as an issue report or email to improve help improve this logic.
46
+ EOL
47
+ nil
38
48
  end
39
49
 
40
50
  def full_repo
@@ -16,6 +16,8 @@ class Terraspace::Shell
16
16
  Terraspace::BucketNotFoundError.new(message)
17
17
  elsif shared_cache_error?
18
18
  Terraspace::SharedCacheError.new(message)
19
+ elsif state_lock_error?
20
+ Terraspace::StateLockError.new(message)
19
21
  end
20
22
  end
21
23
 
@@ -43,5 +45,10 @@ class Terraspace::Shell
43
45
  message.include?("Failed to install provider from shared cache") ||
44
46
  message.include?("Failed to validate installed provider")
45
47
  end
48
+
49
+ def state_lock_error?
50
+ # Example: https://gist.github.com/tongueroo/6bcb86f88053c58fa50f434789268b78
51
+ message.include?("Error acquiring the state lock")
52
+ end
46
53
  end
47
54
  end
@@ -60,6 +60,17 @@ module Terraspace::Terraform::Args
60
60
  result
61
61
  end
62
62
 
63
+ def terraform_arg_types
64
+ arg_types = terraform_arg_types_for_command(@name)
65
+ # "terraspace apply/destroy" support the same options as "plan", but they don't document
66
+ # them directly in their "-help" option, so we need to add them.
67
+ if ["apply", "destroy"].include? @name
68
+ arg_types.merge! terraform_arg_types_for_command("plan")
69
+ end
70
+
71
+ arg_types
72
+ end
73
+
63
74
  # Parses terraform COMMAND -help output for arg types.
64
75
  # Return Example:
65
76
  #
@@ -69,8 +80,8 @@ module Terraspace::Terraform::Args
69
80
  # var: :hash,
70
81
  # }
71
82
  #
72
- def terraform_arg_types
73
- out = terraform_help(@name)
83
+ def terraform_arg_types_for_command(name)
84
+ out = terraform_help(name)
74
85
  lines = out.split("\n")
75
86
  lines.select! do |line|
76
87
  line =~ /^ -/
@@ -65,6 +65,18 @@ module Terraspace::Terraform
65
65
  else
66
66
  exit(1)
67
67
  end
68
+ rescue Terraspace::StateLockError => e
69
+ logger.debug "ERROR: #{e.class}".color(:red)
70
+ logger.info e.message
71
+ md = e.message.match(/\s+ID:\s+(.*)/)
72
+ return unless md
73
+ return unless lock_id = md[1]
74
+ logger.info <<~EOL
75
+ You can force release the lock with:
76
+
77
+ terraspace force_unlock #{@mod.name} #{lock_id}
78
+
79
+ EOL
68
80
  end
69
81
 
70
82
  @@current_dir_message_shown = false
@@ -1,3 +1,3 @@
1
1
  module Terraspace
2
- VERSION = "2.1.3"
2
+ VERSION = "2.1.6"
3
3
  end
data/lib/terraspace.rb CHANGED
@@ -32,9 +32,10 @@ module Terraspace
32
32
 
33
33
  class BucketNotFoundError < Error; end
34
34
  class InitRequiredError < Error; end
35
+ class NetworkError < Error; end
35
36
  class SharedCacheError < Error; end
36
37
  class ShellError < Error; end
37
- class NetworkError < Error; end
38
+ class StateLockError < Error; end
38
39
  end
39
40
 
40
41
  Terraspace::Booter.boot
@@ -51,6 +51,19 @@ describe Terraspace::Terraform::Args::Pass do
51
51
  end
52
52
  end
53
53
 
54
+ context "indirectly documented args" do
55
+ # "terraform apply -help" doesn't document "-target" directly, but refers to
56
+ # "terraform plan -help" documentation.
57
+ context "-target=resource" do
58
+ let(:args) { ["-target=foo.bar"] }
59
+ let(:name) { "apply" }
60
+ it "pass through args" do
61
+ args = pass.args
62
+ expect(args).to eq ["-target=foo.bar"]
63
+ end
64
+ end
65
+ end
66
+
54
67
  context "hash arg" do
55
68
  context "-var 'foo=bar'" do
56
69
  let(:args) { ["-var 'foo=bar'"] }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: terraspace
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.3
4
+ version: 2.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tung Nguyen
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-07-13 00:00:00.000000000 Z
11
+ date: 2022-08-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -670,6 +670,7 @@ files:
670
670
  - lib/terraspace/cloud/vcs/interface.rb
671
671
  - lib/terraspace/cloud/vcs/local_env.rb
672
672
  - lib/terraspace/cloud/vcs/local_git.rb
673
+ - lib/terraspace/cloud/vcs/local_git/azure.rb
673
674
  - lib/terraspace/cloud/vcs/local_git/base.rb
674
675
  - lib/terraspace/cloud/vcs/local_git/bitbucket.rb
675
676
  - lib/terraspace/cloud/vcs/local_git/github.rb