Last active
June 21, 2019 14:00
-
-
Save miry/bf52ed5507b758a6d27762edea303992 to your computer and use it in GitHub Desktop.
Change ubuntu hostname with Terraform. `terraform apply -target=null_resource.set-hostname`
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
variable "server_ip" { | |
default = "10.0.0.2" | |
} | |
variable "server_hostname" { | |
default = "node01" | |
} | |
# Ubuntu reference for hostnamectl: http://manpages.ubuntu.com/manpages/trusty/man1/hostnamectl.1.html | |
resource "null_resource" "set-hostname" { | |
connection { | |
type = "ssh" | |
user = "ubuntu" | |
host = "${var.server_ip}" | |
} | |
provisioner "remote-exec" { | |
inline = [ | |
"sudo hostnamectl set-hostname ${var.server_hostname}", | |
"echo '127.0.0.1 ${var.server_hostname}' | sudo tee -a /etc/hosts", | |
"sudo reboot" | |
] | |
} | |
} |
How to change hostname if security group limit IPs that can connect to instance?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I followed the same but it is not working
Code:
resource "null_resource" "setup-httpd" {
type = "ssh"
}
provisioner "remote-exec" {
}
}