Sha256: 95060fa040134d19ea14a91e53be2bfef60ad6c05702591aa5c75f6a1632700f

Contents?: true

Size: 1.92 KB

Versions: 67

Compression:

Stored size: 1.92 KB

Contents

# Convection Stacks
**NOTE**: Examples in this file can be found in `example/stacks`.

### Defining a stack
Defining a stack is as simple as a few lines of Ruby:

```ruby
# templates/vpc.rb
require 'convection'

module Templates
  VPC = Convection.template do
    description 'EC2 VPC Test Template'

    ec2_vpc 'TargetVPC' do
      network '10.10.10.0/23'
    end
  end
end
```

### Using a defined stack
```ruby
# Cloudfile
require_relative './templates/vpc.rb'

user = ENV['USER'] || 'anon'
name "#{user}-demo-cloud"
region 'us-east-1'

stack 'vpc', Templates::VPC
```

Once evaluated by Convection stacks will be represented as CloudFormation JSON.

### Defining a task to execute on a stack
A stack has the following life-cycle phases:

1. Before creation (`before_create_task`)
2. After creation (`after_create_task`)
3. Before being updated (`before_update_task`)
4. After being updated (`after_update_task`)
5. Before deletion (`before_delete_task`)
6. After deletion (`after_delete_task`)

To define tasks on a stack (using the `VPC` stack defined above for example):

```ruby
# tasks/lookup_vpc_task.rb
module Tasks
  class LookupVpcTask
    # REQUIRED: Convection expects tasks to respond to #call.
    def call(stack)
      @vpc_id = stack.get('vpc', 'id')
      @result = vpc_found?
    end

    # REQUIRED: Convection expects tasks to respond to #success?.
    def success?
      @result
    end

    # OPTIONAL: Convection emits the task as `task.to_s` in certain log messages.
    def to_s
      return 'VPC lookup' unless @vpc_id

      "VPC lookup of #{@vpc_id.inspect}"
    end

    private

    def vpc_found?
      true # XXX: This could be a call to the aws-sdk APIs.
    end
  end
end
```

You would then change your Cloudfile to give the optional configuration block to the stack declaration:
```ruby
# Cloudfile
stack 'vpc', Templates::VPC do
  after_create_task Tasks::LookupVpcTask.new
  after_update_task Tasks::LookupVpcTask.new
end
```

Version data entries

67 entries across 67 versions & 1 rubygems

Version Path
convection-2.2.12 docs/stacks.md
convection-2.2.11 docs/stacks.md
convection-2.2.10 docs/stacks.md
convection-2.2.9 docs/stacks.md
convection-2.2.8 docs/stacks.md
convection-2.2.7 docs/stacks.md
convection-2.2.6 docs/stacks.md
convection-2.2.5 docs/stacks.md
convection-2.2.4 docs/stacks.md
convection-2.2.3 docs/stacks.md
convection-2.2.2 docs/stacks.md
convection-2.2.1 docs/stacks.md
convection-2.2.0 docs/stacks.md
convection-2.1.2 docs/stacks.md
convection-2.1.1 docs/stacks.md
convection-2.1.0 docs/stacks.md
convection-2.0.0 docs/stacks.md
convection-1.1.7 docs/stacks.md
convection-1.1.5 docs/stacks.md
convection-1.1.4 docs/stacks.md