I am provisioning some resources on OpenStack cloud. For which I am using cloud-config files. Now I require to get IP before starting cloud-config. I get this IP using port resource and trying to change this in other file.(let’s say fil1.tpl)
The cloud-configs are in the form of file1.tpl format. I am replacing this variable( IP ) in this file using sed command from local-exec provisioner.
sed -i s/IP/${openstack_networking_port_v2.master-port.all_fixed_ips[0]}/g file1.tpl
The file is changed fine on my local machine, but the files used for cloud-config do not have this variable replaced.
I am not familiar with OpenStack so I apologise in advance for my ignorance.
The first thing I would suggest is to potentially look at the Terraform Template provider which will allow you to mutate template without needing to use local-exec or SED.
With a template you can pass in variables and the computed output is available as a Terraform resource. Once you have your computed template the next step is to add this to your instance. If you are using a resource like compute_instance_v2 you can assign the output of the template to the user_data parameter. The benefit of this approach is that Terraform can compute an order for creating the resources. It understands that the template needs to be computed before creating the instance.
Which OpenStack resources are you creating which require CloudConfig so I can assist further?