How do I clone a linode via terraform?

Hi,

I've successful create an instance with an debian image using terrfrm, but I need to clone my instance using terraform. how do I do that?

resource "linode_instance" "web" {
count = 1
# image = "linode/debian10"
linode_id = 1234 #I use this but getting an error (An argument named "linode_id" is not expected here.)
label = "linode instance"
region = var.region
type = var.size
private_ip = true
authorized_keys = [data.linode_sshkey.first.ssh_key]
group = "tf"
tags = [ "tf" ]
provisioner "remote-exec" {
inline = ["sudo apt update", "sudo apt install python3 -y", "echo Done!"]
connection {
host = linode_instance.web[0].ip_address
type = "ssh"
user = "root"
private_key = file(var.pvt_key)
}
}

1 Reply

If your use case is to eventually deploy "clones" of your particular Linode, you'll most likely want to use Packer to build/provision an Image and then deploy the Image with Terraform after-the-fact:

  1. Configure and provision your desired Linode Image with Packer. This will result in an Image ID being created.
  2. Using the Image ID + Terraform, deploy however many instances of that Image you'd like.

Here's Terraform's documentation on Images: Data Source: linode_image

And for reference, Terraform's documentation on Linode's provider: Linode Provider

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