diff --git a/terraform/modules/vsphere-vm/files/default-cloud-config.yml.tftpl b/terraform/modules/vsphere-vm/files/default-cloud-config.yml.tftpl index 95afe6f..05a17af 100644 --- a/terraform/modules/vsphere-vm/files/default-cloud-config.yml.tftpl +++ b/terraform/modules/vsphere-vm/files/default-cloud-config.yml.tftpl @@ -1,6 +1,8 @@ #cloud-config +hostname: ${hostname} fqdn: ${fqdn} +prefer_fqdn_over_hostname: true ssh_pwauth: false diff --git a/terraform/modules/vsphere-vm/version b/terraform/modules/vsphere-vm/version index 7bcd0e3..6812f81 100644 --- a/terraform/modules/vsphere-vm/version +++ b/terraform/modules/vsphere-vm/version @@ -1 +1 @@ -0.0.2 \ No newline at end of file +0.0.3 \ No newline at end of file diff --git a/terraform/modules/vsphere-vm/vm.tf b/terraform/modules/vsphere-vm/vm.tf index 430e590..2ffbcac 100644 --- a/terraform/modules/vsphere-vm/vm.tf +++ b/terraform/modules/vsphere-vm/vm.tf @@ -6,12 +6,15 @@ resource "random_password" "vm_root_user" { } locals { + hostname = split(".", var.fqdn)[0] + # Fallback to a random generated password if the user didn't provide one root_password = coalesce(var.root_password, random_password.vm_root_user.result) # User data rendered using the Terraform provider produce an invalid configuration # See https://github.com/hashicorp/terraform-provider-cloudinit/issues/165 default_user_data = templatefile("${path.module}/files/default-cloud-config.yml.tftpl", { + hostname: local.hostname fqdn : var.fqdn root_password : local.root_password authorized_key : var.vm_authorized_key