Unable to get RDS end point with aws_object

I am trying to get the endpoint of the rds created but it is returning error specifying unknown method. I have tried the following

and some other

But I found unknown method error for all the above. I was wondering if someone could help me in resolving this.

rdsinstance.aws_object.endpoint should work (I wrote the patch) but only with the latest version of chef-provisioning-aws.

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"
content lazy {rdsinstance.aws_object.endpoint }

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.

I have tried the following code as well

file ‘/tmp/sgid’ do
Customer = Struct.new(:name,:port)
while (Customer[“address”].to_s)+sample == sample do
puts “rds endpoint has not created"
content lazy {rdsinstance.aws_object.endpoint.to_s+”\t”+Customer[“address”].to_s+“welcome” }

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.

I have tried lazy like the below earlier.

file ‘/tmp/sgid’ do
lazy {
Customer = Struct.new(:name,:port)
content lazy {rdsinstance.aws_object.endpoint.to_s+"\t"+Customer[“address”].to_s+“welcome” }

file ‘/tmp/sgid’ do
content lazy {rdsinstance.aws_object.endpoint }

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.

Could you please share me sample code of that

$aws_rds_instance = aws_rds_instance "my_db" do
  # Attributes go here

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
      endpoint = $aws_rds_instance.aws_object.endpoint
      Chef::Log.warn "RDS endpoint address=#{endpoint.address}"
  action :run

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.

See the end of https://github.com/chef/chef-provisioning-aws/issues/368

Thank you.