Delayed evaluation of machine_options


#1

Hi,

I came up with this approach to delaying evaluation of machine_options
until converge (when the dynamically assigned IDs are available). Wondering
if there’s a better way. In particular, I’d really like to keep
AWS-specific logic out of my machine_setup recipe.

aws_provisioner_setup.rb:

set up the static machine options

with_machine_options :bootstrap_options => {
:key_name => ‘test1_aws’,
:instance_type => ‘t1.micro’,
:associate_public_ip_address => true
}

aws_network_setup.rb:

Creates vpc, subnet, security group

machine_setup.rb:

opts = self.current_machine_options
machine ‘mytest’ do
action :destroy
machine_options lazy {
opts[:bootstrap_options][:subnet] = data_bag_item(“aws_subnet”,
“provisioning-vpc-subnet-a”)[“subnet_id”]
opts[:bootstrap_options][:security_group_ids] =
data_bag_item(“aws_security_groups”,
“provisioning-vpc-security-group”)[“security_group_id”]
opts
}
end

Regards,
Christine Draper