Class: TerraspaceBundler::Example

Inherits:
TB::CLI::Base
  • Object
show all
Defined in:
lib/terraspace_bundler/example.rb

Instance Method Summary collapse

Instance Method Details

#check_mod!Object



27
28
29
30
31
32
# File 'lib/terraspace_bundler/example.rb', line 27

def check_mod!
  unless mod
    logger.error "ERROR: mod #{@options[:mod]} not found in Terrafile.lock".color(:red)
    exit 1
  end
end

#modObject



23
24
25
# File 'lib/terraspace_bundler/example.rb', line 23

def mod
  lockfile.mods.find { |mod| mod.name == @options[:mod] }
end

#runObject



3
4
5
6
7
8
# File 'lib/terraspace_bundler/example.rb', line 3

def run
  check_mod!
  stack = Exporter::Stacks::Stack.new(mod, stack_options)
  stack.export
  logger.info "Example from vendor/modules/#{@options[:mod]}/examples/#{@src} imported to #{@dest}/#{@name}"
end

#stack_optionsObject



10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/terraspace_bundler/example.rb', line 10

def stack_options
  @name = @options[:name] || @options[:example]
  @purge = @options[:purge].nil? ? true : @options[:purge]
  @dest = @options[:dest] || "app/stacks"
  @src = @options[:example]
  {
    name: @name,
    src: @src,
    dest: @dest,
    purge: @purge,
  }
end