How to Set the Hostname on a Linux Server With Terraform


If you need to set the hostname on a linux server, and you are using Terraform, then you can do the following:

Include the provisioner block and set it to remote-exec:

provisioner "remote-exec" {
  inline = ["sudo hostnamectl set-hostname friendly.example.com"]
}