✓ Solved

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:

  1. Ansible playbook to build Image
  2. Terraform spins up n servers (3 separate images)
  3. Terraform templates an Ansible inventory file
  4. 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.

1 Reply

✓ 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:

How to use the Linode Ansible Module to Deploy Linodes

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:

Terraform: linode_instance

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:

Ansible Community

Terraform Community

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct