Class: Terraspace::Mod
- Inherits:
-
Object
- Object
- Terraspace::Mod
- Extended by:
- Memoist
- Includes:
- Util
- Defined in:
- lib/terraspace/mod.rb,
lib/terraspace/mod/remote.rb
Overview
Example properties:
name: vpc
root: app/modules/vpc, app/stacks/vpc, vendor/modules/vpc or vendor/stacks/vpc
type: module or stack
Direct Known Subclasses
Defined Under Namespace
Classes: Remote
Instance Attribute Summary collapse
-
#consider_stacks ⇒ Object
readonly
Returns the value of attribute consider_stacks.
-
#instance ⇒ Object
readonly
Returns the value of attribute instance.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#root_module ⇒ Object
Returns the value of attribute root_module.
Instance Method Summary collapse
-
#build_dir(disable_instance: false) ⇒ Object
Relative folder path without app or vendor.
-
#cache_dir ⇒ Object
Full path with build_dir.
- #check_exist! ⇒ Object
-
#initialize(name, options = {}) ⇒ Mod
constructor
A new instance of Mod.
- #placeholder(name) ⇒ Object
-
#possible_fake_root ⇒ Object
If the app/stacks/NAME has been removed in source code but stack still exist in the cloud.
- #root ⇒ Object
- #root_module? ⇒ Boolean
- #to_info ⇒ Object
- #type ⇒ Object
- #type_dir ⇒ Object
Methods included from Util
Methods included from Util::Sure
Methods included from Util::Sh
Methods included from Util::Logging
Constructor Details
#initialize(name, options = {}) ⇒ Mod
Returns a new instance of Mod.
13 14 15 16 17 |
# File 'lib/terraspace/mod.rb', line 13 def initialize(name, ={}) @name, @options = placeholder(name), @consider_stacks = [:consider_stacks].nil? ? true : [:consider_stacks] @instance = [:instance] end |
Instance Attribute Details
#consider_stacks ⇒ Object (readonly)
Returns the value of attribute consider_stacks.
12 13 14 |
# File 'lib/terraspace/mod.rb', line 12 def consider_stacks @consider_stacks end |
#instance ⇒ Object (readonly)
Returns the value of attribute instance.
12 13 14 |
# File 'lib/terraspace/mod.rb', line 12 def instance @instance end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
12 13 14 |
# File 'lib/terraspace/mod.rb', line 12 def name @name end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
12 13 14 |
# File 'lib/terraspace/mod.rb', line 12 def @options end |
#root_module ⇒ Object
Returns the value of attribute root_module.
27 28 29 |
# File 'lib/terraspace/mod.rb', line 27 def root_module @root_module end |
Instance Method Details
#build_dir(disable_instance: false) ⇒ Object
Relative folder path without app or vendor. For example, the actual location can be found in a couple of places
app/modules/vpc
app/stacks/vpc
vendor/modules/vpc
vendor/stacks/vpc
The build folder does not include the app or vendor info.
modules/vpc
88 89 90 91 92 93 94 95 96 |
# File 'lib/terraspace/mod.rb', line 88 def build_dir(disable_instance: false) if !disable_instance && !@instance.nil? # add _ in front so instance doesnt collide with other default stacks instance_name = [name, @instance].compact.join('.') else instance_name = name end [type_dir, instance_name].compact.join('/') end |
#cache_dir ⇒ Object
Full path with build_dir
99 100 101 102 103 |
# File 'lib/terraspace/mod.rb', line 99 def cache_dir pattern = Terraspace.config.build.cache_dir # IE: :CACHE_ROOT/:REGION/:ENV/:BUILD_DIR = Terraspace::Compiler::Expander.autodetect(self) .expansion(pattern) end |
#check_exist! ⇒ Object
32 33 34 35 36 37 38 39 |
# File 'lib/terraspace/mod.rb', line 32 def check_exist! Terraspace.check_project! return if root pretty_paths = paths.map { |p| Terraspace::Util.pretty_path(p) } logger.error "ERROR: Unable to find #{@name.color(:green)} module. Searched paths: #{pretty_paths}" ENV['TS_TEST'] ? raise : exit(1) end |
#placeholder(name) ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/terraspace/mod.rb', line 19 def placeholder(name) if name == "placeholder" Terraspace::CLI::Build::Placeholder.new(@options).find_mod else name end end |
#possible_fake_root ⇒ Object
If the app/stacks/NAME has been removed in source code but stack still exist in the cloud. allow user to delete by materializing an empty stack with the backend.tf Note this does not seem to work for Terraform Cloud as terraform init doesnt seem to download the plugins required. SIt only works for s3, azurerm, and gcs backends. On TFC, you can delete the stack via the GUI though.
down - so user can delete stacks w/o needing to create an empty app/stacks/demo folder
null - for the terraspace summary command when there are zero stacks.
Also useful for terraspace cloud list_workspaces
71 72 73 74 75 |
# File 'lib/terraspace/mod.rb', line 71 def possible_fake_root if @options[:command] == "down" "#{Terraspace.root}/app/stacks/#{@name}" # fake stack root end end |
#root ⇒ Object
52 53 54 55 56 57 58 59 |
# File 'lib/terraspace/mod.rb', line 52 def root root = paths.find { |p| File.exist?(p) } if root.nil? possible_fake_root else root end end |
#root_module? ⇒ Boolean
28 29 30 |
# File 'lib/terraspace/mod.rb', line 28 def root_module? @root_module end |
#to_info ⇒ Object
41 42 43 44 45 46 47 48 49 50 |
# File 'lib/terraspace/mod.rb', line 41 def to_info { build_dir: build_dir, cache_dir: Terraspace::Util.pretty_path(cache_dir), name: name, root: Terraspace::Util.pretty_path(root), type: type, type_dir: type_dir, } end |
#type ⇒ Object
106 107 108 |
# File 'lib/terraspace/mod.rb', line 106 def type root.include?("/stacks/") ? "stack" : "module" end |
#type_dir ⇒ Object
110 111 112 |
# File 'lib/terraspace/mod.rb', line 110 def type_dir type.pluralize end |