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:
- Configure and provision your desired Linode Image with Packer. This will result in an Image ID being created.
- 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