opentelekomcloud / terraform-provider-opentelekomcloud

Terraform OpenTelekomCloud provider
https://registry.terraform.io/providers/opentelekomcloud/opentelekomcloud/latest
Mozilla Public License 2.0
84 stars 76 forks source link

compute_instance_v2: Make display name and hostname separately defineable and add description field. #2551

Open dschemp opened 3 weeks ago

dschemp commented 3 weeks ago

We have a use-case in which we want to set the systems hostname differently (FQDN) as is it shown in the management UI (without any domain). For now I have not seen any way to change the hostname besides changing the VMs name. And: as it seems the description field of the ECS cannot be set via the compute_instance_v2 resource but is set automatically (at least initially) to the VMs name.

We've tried setting it via the metadata variable and its propagated into the VM, but not applied and, by the looks of cloud init, set at the wrong spot for it to work.

resource "opentelekomcloud_compute_instance_v2" "vm" {
  name = "vm1"
  [...]
  metadata = {
    local-hostname = "vm1.example.org"
    hostname = "vm1.example.org"
  }
  [...]
}
anton-sidelnikov commented 3 weeks ago

Hi @dschemp, You can do it by passing user_data with cloud-init file:

resource "opentelekomcloud_compute_instance_v2" "my_server" {
  name              = "my-server"
  image_name        = "Standard_Debian_11_latest"
  availability_zone = "eu-de-01"
  flavor_id         = "s3.medium.1"
  key_pair          = "terraform-as"
  security_groups   = ["default"]

  user_data = file("cloud-init.yml")

  network {
    uuid = data.opentelekomcloud_vpc_subnet_v1.shared_subnet.network_id
  }
}

cloud-init.yml:

#cloud-config
hostname: new-hostname
fqdn: new-hostname.example.com
manage_etc_hosts: true
anton-sidelnikov commented 3 weeks ago

You can refer on openstack documentation in case of openstack API: https://registry.terraform.io/providers/terraform-provider-openstack/openstack/latest/docs/resources/compute_instance_v2#instance-with-user-data-cloud-init

dschemp commented 3 weeks ago

Ah, didn't know that. We thought you could only set the hostname (in a cloud-init way, and by that I don't mean runcmd or bootcmd) via the instances metadata (which we dont control) and not via the userdata. Great.

Is there any way to set the description of the ECS VM with TF?