diff --git a/terraform/ops-cluster-o11y/cloud-init--userdata.yml b/terraform/ops-cluster-o11y/cloud-init--userdata.yml deleted file mode 100644 index 436fa4cf..00000000 --- a/terraform/ops-cluster-o11y/cloud-init--userdata.yml +++ /dev/null @@ -1,18 +0,0 @@ -#cloud-config -users: - - name: freecodecamp - groups: sudo - shell: /bin/bash - sudo: ['ALL=(ALL) NOPASSWD:ALL'] - ssh_import_id: - - gh:camperbot - - raisedadead -runcmd: - - usermod -aG docker freecodecamp - # This sections should be the last in the list because it involves restarting the ssh service, - # which may prevent commands from running after it in certain scenarios. - - sed -i -e '/^PermitRootLogin/s/^.*$/PermitRootLogin no/' /etc/ssh/sshd_config - - sed -i -e '/^PasswordAuthentication/s/^.*$/PasswordAuthentication no/' /etc/ssh/sshd_config - - sed -i -e '$aAllowUsers freecodecamp' /etc/ssh/sshd_config - - restart ssh"} -final_message: 'Setup complete' diff --git a/terraform/ops-cluster-o11y/cloud-init--userdata.yml.tftpl b/terraform/ops-cluster-o11y/cloud-init--userdata.yml.tftpl new file mode 100644 index 00000000..3166bd77 --- /dev/null +++ b/terraform/ops-cluster-o11y/cloud-init--userdata.yml.tftpl @@ -0,0 +1,31 @@ +#cloud-config +users: + - name: freecodecamp + groups: sudo + shell: /bin/bash + sudo: ['ALL=(ALL) NOPASSWD:ALL'] + ssh_import_id: + - gh:camperbot + - raisedadead +runcmd: + - usermod -aG docker freecodecamp + # Configure sshd + - | + sed -i -e '/^PermitRootLogin/s/^.*$/PermitRootLogin no/' /etc/ssh/sshd_config + sed -i -e '/^PasswordAuthentication/s/^.*$/PasswordAuthentication no/' /etc/ssh/sshd_config + sed -i -e '/^PubkeyAuthentication/s/^.*$/PubkeyAuthentication yes/' /etc/ssh/sshd_config + sed -i -e '$aAllowUsers freecodecamp' /etc/ssh/sshd_config + # Configure hostname + - | + sed -i '/preserve_hostname: false/c\preserve_hostname: true' /etc/cloud/cloud.cfg + hostnamectl set-hostname ${tf_hostname} + echo \"${tf_hostname}\" > /etc/hostname + # + # :-----------------------: WARNING :-----------------------: + # + # This next line should be the last command in the list, + # because it involves restarting the ssh service. + # + # :-----------------------: WARNING :-----------------------: + - systemctl restart sshd +final_message: 'Setup complete' diff --git a/terraform/ops-cluster-o11y/main.tf b/terraform/ops-cluster-o11y/main.tf index 8551d8e4..af8c7b1a 100644 --- a/terraform/ops-cluster-o11y/main.tf +++ b/terraform/ops-cluster-o11y/main.tf @@ -43,7 +43,11 @@ resource "linode_instance_disk" "ops_o11y_leaders_disk__boot" { stackscript_id = data.linode_stackscripts.cloudinit_scripts.stackscripts.0.id stackscript_data = { - userdata = filebase64("${path.root}/cloud-init--userdata.yml") + userdata = base64encode( + templatefile("${path.root}/cloud-init--userdata.yml.tftpl", { + tf_hostname = "ldr-${count.index + 1}.o11y.${data.linode_domain.ops_dns_domain.domain}" + }) + ) } } @@ -78,13 +82,22 @@ resource "linode_instance_config" "ops_o11y_leaders_config" { host = linode_instance.ops_o11y_leaders[count.index].ip_address } + # All of the provisioning should be done via cloud-init. + # This is just to setup the reboot. provisioner "remote-exec" { inline = [ # Wait for cloud-init to finish. "while [ ! -f /var/lib/cloud/instance/boot-finished ]; do echo 'Waiting for cloud-init...'; sleep 1; done", - # Set the hostname. - "hostnamectl set-hostname ldr-${count.index + 1}.o11y.${data.linode_domain.ops_dns_domain.domain}", - "echo \"ldr-${count.index + 1}.o11y.${data.linode_domain.ops_dns_domain.domain}\" > /etc/hostname", + "echo Current hostname...; hostname", + "shutdown -r +1 'Terraform: Rebooting to apply hostname change in 1 min.'" + ] + } + + # This run is a hack to trigger the reboot, + # which may fail otherwise in the previous step. + provisioner "remote-exec" { + inline = [ + "uptime" ] } @@ -148,7 +161,11 @@ resource "linode_instance_disk" "ops_o11y_workers_disk__boot" { stackscript_id = data.linode_stackscripts.cloudinit_scripts.stackscripts.0.id stackscript_data = { - userdata = filebase64("${path.root}/cloud-init--userdata.yml") + userdata = base64encode( + templatefile("${path.root}/cloud-init--userdata.yml.tftpl", { + tf_hostname = "wkr-${count.index + 1}.o11y.${data.linode_domain.ops_dns_domain.domain}" + }) + ) } } @@ -183,13 +200,22 @@ resource "linode_instance_config" "ops_o11y_workers_config" { host = linode_instance.ops_o11y_workers[count.index].ip_address } + # All of the provisioning should be done via cloud-init. + # This is just to setup the reboot. provisioner "remote-exec" { inline = [ # Wait for cloud-init to finish. "while [ ! -f /var/lib/cloud/instance/boot-finished ]; do echo 'Waiting for cloud-init...'; sleep 1; done", - # Set the hostname. - "hostnamectl set-hostname wkr-${count.index + 1}.o11y.${data.linode_domain.ops_dns_domain.domain}", - "echo \"wkr-${count.index + 1}.o11y.${data.linode_domain.ops_dns_domain.domain}\" > /etc/hostname", + "echo Current hostname...; hostname", + "shutdown -r +1 'Terraform: Rebooting to apply hostname change in 1 min.'" + ] + } + + # This run is a hack to trigger the reboot, + # which may fail otherwise in the previous step. + provisioner "remote-exec" { + inline = [ + "uptime" ] } diff --git a/terraform/ops-test/cloud-init--userdata.yml b/terraform/ops-test/cloud-init--userdata.yml deleted file mode 100644 index 436fa4cf..00000000 --- a/terraform/ops-test/cloud-init--userdata.yml +++ /dev/null @@ -1,18 +0,0 @@ -#cloud-config -users: - - name: freecodecamp - groups: sudo - shell: /bin/bash - sudo: ['ALL=(ALL) NOPASSWD:ALL'] - ssh_import_id: - - gh:camperbot - - raisedadead -runcmd: - - usermod -aG docker freecodecamp - # This sections should be the last in the list because it involves restarting the ssh service, - # which may prevent commands from running after it in certain scenarios. - - sed -i -e '/^PermitRootLogin/s/^.*$/PermitRootLogin no/' /etc/ssh/sshd_config - - sed -i -e '/^PasswordAuthentication/s/^.*$/PasswordAuthentication no/' /etc/ssh/sshd_config - - sed -i -e '$aAllowUsers freecodecamp' /etc/ssh/sshd_config - - restart ssh"} -final_message: 'Setup complete' diff --git a/terraform/ops-test/cloud-init--userdata.yml.tftpl b/terraform/ops-test/cloud-init--userdata.yml.tftpl new file mode 100644 index 00000000..3166bd77 --- /dev/null +++ b/terraform/ops-test/cloud-init--userdata.yml.tftpl @@ -0,0 +1,31 @@ +#cloud-config +users: + - name: freecodecamp + groups: sudo + shell: /bin/bash + sudo: ['ALL=(ALL) NOPASSWD:ALL'] + ssh_import_id: + - gh:camperbot + - raisedadead +runcmd: + - usermod -aG docker freecodecamp + # Configure sshd + - | + sed -i -e '/^PermitRootLogin/s/^.*$/PermitRootLogin no/' /etc/ssh/sshd_config + sed -i -e '/^PasswordAuthentication/s/^.*$/PasswordAuthentication no/' /etc/ssh/sshd_config + sed -i -e '/^PubkeyAuthentication/s/^.*$/PubkeyAuthentication yes/' /etc/ssh/sshd_config + sed -i -e '$aAllowUsers freecodecamp' /etc/ssh/sshd_config + # Configure hostname + - | + sed -i '/preserve_hostname: false/c\preserve_hostname: true' /etc/cloud/cloud.cfg + hostnamectl set-hostname ${tf_hostname} + echo \"${tf_hostname}\" > /etc/hostname + # + # :-----------------------: WARNING :-----------------------: + # + # This next line should be the last command in the list, + # because it involves restarting the ssh service. + # + # :-----------------------: WARNING :-----------------------: + - systemctl restart sshd +final_message: 'Setup complete' diff --git a/terraform/ops-test/main.tf b/terraform/ops-test/main.tf index 1c529faf..44008b07 100644 --- a/terraform/ops-test/main.tf +++ b/terraform/ops-test/main.tf @@ -39,7 +39,11 @@ resource "linode_instance_disk" "ops_test_disk__boot" { stackscript_id = data.linode_stackscripts.cloudinit_scripts.stackscripts.0.id stackscript_data = { - userdata = filebase64("${path.root}/cloud-init--userdata.yml") + userdata = base64encode( + templatefile("${path.root}/cloud-init--userdata.yml.tftpl", { + tf_hostname = "test.${data.linode_domain.ops_dns_domain.domain}" + }) + ) } } @@ -73,13 +77,22 @@ resource "linode_instance_config" "ops_test_config" { host = linode_instance.ops_test.ip_address } + # All of the provisioning should be done via cloud-init. + # This is just to setup the reboot. provisioner "remote-exec" { inline = [ # Wait for cloud-init to finish. "while [ ! -f /var/lib/cloud/instance/boot-finished ]; do echo 'Waiting for cloud-init...'; sleep 1; done", - # Set the hostname. - "hostnamectl set-hostname test.${data.linode_domain.ops_dns_domain.domain}", - "echo \"test.${data.linode_domain.ops_dns_domain.domain}\" > /etc/hostname", + "echo Current hostname...; hostname", + "shutdown -r +1 'Terraform: Rebooting to apply hostname change in 1 min.'" + ] + } + + # This run is a hack to trigger the reboot, + # which may fail otherwise in the previous step. + provisioner "remote-exec" { + inline = [ + "uptime" ] } diff --git a/terraform/prd-cluster-publish/cloud-init--userdata.yml b/terraform/prd-cluster-publish/cloud-init--userdata.yml deleted file mode 100644 index 436fa4cf..00000000 --- a/terraform/prd-cluster-publish/cloud-init--userdata.yml +++ /dev/null @@ -1,18 +0,0 @@ -#cloud-config -users: - - name: freecodecamp - groups: sudo - shell: /bin/bash - sudo: ['ALL=(ALL) NOPASSWD:ALL'] - ssh_import_id: - - gh:camperbot - - raisedadead -runcmd: - - usermod -aG docker freecodecamp - # This sections should be the last in the list because it involves restarting the ssh service, - # which may prevent commands from running after it in certain scenarios. - - sed -i -e '/^PermitRootLogin/s/^.*$/PermitRootLogin no/' /etc/ssh/sshd_config - - sed -i -e '/^PasswordAuthentication/s/^.*$/PasswordAuthentication no/' /etc/ssh/sshd_config - - sed -i -e '$aAllowUsers freecodecamp' /etc/ssh/sshd_config - - restart ssh"} -final_message: 'Setup complete' diff --git a/terraform/prd-cluster-publish/cloud-init--userdata.yml.tftpl b/terraform/prd-cluster-publish/cloud-init--userdata.yml.tftpl new file mode 100644 index 00000000..3166bd77 --- /dev/null +++ b/terraform/prd-cluster-publish/cloud-init--userdata.yml.tftpl @@ -0,0 +1,31 @@ +#cloud-config +users: + - name: freecodecamp + groups: sudo + shell: /bin/bash + sudo: ['ALL=(ALL) NOPASSWD:ALL'] + ssh_import_id: + - gh:camperbot + - raisedadead +runcmd: + - usermod -aG docker freecodecamp + # Configure sshd + - | + sed -i -e '/^PermitRootLogin/s/^.*$/PermitRootLogin no/' /etc/ssh/sshd_config + sed -i -e '/^PasswordAuthentication/s/^.*$/PasswordAuthentication no/' /etc/ssh/sshd_config + sed -i -e '/^PubkeyAuthentication/s/^.*$/PubkeyAuthentication yes/' /etc/ssh/sshd_config + sed -i -e '$aAllowUsers freecodecamp' /etc/ssh/sshd_config + # Configure hostname + - | + sed -i '/preserve_hostname: false/c\preserve_hostname: true' /etc/cloud/cloud.cfg + hostnamectl set-hostname ${tf_hostname} + echo \"${tf_hostname}\" > /etc/hostname + # + # :-----------------------: WARNING :-----------------------: + # + # This next line should be the last command in the list, + # because it involves restarting the ssh service. + # + # :-----------------------: WARNING :-----------------------: + - systemctl restart sshd +final_message: 'Setup complete' diff --git a/terraform/prd-cluster-publish/main.tf b/terraform/prd-cluster-publish/main.tf index aefd8dcc..489af07d 100644 --- a/terraform/prd-cluster-publish/main.tf +++ b/terraform/prd-cluster-publish/main.tf @@ -43,7 +43,11 @@ resource "linode_instance_disk" "prd_publish_leaders_disk__boot" { stackscript_id = data.linode_stackscripts.cloudinit_scripts.stackscripts.0.id stackscript_data = { - userdata = filebase64("${path.root}/cloud-init--userdata.yml") + userdata = base64encode( + templatefile("${path.root}/cloud-init--userdata.yml.tftpl", { + tf_hostname = "ldr-${count.index + 1}.publish.prd.${data.linode_domain.ops_dns_domain.domain}" + }) + ) } } @@ -78,13 +82,22 @@ resource "linode_instance_config" "prd_publish_leaders_config" { host = linode_instance.prd_publish_leaders[count.index].ip_address } + # All of the provisioning should be done via cloud-init. + # This is just to setup the reboot. provisioner "remote-exec" { inline = [ # Wait for cloud-init to finish. "while [ ! -f /var/lib/cloud/instance/boot-finished ]; do echo 'Waiting for cloud-init...'; sleep 1; done", - # Set the hostname. - "hostnamectl set-hostname ldr-${count.index + 1}.publish.prd.${data.linode_domain.ops_dns_domain.domain}", - "echo \"ldr-${count.index + 1}.publish.prd.${data.linode_domain.ops_dns_domain.domain}\" > /etc/hostname", + "echo Current hostname...; hostname", + "shutdown -r +1 'Terraform: Rebooting to apply hostname change in 1 min.'" + ] + } + + # This run is a hack to trigger the reboot, + # which may fail otherwise in the previous step. + provisioner "remote-exec" { + inline = [ + "uptime" ] } @@ -148,7 +161,11 @@ resource "linode_instance_disk" "prd_publish_workers_disk__boot" { stackscript_id = data.linode_stackscripts.cloudinit_scripts.stackscripts.0.id stackscript_data = { - userdata = filebase64("${path.root}/cloud-init--userdata.yml") + userdata = base64encode( + templatefile("${path.root}/cloud-init--userdata.yml.tftpl", { + tf_hostname = "wkr-${count.index + 1}.publish.prd.${data.linode_domain.ops_dns_domain.domain}" + }) + ) } } @@ -183,13 +200,22 @@ resource "linode_instance_config" "prd_publish_workers_config" { host = linode_instance.prd_publish_workers[count.index].ip_address } + # All of the provisioning should be done via cloud-init. + # This is just to setup the reboot. provisioner "remote-exec" { inline = [ # Wait for cloud-init to finish. "while [ ! -f /var/lib/cloud/instance/boot-finished ]; do echo 'Waiting for cloud-init...'; sleep 1; done", - # Set the hostname. - "hostnamectl set-hostname wkr-${count.index + 1}.publish.prd.${data.linode_domain.ops_dns_domain.domain}", - "echo \"wkr-${count.index + 1}.publish.prd.${data.linode_domain.ops_dns_domain.domain}\" > /etc/hostname", + "echo Current hostname...; hostname", + "shutdown -r +1 'Terraform: Rebooting to apply hostname change in 1 min.'" + ] + } + + # This run is a hack to trigger the reboot, + # which may fail otherwise in the previous step. + provisioner "remote-exec" { + inline = [ + "uptime" ] } diff --git a/terraform/stg-cluster-oldeworld/cloud-init--userdata.yml b/terraform/stg-cluster-oldeworld/cloud-init--userdata.yml deleted file mode 100644 index 436fa4cf..00000000 --- a/terraform/stg-cluster-oldeworld/cloud-init--userdata.yml +++ /dev/null @@ -1,18 +0,0 @@ -#cloud-config -users: - - name: freecodecamp - groups: sudo - shell: /bin/bash - sudo: ['ALL=(ALL) NOPASSWD:ALL'] - ssh_import_id: - - gh:camperbot - - raisedadead -runcmd: - - usermod -aG docker freecodecamp - # This sections should be the last in the list because it involves restarting the ssh service, - # which may prevent commands from running after it in certain scenarios. - - sed -i -e '/^PermitRootLogin/s/^.*$/PermitRootLogin no/' /etc/ssh/sshd_config - - sed -i -e '/^PasswordAuthentication/s/^.*$/PasswordAuthentication no/' /etc/ssh/sshd_config - - sed -i -e '$aAllowUsers freecodecamp' /etc/ssh/sshd_config - - restart ssh"} -final_message: 'Setup complete' diff --git a/terraform/stg-cluster-oldeworld/cloud-init--userdata.yml.tftpl b/terraform/stg-cluster-oldeworld/cloud-init--userdata.yml.tftpl new file mode 100644 index 00000000..3166bd77 --- /dev/null +++ b/terraform/stg-cluster-oldeworld/cloud-init--userdata.yml.tftpl @@ -0,0 +1,31 @@ +#cloud-config +users: + - name: freecodecamp + groups: sudo + shell: /bin/bash + sudo: ['ALL=(ALL) NOPASSWD:ALL'] + ssh_import_id: + - gh:camperbot + - raisedadead +runcmd: + - usermod -aG docker freecodecamp + # Configure sshd + - | + sed -i -e '/^PermitRootLogin/s/^.*$/PermitRootLogin no/' /etc/ssh/sshd_config + sed -i -e '/^PasswordAuthentication/s/^.*$/PasswordAuthentication no/' /etc/ssh/sshd_config + sed -i -e '/^PubkeyAuthentication/s/^.*$/PubkeyAuthentication yes/' /etc/ssh/sshd_config + sed -i -e '$aAllowUsers freecodecamp' /etc/ssh/sshd_config + # Configure hostname + - | + sed -i '/preserve_hostname: false/c\preserve_hostname: true' /etc/cloud/cloud.cfg + hostnamectl set-hostname ${tf_hostname} + echo \"${tf_hostname}\" > /etc/hostname + # + # :-----------------------: WARNING :-----------------------: + # + # This next line should be the last command in the list, + # because it involves restarting the ssh service. + # + # :-----------------------: WARNING :-----------------------: + - systemctl restart sshd +final_message: 'Setup complete' diff --git a/terraform/stg-cluster-oldeworld/next-01-nginx.tf b/terraform/stg-cluster-oldeworld/next-01-nginx.tf index b5951a6a..b91c5f90 100644 --- a/terraform/stg-cluster-oldeworld/next-01-nginx.tf +++ b/terraform/stg-cluster-oldeworld/next-01-nginx.tf @@ -21,7 +21,11 @@ resource "linode_instance_disk" "stg_oldeworld_pxy_disk__boot" { stackscript_id = data.linode_stackscripts.cloudinit_scripts.stackscripts.0.id stackscript_data = { - userdata = filebase64("${path.root}/cloud-init--userdata.yml") + userdata = base64encode( + templatefile("${path.root}/cloud-init--userdata.yml.tftpl", { + tf_hostname = "pxy-${count.index + 1}.oldeworld.stg.${data.linode_domain.ops_dns_domain.domain}" + }) + ) } } @@ -56,13 +60,22 @@ resource "linode_instance_config" "stg_oldeworld_pxy_config" { host = linode_instance.stg_oldeworld_pxy[count.index].ip_address } + # All of the provisioning should be done via cloud-init. + # This is just to setup the reboot. provisioner "remote-exec" { inline = [ # Wait for cloud-init to finish. "while [ ! -f /var/lib/cloud/instance/boot-finished ]; do echo 'Waiting for cloud-init...'; sleep 1; done", - # Set the hostname. - "hostnamectl set-hostname pxy-${count.index + 1}.oldeworld.stg.${data.linode_domain.ops_dns_domain.domain}", - "echo \"pxy-${count.index + 1}.oldeworld.stg.${data.linode_domain.ops_dns_domain.domain}\" > /etc/hostname", + "echo Current hostname...; hostname", + "shutdown -r +1 'Terraform: Rebooting to apply hostname change in 1 min.'" + ] + } + + # This run is a hack to trigger the reboot, + # which may fail otherwise in the previous step. + provisioner "remote-exec" { + inline = [ + "uptime" ] } diff --git a/terraform/stg-cluster-oldeworld/next-11-client-eng.tf b/terraform/stg-cluster-oldeworld/next-11-client-eng.tf index 87862a00..ab31e9cc 100644 --- a/terraform/stg-cluster-oldeworld/next-11-client-eng.tf +++ b/terraform/stg-cluster-oldeworld/next-11-client-eng.tf @@ -21,7 +21,11 @@ resource "linode_instance_disk" "stg_oldeworld_clteng_disk__boot" { stackscript_id = data.linode_stackscripts.cloudinit_scripts.stackscripts.0.id stackscript_data = { - userdata = filebase64("${path.root}/cloud-init--userdata.yml") + userdata = base64encode( + templatefile("${path.root}/cloud-init--userdata.yml.tftpl", { + tf_hostname = "clteng-${count.index + 1}.oldeworld.stg.${data.linode_domain.ops_dns_domain.domain}" + }) + ) } } @@ -56,13 +60,22 @@ resource "linode_instance_config" "stg_oldeworld_clteng_config" { host = linode_instance.stg_oldeworld_clteng[count.index].ip_address } + # All of the provisioning should be done via cloud-init. + # This is just to setup the reboot. provisioner "remote-exec" { inline = [ # Wait for cloud-init to finish. "while [ ! -f /var/lib/cloud/instance/boot-finished ]; do echo 'Waiting for cloud-init...'; sleep 1; done", - # Set the hostname. - "hostnamectl set-hostname clteng-${count.index + 1}.oldeworld.stg.${data.linode_domain.ops_dns_domain.domain}", - "echo \"clteng-${count.index + 1}.oldeworld.stg.${data.linode_domain.ops_dns_domain.domain}\" > /etc/hostname", + "echo Current hostname...; hostname", + "shutdown -r +1 'Terraform: Rebooting to apply hostname change in 1 min.'" + ] + } + + # This run is a hack to trigger the reboot, + # which may fail otherwise in the previous step. + provisioner "remote-exec" { + inline = [ + "uptime" ] } diff --git a/terraform/stg-cluster-oldeworld/next-12-client-chn.tf b/terraform/stg-cluster-oldeworld/next-12-client-chn.tf index 91098575..e255ae45 100644 --- a/terraform/stg-cluster-oldeworld/next-12-client-chn.tf +++ b/terraform/stg-cluster-oldeworld/next-12-client-chn.tf @@ -21,7 +21,11 @@ resource "linode_instance_disk" "stg_oldeworld_cltchn_disk__boot" { stackscript_id = data.linode_stackscripts.cloudinit_scripts.stackscripts.0.id stackscript_data = { - userdata = filebase64("${path.root}/cloud-init--userdata.yml") + userdata = base64encode( + templatefile("${path.root}/cloud-init--userdata.yml.tftpl", { + tf_hostname = "cltchn-${count.index + 1}.oldeworld.stg.${data.linode_domain.ops_dns_domain.domain}" + }) + ) } } @@ -56,13 +60,22 @@ resource "linode_instance_config" "stg_oldeworld_cltchn_config" { host = linode_instance.stg_oldeworld_cltchn[count.index].ip_address } + # All of the provisioning should be done via cloud-init. + # This is just to setup the reboot. provisioner "remote-exec" { inline = [ # Wait for cloud-init to finish. "while [ ! -f /var/lib/cloud/instance/boot-finished ]; do echo 'Waiting for cloud-init...'; sleep 1; done", - # Set the hostname. - "hostnamectl set-hostname cltchn-${count.index + 1}.oldeworld.stg.${data.linode_domain.ops_dns_domain.domain}", - "echo \"cltchn-${count.index + 1}.oldeworld.stg.${data.linode_domain.ops_dns_domain.domain}\" > /etc/hostname", + "echo Current hostname...; hostname", + "shutdown -r +1 'Terraform: Rebooting to apply hostname change in 1 min.'" + ] + } + + # This run is a hack to trigger the reboot, + # which may fail otherwise in the previous step. + provisioner "remote-exec" { + inline = [ + "uptime" ] } diff --git a/terraform/stg-cluster-oldeworld/next-13-client-cnt.tf b/terraform/stg-cluster-oldeworld/next-13-client-cnt.tf index 5ec22f3a..60a1b934 100644 --- a/terraform/stg-cluster-oldeworld/next-13-client-cnt.tf +++ b/terraform/stg-cluster-oldeworld/next-13-client-cnt.tf @@ -21,7 +21,11 @@ resource "linode_instance_disk" "stg_oldeworld_cltcnt_disk__boot" { stackscript_id = data.linode_stackscripts.cloudinit_scripts.stackscripts.0.id stackscript_data = { - userdata = filebase64("${path.root}/cloud-init--userdata.yml") + userdata = base64encode( + templatefile("${path.root}/cloud-init--userdata.yml.tftpl", { + tf_hostname = "cltcnt-${count.index + 1}.oldeworld.stg.${data.linode_domain.ops_dns_domain.domain}" + }) + ) } } @@ -56,13 +60,22 @@ resource "linode_instance_config" "stg_oldeworld_cltcnt_config" { host = linode_instance.stg_oldeworld_cltcnt[count.index].ip_address } + # All of the provisioning should be done via cloud-init. + # This is just to setup the reboot. provisioner "remote-exec" { inline = [ # Wait for cloud-init to finish. "while [ ! -f /var/lib/cloud/instance/boot-finished ]; do echo 'Waiting for cloud-init...'; sleep 1; done", - # Set the hostname. - "hostnamectl set-hostname cltcnt-${count.index + 1}.oldeworld.stg.${data.linode_domain.ops_dns_domain.domain}", - "echo \"cltcnt-${count.index + 1}.oldeworld.stg.${data.linode_domain.ops_dns_domain.domain}\" > /etc/hostname", + "echo Current hostname...; hostname", + "shutdown -r +1 'Terraform: Rebooting to apply hostname change in 1 min.'" + ] + } + + # This run is a hack to trigger the reboot, + # which may fail otherwise in the previous step. + provisioner "remote-exec" { + inline = [ + "uptime" ] } diff --git a/terraform/stg-cluster-oldeworld/next-14-client-esp.tf b/terraform/stg-cluster-oldeworld/next-14-client-esp.tf index 15cd7462..bd6735ba 100644 --- a/terraform/stg-cluster-oldeworld/next-14-client-esp.tf +++ b/terraform/stg-cluster-oldeworld/next-14-client-esp.tf @@ -21,7 +21,11 @@ resource "linode_instance_disk" "stg_oldeworld_cltesp_disk__boot" { stackscript_id = data.linode_stackscripts.cloudinit_scripts.stackscripts.0.id stackscript_data = { - userdata = filebase64("${path.root}/cloud-init--userdata.yml") + userdata = base64encode( + templatefile("${path.root}/cloud-init--userdata.yml.tftpl", { + tf_hostname = "cltesp-${count.index + 1}.oldeworld.stg.${data.linode_domain.ops_dns_domain.domain}" + }) + ) } } @@ -56,13 +60,22 @@ resource "linode_instance_config" "stg_oldeworld_cltesp_config" { host = linode_instance.stg_oldeworld_cltesp[count.index].ip_address } + # All of the provisioning should be done via cloud-init. + # This is just to setup the reboot. provisioner "remote-exec" { inline = [ # Wait for cloud-init to finish. "while [ ! -f /var/lib/cloud/instance/boot-finished ]; do echo 'Waiting for cloud-init...'; sleep 1; done", - # Set the hostname. - "hostnamectl set-hostname cltesp-${count.index + 1}.oldeworld.stg.${data.linode_domain.ops_dns_domain.domain}", - "echo \"cltesp-${count.index + 1}.oldeworld.stg.${data.linode_domain.ops_dns_domain.domain}\" > /etc/hostname", + "echo Current hostname...; hostname", + "shutdown -r +1 'Terraform: Rebooting to apply hostname change in 1 min.'" + ] + } + + # This run is a hack to trigger the reboot, + # which may fail otherwise in the previous step. + provisioner "remote-exec" { + inline = [ + "uptime" ] } diff --git a/terraform/stg-cluster-oldeworld/next-15-client-ger.tf b/terraform/stg-cluster-oldeworld/next-15-client-ger.tf index ace95abd..881da51c 100644 --- a/terraform/stg-cluster-oldeworld/next-15-client-ger.tf +++ b/terraform/stg-cluster-oldeworld/next-15-client-ger.tf @@ -21,7 +21,11 @@ resource "linode_instance_disk" "stg_oldeworld_cltger_disk__boot" { stackscript_id = data.linode_stackscripts.cloudinit_scripts.stackscripts.0.id stackscript_data = { - userdata = filebase64("${path.root}/cloud-init--userdata.yml") + userdata = base64encode( + templatefile("${path.root}/cloud-init--userdata.yml.tftpl", { + tf_hostname = "cltger-${count.index + 1}.oldeworld.stg.${data.linode_domain.ops_dns_domain.domain}" + }) + ) } } @@ -56,13 +60,22 @@ resource "linode_instance_config" "stg_oldeworld_cltger_config" { host = linode_instance.stg_oldeworld_cltger[count.index].ip_address } + # All of the provisioning should be done via cloud-init. + # This is just to setup the reboot. provisioner "remote-exec" { inline = [ # Wait for cloud-init to finish. "while [ ! -f /var/lib/cloud/instance/boot-finished ]; do echo 'Waiting for cloud-init...'; sleep 1; done", - # Set the hostname. - "hostnamectl set-hostname cltger-${count.index + 1}.oldeworld.stg.${data.linode_domain.ops_dns_domain.domain}", - "echo \"cltger-${count.index + 1}.oldeworld.stg.${data.linode_domain.ops_dns_domain.domain}\" > /etc/hostname", + "echo Current hostname...; hostname", + "shutdown -r +1 'Terraform: Rebooting to apply hostname change in 1 min.'" + ] + } + + # This run is a hack to trigger the reboot, + # which may fail otherwise in the previous step. + provisioner "remote-exec" { + inline = [ + "uptime" ] } diff --git a/terraform/stg-cluster-oldeworld/next-16-client-ita.tf b/terraform/stg-cluster-oldeworld/next-16-client-ita.tf index 9d7baf66..b4aede53 100644 --- a/terraform/stg-cluster-oldeworld/next-16-client-ita.tf +++ b/terraform/stg-cluster-oldeworld/next-16-client-ita.tf @@ -21,7 +21,11 @@ resource "linode_instance_disk" "stg_oldeworld_cltita_disk__boot" { stackscript_id = data.linode_stackscripts.cloudinit_scripts.stackscripts.0.id stackscript_data = { - userdata = filebase64("${path.root}/cloud-init--userdata.yml") + userdata = base64encode( + templatefile("${path.root}/cloud-init--userdata.yml.tftpl", { + tf_hostname = "cltita-${count.index + 1}.oldeworld.stg.${data.linode_domain.ops_dns_domain.domain}" + }) + ) } } @@ -56,13 +60,22 @@ resource "linode_instance_config" "stg_oldeworld_cltita_config" { host = linode_instance.stg_oldeworld_cltita[count.index].ip_address } + # All of the provisioning should be done via cloud-init. + # This is just to setup the reboot. provisioner "remote-exec" { inline = [ # Wait for cloud-init to finish. "while [ ! -f /var/lib/cloud/instance/boot-finished ]; do echo 'Waiting for cloud-init...'; sleep 1; done", - # Set the hostname. - "hostnamectl set-hostname cltita-${count.index + 1}.oldeworld.stg.${data.linode_domain.ops_dns_domain.domain}", - "echo \"cltita-${count.index + 1}.oldeworld.stg.${data.linode_domain.ops_dns_domain.domain}\" > /etc/hostname", + "echo Current hostname...; hostname", + "shutdown -r +1 'Terraform: Rebooting to apply hostname change in 1 min.'" + ] + } + + # This run is a hack to trigger the reboot, + # which may fail otherwise in the previous step. + provisioner "remote-exec" { + inline = [ + "uptime" ] } diff --git a/terraform/stg-cluster-oldeworld/next-17-client-jpn.tf b/terraform/stg-cluster-oldeworld/next-17-client-jpn.tf index 569b14e1..f2ba810f 100644 --- a/terraform/stg-cluster-oldeworld/next-17-client-jpn.tf +++ b/terraform/stg-cluster-oldeworld/next-17-client-jpn.tf @@ -21,7 +21,11 @@ resource "linode_instance_disk" "stg_oldeworld_cltjpn_disk__boot" { stackscript_id = data.linode_stackscripts.cloudinit_scripts.stackscripts.0.id stackscript_data = { - userdata = filebase64("${path.root}/cloud-init--userdata.yml") + userdata = base64encode( + templatefile("${path.root}/cloud-init--userdata.yml.tftpl", { + tf_hostname = "cltjpn-${count.index + 1}.oldeworld.stg.${data.linode_domain.ops_dns_domain.domain}" + }) + ) } } @@ -56,13 +60,22 @@ resource "linode_instance_config" "stg_oldeworld_cltjpn_config" { host = linode_instance.stg_oldeworld_cltjpn[count.index].ip_address } + # All of the provisioning should be done via cloud-init. + # This is just to setup the reboot. provisioner "remote-exec" { inline = [ # Wait for cloud-init to finish. "while [ ! -f /var/lib/cloud/instance/boot-finished ]; do echo 'Waiting for cloud-init...'; sleep 1; done", - # Set the hostname. - "hostnamectl set-hostname cltjpn-${count.index + 1}.oldeworld.stg.${data.linode_domain.ops_dns_domain.domain}", - "echo \"cltjpn-${count.index + 1}.oldeworld.stg.${data.linode_domain.ops_dns_domain.domain}\" > /etc/hostname", + "echo Current hostname...; hostname", + "shutdown -r +1 'Terraform: Rebooting to apply hostname change in 1 min.'" + ] + } + + # This run is a hack to trigger the reboot, + # which may fail otherwise in the previous step. + provisioner "remote-exec" { + inline = [ + "uptime" ] } diff --git a/terraform/stg-cluster-oldeworld/next-18-client-por.tf b/terraform/stg-cluster-oldeworld/next-18-client-por.tf index f123e591..74cfe44b 100644 --- a/terraform/stg-cluster-oldeworld/next-18-client-por.tf +++ b/terraform/stg-cluster-oldeworld/next-18-client-por.tf @@ -21,7 +21,11 @@ resource "linode_instance_disk" "stg_oldeworld_cltpor_disk__boot" { stackscript_id = data.linode_stackscripts.cloudinit_scripts.stackscripts.0.id stackscript_data = { - userdata = filebase64("${path.root}/cloud-init--userdata.yml") + userdata = base64encode( + templatefile("${path.root}/cloud-init--userdata.yml.tftpl", { + tf_hostname = "cltpor-${count.index + 1}.oldeworld.stg.${data.linode_domain.ops_dns_domain.domain}" + }) + ) } } @@ -56,13 +60,22 @@ resource "linode_instance_config" "stg_oldeworld_cltpor_config" { host = linode_instance.stg_oldeworld_cltpor[count.index].ip_address } + # All of the provisioning should be done via cloud-init. + # This is just to setup the reboot. provisioner "remote-exec" { inline = [ # Wait for cloud-init to finish. "while [ ! -f /var/lib/cloud/instance/boot-finished ]; do echo 'Waiting for cloud-init...'; sleep 1; done", - # Set the hostname. - "hostnamectl set-hostname cltpor-${count.index + 1}.oldeworld.stg.${data.linode_domain.ops_dns_domain.domain}", - "echo \"cltpor-${count.index + 1}.oldeworld.stg.${data.linode_domain.ops_dns_domain.domain}\" > /etc/hostname", + "echo Current hostname...; hostname", + "shutdown -r +1 'Terraform: Rebooting to apply hostname change in 1 min.'" + ] + } + + # This run is a hack to trigger the reboot, + # which may fail otherwise in the previous step. + provisioner "remote-exec" { + inline = [ + "uptime" ] } diff --git a/terraform/stg-cluster-oldeworld/next-19-client-ukr.tf b/terraform/stg-cluster-oldeworld/next-19-client-ukr.tf index 6bd4dabc..6dd68445 100644 --- a/terraform/stg-cluster-oldeworld/next-19-client-ukr.tf +++ b/terraform/stg-cluster-oldeworld/next-19-client-ukr.tf @@ -21,7 +21,11 @@ resource "linode_instance_disk" "stg_oldeworld_cltukr_disk__boot" { stackscript_id = data.linode_stackscripts.cloudinit_scripts.stackscripts.0.id stackscript_data = { - userdata = filebase64("${path.root}/cloud-init--userdata.yml") + userdata = base64encode( + templatefile("${path.root}/cloud-init--userdata.yml.tftpl", { + tf_hostname = "cltukr-${count.index + 1}.oldeworld.stg.${data.linode_domain.ops_dns_domain.domain}" + }) + ) } } @@ -56,13 +60,22 @@ resource "linode_instance_config" "stg_oldeworld_cltukr_config" { host = linode_instance.stg_oldeworld_cltukr[count.index].ip_address } + # All of the provisioning should be done via cloud-init. + # This is just to setup the reboot. provisioner "remote-exec" { inline = [ # Wait for cloud-init to finish. "while [ ! -f /var/lib/cloud/instance/boot-finished ]; do echo 'Waiting for cloud-init...'; sleep 1; done", - # Set the hostname. - "hostnamectl set-hostname cltukr-${count.index + 1}.oldeworld.stg.${data.linode_domain.ops_dns_domain.domain}", - "echo \"cltukr-${count.index + 1}.oldeworld.stg.${data.linode_domain.ops_dns_domain.domain}\" > /etc/hostname", + "echo Current hostname...; hostname", + "shutdown -r +1 'Terraform: Rebooting to apply hostname change in 1 min.'" + ] + } + + # This run is a hack to trigger the reboot, + # which may fail otherwise in the previous step. + provisioner "remote-exec" { + inline = [ + "uptime" ] } diff --git a/terraform/stg-cluster-oldeworld/next-20-api.tf b/terraform/stg-cluster-oldeworld/next-20-api.tf index 46bc2e08..a9061bec 100644 --- a/terraform/stg-cluster-oldeworld/next-20-api.tf +++ b/terraform/stg-cluster-oldeworld/next-20-api.tf @@ -21,7 +21,11 @@ resource "linode_instance_disk" "stg_oldeworld_api_disk__boot" { stackscript_id = data.linode_stackscripts.cloudinit_scripts.stackscripts.0.id stackscript_data = { - userdata = filebase64("${path.root}/cloud-init--userdata.yml") + userdata = base64encode( + templatefile("${path.root}/cloud-init--userdata.yml.tftpl", { + tf_hostname = "api-${count.index + 1}.oldeworld.stg.${data.linode_domain.ops_dns_domain.domain}" + }) + ) } } @@ -56,13 +60,22 @@ resource "linode_instance_config" "stg_oldeworld_api_config" { host = linode_instance.stg_oldeworld_api[count.index].ip_address } + # All of the provisioning should be done via cloud-init. + # This is just to setup the reboot. provisioner "remote-exec" { inline = [ # Wait for cloud-init to finish. "while [ ! -f /var/lib/cloud/instance/boot-finished ]; do echo 'Waiting for cloud-init...'; sleep 1; done", - # Set the hostname. - "hostnamectl set-hostname api-${count.index + 1}.oldeworld.stg.${data.linode_domain.ops_dns_domain.domain}", - "echo \"api-${count.index + 1}.oldeworld.stg.${data.linode_domain.ops_dns_domain.domain}\" > /etc/hostname", + "echo Current hostname...; hostname", + "shutdown -r +1 'Terraform: Rebooting to apply hostname change in 1 min.'" + ] + } + + # This run is a hack to trigger the reboot, + # which may fail otherwise in the previous step. + provisioner "remote-exec" { + inline = [ + "uptime" ] } diff --git a/terraform/stg-cluster-oldeworld/next-50-ghost.tf b/terraform/stg-cluster-oldeworld/next-50-ghost.tf index 02f94e2c..e7c00e9c 100644 --- a/terraform/stg-cluster-oldeworld/next-50-ghost.tf +++ b/terraform/stg-cluster-oldeworld/next-50-ghost.tf @@ -19,7 +19,11 @@ resource "linode_instance_disk" "stg_oldeworld_newstst_disk__boot" { stackscript_id = data.linode_stackscripts.cloudinit_scripts.stackscripts.0.id stackscript_data = { - userdata = filebase64("${path.root}/cloud-init--userdata.yml") + userdata = base64encode( + templatefile("${path.root}/cloud-init--userdata.yml.tftpl", { + tf_hostname = "newstst-1.oldeworld.stg.${data.linode_domain.ops_dns_domain.domain}" + }) + ) } } @@ -53,13 +57,22 @@ resource "linode_instance_config" "stg_oldeworld_newstst_config" { host = linode_instance.stg_oldeworld_newstst.ip_address } + # All of the provisioning should be done via cloud-init. + # This is just to setup the reboot. provisioner "remote-exec" { inline = [ # Wait for cloud-init to finish. "while [ ! -f /var/lib/cloud/instance/boot-finished ]; do echo 'Waiting for cloud-init...'; sleep 1; done", - # Set the hostname. - "hostnamectl set-hostname newstst-1.oldeworld.stg.${data.linode_domain.ops_dns_domain.domain}", - "echo \"newstst-1.oldeworld.stg.${data.linode_domain.ops_dns_domain.domain}\" > /etc/hostname", + "echo Current hostname...; hostname", + "shutdown -r +1 'Terraform: Rebooting to apply hostname change in 1 min.'" + ] + } + + # This run is a hack to trigger the reboot, + # which may fail otherwise in the previous step. + provisioner "remote-exec" { + inline = [ + "uptime" ] }