Set an IPv4 with a terraform provisioning step
I have an ansible playbook building an image with Packer for a few servers that all must talk to each other.
Currently, the company uses static IP's but my current understanding is that Terraform provisions an instance, and then provides an ipv4.
This creates a weird four step process:
- Ansible playbook to build Image
- Terraform spins up n servers (3 separate images)
- Terraform templates an Ansible inventory file
- Another Ansible playbook reconfigures each image with the dynamic IP's provided
I've done some searching but older posts all have dead links so the answers feel half-baked.
There does appear to be a networking resource for Terraform's Linode provider, but when I manually make a Linode, it doesn't let me choose my private IP address, because (I'm assuming) there would be some major conflicts when ppl choose the same range.
Is there a more streamlined approach to getting a collection of IP's for servers requiring a static IP setup in the provisioning or image generation stage?
PS: I am looking into making these boxes more dynamic to hopefully leverage DNS as well, but have been told that aspects of these servers require static IP's at this time.
✓ Best Answer
Hey @cwoz117. I admittedly don't have a ton of firsthand experience with Ansible/Terraform, but the steps you laid out seem to align with our Ansible documentation here:
You're also correct in that users are not able to select or provide their own private IPs. They're automatically generated when they're activated, and the addresses themselves are dependent on the data center that they're located in.
In terms of provisioning Linodes with private IPs during the generation step, it looks like you can use the
linode_instance resource with the Terraform Linode provider to do just that:
From the documentation, as long as you have the
private_ip value set as "true", it will enable private networking during the provisioning step.
Otherwise, this might be a really great question for the Ansible or Terraform forums: