Class: Stackup::RakeTasks

Inherits:
Rake::TaskLib
  • Object
show all
Defined in:
lib/stackup/rake_tasks.rb

Overview

Declare Rake tasks for managing a stack.

Defined Under Namespace

Classes: DataOption, DataOptionArray, DataOptionFile, DataOptionHash

Constant Summary collapse

STACKUP_CLI =

path to the “stackup” executable

File.expand_path("../../bin/stackup", __dir__)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, template = nil) {|_self| ... } ⇒ RakeTasks

Returns a new instance of RakeTasks.

Yields:

  • (_self)

Yield Parameters:

Raises:

  • (ArgumentError)


21
22
23
24
25
26
27
28
29
30
# File 'lib/stackup/rake_tasks.rb', line 21

def initialize(name, template = nil)
  @name = name
  @stack = name
  @template = template
  yield self if block_given?
  raise ArgumentError, "no name provided" unless @name
  raise ArgumentError, "no template provided" unless @template

  define
end

Instance Attribute Details

#capabilitiesObject

Returns the value of attribute capabilities.



17
18
19
# File 'lib/stackup/rake_tasks.rb', line 17

def capabilities
  @capabilities
end

#nameObject

Returns the value of attribute name.



12
13
14
# File 'lib/stackup/rake_tasks.rb', line 12

def name
  @name
end

#parametersObject

Returns the value of attribute parameters.



15
16
17
# File 'lib/stackup/rake_tasks.rb', line 15

def parameters
  @parameters
end

#stackObject

Returns the value of attribute stack.



13
14
15
# File 'lib/stackup/rake_tasks.rb', line 13

def stack
  @stack
end

#tagsObject

Returns the value of attribute tags.



16
17
18
# File 'lib/stackup/rake_tasks.rb', line 16

def tags
  @tags
end

#templateObject

Returns the value of attribute template.



14
15
16
# File 'lib/stackup/rake_tasks.rb', line 14

def template
  @template
end

Instance Method Details

#defineObject



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/stackup/rake_tasks.rb', line 39

def define
  namespace(name) do

    data_options = []
    data_options << DataOption.for("--template", template)
    data_options << DataOption.for("--parameters", parameters) if parameters
    data_options << DataOption.for("--tags", tags) if tags

    desc "Update #{stack} stack"
    task "up" => data_options.grep(DataOptionFile).map(&:argument) do
      data_options << DataOption.for("--capability", capabilities) if capabilities
      stackup "up", *data_options.map(&:to_a).flatten
    end

    desc "Cancel update of #{stack} stack"
    task "cancel" do
      stackup "cancel-update"
    end

    desc "Show pending changes to #{stack} stack"
    task "diff" => data_options.grep(DataOptionFile).map(&:argument) do
      stackup "diff", *data_options.map(&:to_a).flatten
    end

    desc "Show #{stack} stack outputs and resources"
    task "inspect" do
      stackup "inspect"
    end

    desc "Show #{stack} stack outputs only"
    task "outputs" do
      stackup "outputs"
    end

    desc "Delete #{stack} stack"
    task "down" do
      stackup "down"
    end

  end
end

#stackup(*rest) ⇒ Object



35
36
37
# File 'lib/stackup/rake_tasks.rb', line 35

def stackup(*rest)
  sh STACKUP_CLI, "-Y", stack, *rest
end