I have a recipe for provisioning an ec2 instance that I'm trying to apply an environment to, which I run as:
chef-client -z -o 'myapp::dev_create'
The default.rb attributes file is defined as:
default['myapp_provisioner'].tap do |myapp_provisioner|
myapp_provisioner['node_name'] = 'test'
end
The myapp::dev_create recipe is defined as:
require 'chef/provisioning'
Chef::Config.chef_provisioning({
:machine_max_wait_time => 240
})
# Override environment specific configs
node.override['myapp_provisioner']['node_name'] = 'RULZ_DEV'
include_recipe 'myapp_provisioner::ec2_instance' # sets machine_options
# The line below prints "RULZ_DEV"
# as it is overridden above
puts node['myapp_provisioner']['node_name']
machine node['myapp_provisioner']['node_name'] do
chef_environment 'DEV'
admin true # run as sudo
recipe 'myapp::copy_tls_certs'
role 'reverse_proxy'
role 'app_server'
end
The Recipe myapp::copy_tls_certs is defined as:
node_name = node['myapp_provisioner']['node_name']
# The line below prints the value from default attributes "test"
puts "cert path ---------------> #{node_name}"
Updated
I had previously titled the question as Chef Environment not overriding recipe called inside a machine resource
, but I have come to realize that the issue is not related to Environments, but is only about attributes overriding and using those attributes inside a machine resource. It feels like I'm missing something quite fundamental here, any ideas?