I want to write the endpoint details to a file and tried the following code after updating chef-provisioning aws-gem
file ‘opt/rds’ do
while rdsinstance.aws_object.endpoint == nil do
puts "endpoint has not created"
sleep(5)
end
content lazy {rdsinstance.aws_object.endpoint }
end
then I am getting ERROR: undefined method `endpoint’ for nil:NilClass if I revoke the while loop it is writing nil content to the file.
file ‘/tmp/sgid’ do
Customer = Struct.new(:name,:port)
Customer=rdsinstance.aws_object.endpoint
sample=“check"
while (Customer[“address”].to_s)+sample == sample do
sleep(10)
puts “rds endpoint has not created"
end
content lazy {rdsinstance.aws_object.endpoint.to_s+”\t”+Customer[“address”].to_s+“welcome” }
end
but is also resulted in the same error. But after the rds endpoint creation it is able to provide the output.
You need to use lazy everywhere you use rdsinstance, as it is only non-nil during the converge phase, after whatever code runs that assigns the RDS instance object to the rdsinstance variable. You are using it during compilation by omitting lazy. The chef-provisioning-aws README talks about this.
file ‘/tmp/sgid’ do
lazy {
Customer = Struct.new(:name,:port)
Customer=rdsinstance.aws_object.endpoint
content lazy {rdsinstance.aws_object.endpoint.to_s+"\t"+Customer[“address”].to_s+“welcome” }
}
end
file ‘/tmp/sgid’ do
content lazy {rdsinstance.aws_object.endpoint }
end
But the above is returning null. My main concern here is that after the execution of the resource it will create an object but it won’t create endpoint immediately so it is returning null. So do we have any other option to get the endpoint. If possible could you please share me a snippet of code. It is able to provide the details only after the endpoint creation which is not working with lazy
To be clear lazy is not waiting up to endpoint creation
You also need to busy wait until rdsinstance.aws_object.endpoint is non-nil, even when using lazy. I do this in a separate ruby_block, after the aws_rds_instance invocation.
$aws_rds_instance = aws_rds_instance "my_db" do
# Attributes go here
end
ruby_block "update RDS endpoint" do
block do
if $aws_rds_instance
tries = 60
while $aws_rds_instance.aws_object.nil? or $aws_rds_instance.aws_object.endpoint.nil? or $aws_rds_instance.aws_object.endpoint.address.nil?
Chef::Log.warn "Waiting for RDS instance to come up"
sleep 10
tries -= 1
raise "RDS instance did not come up on time" if tries < 0
end
endpoint = $aws_rds_instance.aws_object.endpoint
Chef::Log.warn "RDS endpoint address=#{endpoint.address}"
end
end
action :run
end
Could you please help me specifying a particular security group to rds I have tried specifying them in additional_options it is not giving me any error but assigning default security group.