I am using upcloud provider plugin and terraform 0.12.7 to create new instance of server. Unfortunately plugin is off the main TF site, in https://github.com/UpCloudLtd/terraform-provider-upcloud so it has to be installed using go language, but this part went fine.
provider "upcloud" {
# Your UpCloud credentials are read from the environment variables
# export UPCLOUD_USERNAME="Username for Upcloud API user"
# export UPCLOUD_PASSWORD="Password for Upcloud API user"
}
resource "upcloud_server" "test" {
# System hostname
hostname = "test.example.com"
# Availability zone
zone = "de-fra1"
# Number of CPUs and memory in MB
cpu = "4"
mem = "8192"
storage_devices {
# OS root disk size
size = "20"
action = "clone"
# Template Ubuntu 18.04
storage = "01000000-0000-4000-8000-000030080200"
tier = "maxiops"
}
# Include at least one public SSH key
login {
user = "root"
keys = [
# File module reads file as-is including trailing linefeed that breaks during terraform apply
"${replace(file("${var.ssh_pubkey}"), "\n", "")}"
]
}
# Configuring connection details
connection {
host = "${self.ipv4_address}"
type = "ssh"
user = "root"
private_key = "${file("${var.ssh_privkey}")}"
}
# Remotely executing a command on the server
provisioner "remote-exec" {
inline = [
"echo 'Hello world!'"
]
}
}
output "server_ip" {
value = "${upcloud_server.test.ipv4_address}"
}
And it creates the resource successfully. Now I change resource name to "test5" (also hostname and other hardcoded values) run terraform plan, and then it tells me that it want to destroy "test" resource even though it has it defined in tf state file and I did not request to delete it. I tried with defining terraform backend "local", keep a workspace persistent at all times, but it did not change a thing. What I am doing wrong? It works the same way if I use OS template or a snapshot volume ID.
Also is there a way to parametrize this resource name (or in output section, self is not working in here), so I don't have to run sed command to keep the names consistent? Other variables may be adjusted in terraform plan or apply - not a problem. Thanks in advance for the response