rancher / terraform-provider-rancher2

Terraform Rancher2 provider
https://www.terraform.io/docs/providers/rancher2/
Mozilla Public License 2.0
255 stars 220 forks source link

Cannot set OS Image for Node Template on Hetzner Cloud #751

Open talex-de opened 2 years ago

talex-de commented 2 years ago

Hi there, I run into an issue with the image field when trying to setup a node template in Rancherv2.5.9 using Terraform. It looks like the value for the operation system image is not being set correctly for my node template by the TF provider.

TF code looks like this:

resource "rancher2_node_template" "worker" {
  name = "hetzner-worker"
  driver_id = rancher2_node_driver.hetzner.id

  hetzner_config {
    api_token = var.hcloud_token
    image = "ubuntu-20.04"
    server_location = var.rancher2_node_template_server_location
    server_type = var.rancher2_node_template_server_type_worker
    networks = data.hcloud_network.rancher.id
    use_private_network = true
  }
}

When viewing this node pool in the Rancher web UI all fields are set correctly, excepted the image field which shows "Debian 9" in the UI selector.

Using this node template for cluster creation causes an error and Docker cannot be installed on the nodes. Although some message before says that an Ubuntu system was recognized and the VM seems to get installed with my selected Ubuntu image.

After editing the node template manually in the UI and setting image to "Ubuntu 20.04", I get this error:

Error setting machine configuration from flags provided: --hetzner-image and --hetzner-image-id are mutually exclusive

So it looks like there's no way to fix this corrupted node template using the Rancher UI.

If I create a new node template manually using the Rancher UI this new template works fine for cluster creation. Therefore the node driver for Hetzner seems to work as expected, also installed using the TF provider.

talex-de commented 2 years ago

Same for TF provider rancher/rancher2,v1.20.0 and Rancher v2.6 – the image is not being set correctly. Therefore the node installation fails due to an error during Docker installation.

ulptsascora commented 2 years ago

Same problem. Provider version 1.20.1 and Rancher v2.5.9.

Ragnored commented 2 years ago

I found that the wrong ImageId is being generated. For example, the ImageId for Ubuntu 20.04 should be "15512617". But imageId created for any image always "0". This can be seen in the API View for Node Templates.

ulptsascora commented 2 years ago

I also found out that it is probably a problem with the nodetemplate itself. I created manually a nodetemplate and looked in the API (v3/nodetemplates) for the Json data because as workaround I create the templates manually with curl. I found out, if I create a template with ubuntu 20.04 then the ImageID is correct (I checked the id over the Hetzner API) but the Image name is ubuntu 18.04! So now my Json files have all the Image name 18.04 but the ImageID of the ubuntu 20.04 and it works... I'm not sure where the problem is but I think with that information someone could figure it out.

talex-de commented 2 years ago

I tried different OS Images, given by name and ID. The TF provider failed in all cases for me. Always ending up with a corrupted Node Template.

If someone can give me a hint where to start searching within this TF providers code base for this issue I'm willing to hunt this down :) I'm a Golang developer but didn't have a try with TF providers yet.

Ragnored commented 2 years ago

Workaround:

In rancher2/schema_node_template_hetzner.go file Add to type hetznerConfig struct

ImageID string `json:" imageId, omitempty "yaml:" imageId, omitempty "`

And in func hetznerConfigFields () map [string] * schema.Schema

"image_id": {
 Type:        schema.TypeString,
 Optional:    true,
 Default:     "15512617",
 Description: "Hetzner Cloud server image id",
}

In rancher2/structure_node_template_hetzner.go file Add in func expandHetznercloudConfig(p []interface{}) *hetznerConfig

if v, ok := in["image_id"].(string); ok && len(v) > 0 {
 obj.ImageID = v
}

This will make it possible to set ImageId in the hetzner_config of the rancher2_node_template resource

semaforce-sean commented 2 years ago

Same problem. Provider version 1.22.2 and Rancher 2.6.3

igorfraa commented 1 year ago

still the same with the provider version 1.25.0 and rancher 2.6.8