terraspace 1.1.0 → 1.1.4

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: c6c8809128dbbbf51d0f654c92784a879c88cab49d31e15e2a1d827c4b40d051
4
- data.tar.gz: c557bd4692fddd9a1bf859a986566780cb6ccd6024dcdb3e7979138a42f1e00e
3
+ metadata.gz: 50baca1ee67aedb6160857e20b413db3e31923ee2f6bd8347723e2445d9b59ef
4
+ data.tar.gz: 0ac181788709d0700c0cfcd8085c375b453e84aef6333b9c93b446ff1bb30938
5
5
  SHA512:
6
- metadata.gz: 8b28d7d1b8565fa0f646fda57163b6d21486db7e7f704ebe657a219335e66504206769e487cec9dc3f30da06ac793e28d81b1709ebd4c32a39a70a5d8668be05
7
- data.tar.gz: 1a09efc8d460c9267371aca9dbb130e4dbb1c9268ea870e19d6a9734aa48e0134b3cee09aedfe894acfd2c7e956a1fed4bf7b38cad9cf9b13b935802bd2fa4a7
6
+ metadata.gz: ce1c04ca24e818cef35397bf9fb7cadb9e9b28838a0e15c3ec18e0e4d0b49d3bdfba4bb01e6d3e9788e5410e99c44dc827ec79a0432ae94d90fd4413c2c446ad
7
+ data.tar.gz: 95d7c2cea1917b0e3c919a43afadf24b2970dbd87c2d46d5b5846d62c6e9cc115751a7ab63defb74ad1c79917984262a7d9987eee1134e87d2778c9edcc3a175
data/CHANGELOG.md CHANGED
@@ -3,6 +3,25 @@
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
+ ## [1.1.4] - 2022-02-21
7
+ - [#210](https://github.com/boltops-tools/terraspace/pull/210) write files without magic conversion, fixes #209
8
+ - cleanup argv and root
9
+ - write files without magic conversion, fixes #209
10
+
11
+ ## [1.1.3] - 2022-02-17
12
+ - [#207](https://github.com/boltops-tools/terraspace/pull/207) dont fork when all.concurrency = 1
13
+
14
+ ## [1.1.2] - 2022-02-17
15
+ - [#200](https://github.com/boltops-tools/terraspace/pull/200) fix terraspace typos
16
+ - [#202](https://github.com/boltops-tools/terraspace/pull/202) Windows support: fix include_dir for windows
17
+ - [#203](https://github.com/boltops-tools/terraspace/pull/203) Fix ERB for windows
18
+ - [#204](https://github.com/boltops-tools/terraspace/pull/204) improve file check
19
+ - setup check terraform_bin windows support
20
+ - slight layering improvement strip trailing slash, helps with custom layering
21
+
22
+ ## [1.1.1] - 2022-02-02
23
+ - [#199](https://github.com/boltops-tools/terraspace/pull/199) build required dependent stacks as part of terraspace up
24
+
6
25
  ## [1.1.0] - 2022-01-30
7
26
  - [#196](https://github.com/boltops-tools/terraspace/pull/196) terraspace all: build modules in batches and only each specific stack
8
27
  - [#197](https://github.com/boltops-tools/terraspace/pull/197) all plan --output and all up --plan options
@@ -41,26 +41,35 @@ module Terraspace::All
41
41
  concurrency = Terraspace.config.all.concurrency
42
42
  batch.sort_by(&:name).each_slice(concurrency) do |slice|
43
43
  slice.each do |node|
44
- pid = fork do
45
- build_stack(node.name)
46
- run_terraspace(node.name)
44
+ if fork?
45
+ pid = fork do
46
+ deploy_stack(node)
47
+ end
48
+ @pids[pid] = node.name # store mod_name mapping
49
+ else
50
+ deploy_stack(node)
47
51
  end
48
- @pids[pid] = node.name # store mod_name mapping
49
52
  end
50
53
  end
54
+ return unless fork?
51
55
  wait_for_child_proccess
52
56
  summarize # also reports lower-level error info
53
57
  report_errors # reports finall errors and possibly exit
54
58
  end
55
59
 
60
+ def deploy_stack(node)
61
+ build_stack(node.name)
62
+ run_terraspace(node.name)
63
+ end
64
+
56
65
  def build_modules
57
- builder = Terraspace::Builder.new(@options.merge(mod: "placeholder", quiet: true, clean: true))
58
- builder.build(modules: true, stack: false)
66
+ builder = Terraspace::Builder.new(@options.merge(mod: "placeholder", clean: true, quiet: true, include_stacks: :none))
67
+ builder.build(modules: true)
59
68
  end
60
69
 
61
70
  def build_stack(name)
62
- builder = Terraspace::Builder.new(@options.merge(mod: name, quiet: true, clean: false))
63
- builder.build(modules: false, stack: true)
71
+ builder = Terraspace::Builder.new(@options.merge(mod: name, clean: false, quiet: true, include_stacks: :root_only))
72
+ builder.build(modules: false)
64
73
  end
65
74
 
66
75
  def wait_for_child_proccess
@@ -109,7 +118,7 @@ module Terraspace::All
109
118
  end
110
119
 
111
120
  def run_terraspace(mod_name)
112
- set_log_path!(mod_name)
121
+ set_log_path!(mod_name) if fork?
113
122
  name = command_map(@command)
114
123
  o = @options.merge(mod: mod_name, yes: true, build: false, input: false, log_to_stderr: true)
115
124
  o.merge!(quiet: false) if @command == "init" # noisy so can filter and summarize output
@@ -123,6 +132,10 @@ module Terraspace::All
123
132
  end
124
133
  end
125
134
 
135
+ def fork?
136
+ Terraspace.config.all.concurrency > 1
137
+ end
138
+
126
139
  def set_log_path!(mod_name)
127
140
  command = terraspace_command(mod_name)
128
141
  path = log_path(mod_name)
@@ -16,7 +16,7 @@ module Terraspace
16
16
  config.all = ActiveSupport::OrderedOptions.new
17
17
  config.all.concurrency = 5
18
18
  config.all.exit_on_fail = ActiveSupport::OrderedOptions.new
19
- config.all.exit_on_fail.down = true
19
+ config.all.exit_on_fail.down = false
20
20
  config.all.exit_on_fail.plan = true
21
21
  config.all.exit_on_fail.up = true
22
22
 
@@ -0,0 +1,42 @@
1
+ class Terraspace::Builder
2
+ class Children
3
+ include Terraspace::Util::Logging
4
+
5
+ def initialize(mod, options={})
6
+ @mod, @options = mod, options
7
+ @queue = []
8
+ end
9
+
10
+ def build
11
+ dependencies = Terraspace::Dependency::Registry.data
12
+ # Find out if current deploy stack contains dependency
13
+ found = dependencies.find do |parent_child|
14
+ parent, _ = parent_child.split(':')
15
+ parent == @mod.name
16
+ end
17
+ return unless found
18
+
19
+ # Go down graph children, which are the dependencies to build a queue
20
+ parent, _ = found.split(':')
21
+ node = Terraspace::Dependency::Node.find_by(name: parent)
22
+ build_queue(node)
23
+
24
+ logger.debug "Terraspace::Builder::Children @queue #{@queue}"
25
+
26
+ # Process queue in reverse order to build leaf nodes first
27
+ @queue.reverse.each do |node|
28
+ mod = Terraspace::Mod.new(node.name, @options)
29
+ Terraspace::Compiler::Perform.new(mod).compile
30
+ end
31
+ end
32
+
33
+ # Use depth first traversal to build queue
34
+ def build_queue(node)
35
+ node.children.each do |child|
36
+ @queue << child
37
+ build_queue(child)
38
+ end
39
+ @queue
40
+ end
41
+ end
42
+ end
@@ -4,23 +4,40 @@ module Terraspace
4
4
  include Compiler::DirsConcern
5
5
  include Hooks::Concern
6
6
 
7
+ # @include_stacks can be 3 values: root_with_children, none, root_only
8
+ #
9
+ # none: dont build any stacks at all. used by `terraspace all up`
10
+ # root_only: only build root stack. used by `terraspace all up`
11
+ # root_with_children: build all parent stacks as well as the root stack. normal `terraspace up`
12
+ #
13
+ def initialize(options={})
14
+ super
15
+ @include_stacks = @options[:include_stacks] || :root_with_children
16
+ end
17
+
7
18
  def run
8
19
  return if @options[:build] == false
9
20
  Terraspace::CLI::Setup::Check.check!
10
21
  check_allow!
11
22
  @mod.root_module = true
12
23
  clean
24
+ resolve_dependencies if @include_stacks == :root_with_children
13
25
  build
14
26
  end
15
27
 
16
- def build(modules: true, stack: true)
28
+ def resolve_dependencies
29
+ resolver = Terraspace::Dependency::Resolver.new(@options.merge(quiet: true))
30
+ resolver.resolve # returns batches
31
+ end
32
+
33
+ def build(modules: true)
17
34
  build_dir = Util.pretty_path(@mod.cache_dir)
18
35
  placeholder_stack_message
19
36
  logger.info "Building #{build_dir}" unless @options[:quiet] # from terraspace all
20
37
  FileUtils.mkdir_p(@mod.cache_dir) # so terraspace before build hooks work
21
38
  run_hooks("terraspace.rb", "build") do
22
39
  build_dir("modules") if modules
23
- build_root_module if stack
40
+ build_stacks
24
41
  logger.info "Built in #{build_dir}" unless @options[:quiet] # from terraspace all
25
42
  end
26
43
  end
@@ -29,16 +46,23 @@ module Terraspace
29
46
  Allow.new(@mod).check!
30
47
  end
31
48
 
32
- def build_root_module
33
- @mod.resolved = true
34
- Compiler::Perform.new(@mod).compile
49
+ def build_stacks
50
+ return if @include_stacks == :none
51
+ build_children_stacks if @include_stacks == :root_with_children
52
+ Compiler::Perform.new(@mod).compile # @include_stacks :root or :root_with_children
53
+ end
54
+
55
+ # Build stacks that are part of the dependency graph. Because .terraspace-cache folders
56
+ # need to exist so `terraform state pull` works to get the state info.
57
+ def build_children_stacks
58
+ children = Children.new(@mod, @options)
59
+ children.build
35
60
  end
36
61
 
37
62
  def build_dir(type_dir)
38
63
  with_each_mod(type_dir) do |mod|
39
- mod.resolved = true
40
64
  is_root_module = mod.cache_dir == @mod.cache_dir
41
- next if is_root_module # handled by build_root_module
65
+ next if is_root_module # handled by build_stacks
42
66
  Compiler::Perform.new(mod).compile
43
67
  end
44
68
  end
@@ -1,9 +1,9 @@
1
1
  ## Example
2
2
 
3
3
  $ terraspace check_setup
4
- Detected Terrspace version: 0.3.3
4
+ Detected Terraspace version: 0.3.3
5
5
  Detected Terraform bin: /home/ec2-user/.tfenv/bin/terraform
6
6
  Detected Terraform v0.13.2
7
7
  Terraspace requires Terraform v0.12.x and above
8
8
  You're all set!
9
- $
9
+ $
@@ -50,7 +50,7 @@ class Terraspace::CLI::New
50
50
 
51
51
  private
52
52
  def switch_ruby_version_line
53
- rbenv_installed = system("type rbenv 2>&1 > /dev/null")
53
+ rbenv_installed = system("type rbenv > /dev/null 2>&1")
54
54
  if rbenv_installed
55
55
  'eval "$(rbenv init -)"'
56
56
  end
@@ -11,7 +11,7 @@ class Terraspace::CLI::Setup
11
11
 
12
12
  # Used for the CLI
13
13
  def run
14
- puts "Detected Terrspace version: #{Terraspace::VERSION}"
14
+ puts "Detected Terraspace version: #{Terraspace::VERSION}"
15
15
  if terraform_bin
16
16
  puts "Detected Terraform bin: #{terraform_bin}"
17
17
  puts "Detected #{terraform_version_message}"
@@ -65,8 +65,12 @@ class Terraspace::CLI::Setup
65
65
  end
66
66
 
67
67
  def terraform_bin
68
- out = `type terraform 2>&1`.strip
69
- return unless $?.success?
68
+ if Gem.win_platform?
69
+ out = "is terraform.exe".strip
70
+ else
71
+ out = `type terraform 2>&1`.strip
72
+ return unless $?.success?
73
+ end
70
74
  md = out.match(/is (.*)/)
71
75
  md[1] if md
72
76
  end
@@ -30,7 +30,7 @@ module Terraspace
30
30
  include Terraspace::Util::Logging
31
31
 
32
32
  def dispatch(m, args, options, config)
33
- # Terraspace.argv provides consistency when terraspace is being called by rspec-terrspace test harness
33
+ # Terraspace.argv provides consistency when terraspace is being called by rspec-terraspace test harness
34
34
  Terraspace.argv = args.clone # important to clone since Thor removes the first argv
35
35
 
36
36
  check_standalone_install!
@@ -8,28 +8,29 @@ class Terraspace::Compiler::Strategy::Mod
8
8
  @filename = filename
9
9
  end
10
10
 
11
- @@already_reported = false
12
11
  def check
13
- unless file_installed?
14
- return true if @@already_reported
15
- logger.warn <<~EOL.color(:yellow)
16
- WARN: The command 'file' is not installed.
17
- Unable to check if files are text or binary files as a part of the Terraspace compile processing.
18
- Assuming all files are not binary file.
12
+ return true if Gem.win_platform? # assume text file if on windows
13
+ return true unless file_installed?
19
14
 
20
- Please install the file command to remove this warning message.
21
- EOL
22
- @@already_reported = true
23
- return true
24
- end
25
15
  # Thanks: https://stackoverflow.com/questions/2355866/ruby-how-to-determine-if-file-being-read-is-binary-or-text
26
16
  file_type, status = Open3.capture2e("file", @filename)
27
17
  status.success? && file_type.include?("text")
28
18
  end
29
19
 
30
20
  private
21
+ @@has_file = nil
31
22
  def file_installed?
32
- system("type file > /dev/null 2>&1")
23
+ return @@has_file unless @@has_file.nil?
24
+ @@has_file = system("type file > /dev/null 2>&1")
25
+ unless @@has_file
26
+ logger.warn <<~EOL.color(:yellow)
27
+ WARN: The command 'file' is not installed.
28
+ Unable to check if files are text or binary files as a part of the Terraspace compile processing.
29
+ Assuming all files are not binary file.
30
+ Please install the file command to remove this warning message.
31
+ EOL
32
+ end
33
+ @@has_file
33
34
  end
34
35
  end
35
36
  end
@@ -58,8 +58,9 @@ class Terraspace::Compiler::Strategy::Tfvar
58
58
  end
59
59
 
60
60
  def full_layering
61
- # layers is defined in Terraspace::Layering module
62
- layers.inject([]) do |sum, layer|
61
+ # layers defined in Terraspace::Layering module
62
+ all = layers.map { |layer| layer.sub(/\/$/,'') } # strip trailing slash
63
+ all.inject([]) do |sum, layer|
63
64
  sum += layer_levels(layer) unless layer.nil?
64
65
  sum
65
66
  end
@@ -34,7 +34,7 @@ module Terraspace::Compiler
34
34
  if content.respond_to?(:path) # IO filehandle
35
35
  FileUtils.cp(content.path, dest_path) # preserves permission
36
36
  else # just content
37
- IO.write(dest_path, content)
37
+ IO.write(dest_path, content, mode: "wb")
38
38
  end
39
39
  logger.debug "Created #{Terraspace::Util.pretty_path(dest_path)}"
40
40
  end
@@ -11,11 +11,8 @@ module Terraspace
11
11
  def root
12
12
  @@root ||= ENV['TS_ROOT'] || Dir.pwd
13
13
  end
14
-
15
14
  # allow testing frameworks to switch roots
16
- def root=(v)
17
- @@root = v
18
- end
15
+ cattr_writer :root
19
16
 
20
17
  def cache_root
21
18
  ENV['TS_CACHE_ROOT'] || config.build.cache_root || "#{root}/.terraspace-cache"
@@ -59,24 +56,9 @@ module Terraspace
59
56
  end
60
57
  end
61
58
 
62
- # Terraspace.argv provides consistency when terraspace is being called by rspec-terrspace test harness
59
+ # Terraspace.argv provides consistency when terraspace is being called by rspec-terraspace test harness
63
60
  # So use Terraspace.argv instead of ARGV constant
64
- def argv=(argv)
65
- @@argv = argv
66
- end
67
-
68
- def argv
69
- @@argv
70
- end
71
-
72
- @@check_project = true
73
- def check_project
74
- @@check_project
75
- end
76
-
77
- # allow testing frameworks to disable
78
- def check_project=(v)
79
- @@check_project = v
80
- end
61
+ cattr_accessor :argv
62
+ cattr_accessor :check_project, default: true
81
63
  end
82
64
  end
@@ -8,6 +8,7 @@ module Terraspace::Dependency
8
8
 
9
9
  def resolve
10
10
  with_each_mod("stacks") do |mod|
11
+ mod.resolved = false
11
12
  Terraspace::Compiler::Perform.new(mod).compile_tfvars(write: false)
12
13
  end
13
14
 
@@ -5,8 +5,15 @@ class Module
5
5
  # include Provider
6
6
  # # etc
7
7
  #
8
+ # Caller lines are different for OSes:
9
+ #
10
+ # windows: "C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/terraspace-1.1.1/lib/terraspace/builder.rb:34:in `build'"
11
+ # linux: "/home/ec2-user/.rvm/gems/ruby-3.0.3/gems/terraspace-1.1.1/lib/terraspace/compiler/dsl/syntax/mod.rb:4:in `<module:Mod>'"
12
+ #
8
13
  def include_dir(dir)
9
- calling_file = caller[0].split(':').first # IE: /home/ec2-user/environment/terraspace/lib/terraspace/compiler/dsl/syntax/mod.rb
14
+ caller_line = caller[0]
15
+ parts = caller_line.split(':')
16
+ calling_file = caller_line.match(/^[a-zA-Z]:/) ? parts[1] : parts[0]
10
17
  parent_dir = File.dirname(calling_file)
11
18
 
12
19
  full_dir = "#{parent_dir}/#{dir}"
@@ -15,6 +15,7 @@ module Terraspace
15
15
  @name, @options = placeholder(name), options
16
16
  @consider_stacks = options[:consider_stacks].nil? ? true : options[:consider_stacks]
17
17
  @instance = options[:instance]
18
+ @resolved = true # more common case
18
19
  end
19
20
 
20
21
  def placeholder(name)
@@ -49,7 +49,7 @@ module Terraspace::Plugin::Summary
49
49
  def download_statefiles
50
50
  return unless download?
51
51
  FileUtils.rm_rf(@dest_folder)
52
- logger.info("Downloading statefiles to #{@dest_folder}")
52
+ logger.debug("Downloading statefiles to #{@dest_folder}")
53
53
  download # INTERFACE METHOD
54
54
  end
55
55
 
@@ -48,7 +48,7 @@ module Terraspace::Terraform::RemoteState
48
48
  def output_error(type)
49
49
  msg = case type
50
50
  when :key_not_found
51
- "Output #{@output_key} was not found for the #{@parent.name} tfvars file. Either #{@child.name} stack has not been deployed yet or it does not have this output: #{@output_key}"
51
+ "Output #{@output_key} was not found for the #{@parent.name} tfvars file. Either #{@child.name} stack has not been deployed yet or it does not have this output: #{@output_key}. Also, if local backend is being used and has been removed/cleaned, then it will also result zero-byte state.json with the 'terraform state pull' used to download the terraform state and output will not be found."
52
52
  when :state_not_found
53
53
  "Output #{@output_key} could not be looked up for the #{@parent.name} tfvars file. #{@child.name} stack needs to be deployed"
54
54
  when :bucket_not_found
@@ -63,7 +63,7 @@ module Terraspace::Terraform::RemoteState
63
63
  @@download_shown = false
64
64
  def pull
65
65
  return if @@pull_successes[cache_key]
66
- logger.info "Downloading tfstate files for dependencies defined in tfvars..." unless @@download_shown || @options[:quiet]
66
+ logger.debug "Downloading tfstate files for dependencies defined in tfvars..." unless @@download_shown || @options[:quiet]
67
67
  @@download_shown = true
68
68
  logger.debug "Downloading tfstate for stack: #{@child.name}"
69
69
 
@@ -1,3 +1,3 @@
1
1
  module Terraspace
2
- VERSION = "1.1.0"
2
+ VERSION = "1.1.4"
3
3
  end
@@ -1,6 +1,10 @@
1
1
  describe Terraspace::Compiler::Erb::Render do
2
2
  let(:render) { described_class.new(mod, src_path) }
3
- let(:mod) { Terraspace::Mod.new("a1") }
3
+ let(:mod) do
4
+ mod = Terraspace::Mod.new("a1")
5
+ mod.resolved = false
6
+ mod
7
+ end
4
8
 
5
9
  # Only testing mod unresolved as a sanity check and its worth the ROI.
6
10
  # The resolved would the Fetcher. We have unit tests to cover those other changes.
data/terraspace.gemspec CHANGED
@@ -12,6 +12,10 @@ Gem::Specification.new do |spec|
12
12
  spec.homepage = "https://terraspace.cloud"
13
13
  spec.license = "Apache-2.0"
14
14
 
15
+ spec.metadata["homepage_uri"] = spec.homepage
16
+ spec.metadata["source_code_uri"] = "https://github.com/boltops-tools/terraspace"
17
+ spec.metadata["changelog_uri"] = "https://github.com/boltops-tools/terraspace/blob/master/CHANGELOG.md"
18
+
15
19
  spec.files = File.directory?('.git') ? `git ls-files`.split($/) : Dir.glob("**/*")
16
20
  spec.bindir = "exe"
17
21
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
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: 1.1.0
4
+ version: 1.1.4
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-01-30 00:00:00.000000000 Z
11
+ date: 2022-02-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -490,6 +490,7 @@ files:
490
490
  - lib/terraspace/builder/allow/env.rb
491
491
  - lib/terraspace/builder/allow/region.rb
492
492
  - lib/terraspace/builder/allow/stack.rb
493
+ - lib/terraspace/builder/children.rb
493
494
  - lib/terraspace/bundle.rb
494
495
  - lib/terraspace/cli.rb
495
496
  - lib/terraspace/cli/all.rb
@@ -869,7 +870,10 @@ files:
869
870
  homepage: https://terraspace.cloud
870
871
  licenses:
871
872
  - Apache-2.0
872
- metadata: {}
873
+ metadata:
874
+ homepage_uri: https://terraspace.cloud
875
+ source_code_uri: https://github.com/boltops-tools/terraspace
876
+ changelog_uri: https://github.com/boltops-tools/terraspace/blob/master/CHANGELOG.md
873
877
  post_install_message:
874
878
  rdoc_options: []
875
879
  require_paths: