How to rebuild an existing linode with Terraform?

Is it possible to tell terraform to re-build an existing linode? I have a linode labeled as web1 that's up and running. But I want rebuild it with a fresh copy of centos8. I made this tf file

provider "linode" {
  token = "******"
}

resource "linode_instance" "web1" {
        image = "linode/centos8"
        label = "web1"
        group = "Terraform"
        region = "ca-central"
        type = "g6-nanode-1"
        root_pass = "*****"
}

But when I do a terraform apply, the system complains that web1 already exists. How do I tell terraform and linode to rebuild this web1 linode?

1 Reply

Linode Staff

Hey @evermight - I don't have a huge amount of experience with Terraform, but I did a little digging around on this.

Essentially, the reason you're getting an error is because Terraform thinks you're trying to provision a new instance with the name of an instance that already exists, in this case web1. In the config you shared, the label you're specifying is bumping into your preexisting web1 server.

In my searching, I came across a Stack Overflow forum where someone was trying to do something similar on AWS: Can i update an existing ec2 instance with terraform.

It sounds like you aren't able rebuild or update an instance that's already up and running, but you might be able to achieve what you're looking to do by utilizing the import function of the provider. From the forum:

…to use this, you'll want to define a resource in your Terraform configuration, map up everything how you want, and then import that resource.

After importing, then you should be able to manage that new resource.

In case you haven't seen them yet, I'm including links to the documentation on our Terraform provider:

From Terraform: Linode Provider

From our docs and guides:

Use Terraform to Provision Linode Environments

A Beginner's Guide to Terraform

Lastly, a non-Terraform route you can go here is to deploy from an Image or Snapshot of your web1 Linode via the Cloud Manager. Linode Images are really designed to be a scaffold for deployment purposes and might be the way to go depending on what your goal is.

Again, I'm by no means an expert on Terraform, but I hope this helps!

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