ionos-cloud / terraform-provider-ionoscloud

The IonosCloud Terraform provider gives the ability to deploy and configure resources using the IonosCloud APIs.
Mozilla Public License 2.0
35 stars 24 forks source link

Error when creating server "An image template not found to use SSH keys." #72

Closed carcuevas closed 3 years ago

carcuevas commented 3 years ago

Description

When trying to create a server using a Debian 10 HDD image in the main volume it wont create it. Instead it will show the error:

ionoscloud_datacenter.datacenter1: Creating...
ionoscloud_datacenter.datacenter1: Creation complete after 1s [id=94432853-38f8-453b-90bc-bab7d48c4949]
ionoscloud_lan.public_lan: Creating...
ionoscloud_ipblock.public_ip1: Creating...
ionoscloud_ipblock.public_ip1: Creation complete after 0s [id=2895f30b-3d87-4a3a-9e65-9ad2f1518903]
ionoscloud_lan.public_lan: Creation complete after 6s [id=1]
ionoscloud_server.testserver1: Creating...
╷
│ Error: error creating server: (422 Unprocessable Entity: {
│   "httpStatus" : 422,
│   "messages" : [ {
│     "errorCode" : "100",
│     "message" : "[(root).entities.volumes.items.[0].properties.sshKeys] An image template not found to use SSH keys."
│   } ]
│ }
│ )
│ 
│   with ionoscloud_server.testserver1,
│   on main.tf line 30, in resource "ionoscloud_server" "testserver1":
│   30: resource "ionoscloud_server" "testserver1" {

Expected behavior

To create the server using the specified image and key.

Environment

Terraform version:

Terraform v1.0.3
on linux_amd64

Provider version:

+ provider registry.terraform.io/ionos-cloud/ionoscloud v5.2.6

OS:

Manjaro 21.7 AMD64

Configuration Files

main.tf

resource "ionoscloud_datacenter" "datacenter1" {
  name        = "TF Test datacenter"
  location    = "de/fra"
  description = "Test datacenter done by TF"
}

resource "ionoscloud_lan" "public_lan" {
  datacenter_id = ionoscloud_datacenter.datacenter1.id
  public        = true
}

resource "ionoscloud_ipblock" "public_ip1" {
  name     = "test-ip"
  location = ionoscloud_datacenter.datacenter1.location
  size     = 1
}

### We create the server
resource "ionoscloud_server" "testserver1" {
  name              = "test1"
  datacenter_id     = ionoscloud_datacenter.datacenter1.id
  cores             = 1
  ram               = 512
  availability_zone = "ZONE_1"
  cpu_family           =  "INTEL_SKYLAKE" 
  ssh_key_path      = [ "/path/to/mykey/.ssh/key.pub" ]
  image_name        = "30b81b5e-da21-11eb-8ba6-26668591ed56"

  volume {
    name           = "test1-root"
    size              = 5
    disk_type      = "SSD Standard"
    licence_type   = "LINUX"

  }

  nic {
    lan             = ionoscloud_lan.public_lan.id
    dhcp            = true
    ips             = ionoscloud_ipblock.public_ip1.ips
    firewall_active = true

    firewall {
      protocol         = "TCP"
      name             = "SSH"
      port_range_start = 22
      port_range_end   = 22
    }
  }
}

How to Reproduce

  1. Execute terraform apply
carcuevas commented 3 years ago

Hopefully I didn't make any mistake when trying to create the server, actually if trying with image_password instead of ssh_key_path also it won't work....

jbuchhammer commented 3 years ago

Hi @carcuevas , is it one of our public images, or is it an image that you uploaded or a snapshot?

carcuevas commented 3 years ago

Hi, actually it's a public image, standard debian 10 HDD image

carcuevas commented 3 years ago

Also I tried with a different image like this one Ubuntu-20.04-LTS-server-2021-08-02 and for different locations but the same result...

carcuevas commented 3 years ago

So nobody has the same problem??? :-/

jbuchhammer commented 3 years ago

hi @carcuevas , I did a quick test w/ one of my simple setups right now (not exactly like yours). Using an image UUID as well as using an image alias worked fine for me.

I'll try to reproduce it tomorrow using your config files - very strange.

carcuevas commented 3 years ago

Thanks very much @jbuchhammer, it can be that I have also something weird in the providers part :thinking: but for me it looks good because all the statements prior to create the server are executed correctly :thinking:

terraform {

  required_providers {
    ionoscloud = {
      source = "ionos-cloud/ionoscloud"

     }
   }
}  

also for the credentials I have in my environment the following variables set:

IONOS_USERNAME="my_ionoscloud_username"
IONOS_PASSWORD="my_ionoscloud_password"

I have experience with terraform and AWS/GCP but now it's the first time with Ionos so maybe there is something I am missing...

Thanks once more ... :)

jbuchhammer commented 3 years ago

Hi @carcuevas , before I come to the nasty part: For our public images, memory hot-plug is enabled, which allows to live-add RAM for a VM. But this requires that RAM is multiple of 1024 MiB, not 512 MiB!

So, when everything else would have been successfully executed, you would still end up with

Error: Request failed with following error: [VDC-5-614] Could not allocate physical resources for the virtual network 3b8e73a9-c60b-4bcc-afdc-661c814f124c because [VDC-5-620] 
The virtual server 527ff039-374b-4496-bb44-6a3a0aa23688 requests 512 MB RAM, but the minimum amount of memory is 1024 MB.
This is a requirement for enabling memory hotplug feature.

   with ionoscloud_server.testserver1,
   on 10_simple-vdc-issue72.tf line 21, in resource "ionoscloud_server" "testserver1":
   21: resource "ionoscloud_server" "testserver1" {

with 512 MiB RAM

carcuevas commented 3 years ago

Aha ok noted :) thanks very much

jbuchhammer commented 3 years ago

And as promised, now the nasty part: Now I took the same Terraform & plugin versions as you (TF 1.0.3, plugin 5.2.6)

  1. Using image_name = "2247f6d7-f38a-11eb-9799-ca71ec1fa085" # Ubuntu-20.04-LTS-server-2021-08-02 results in the error you described:

    Error: error creating server: (422 Unprocessable Entity: {
    "httpStatus" : 422,
    "messages" : [ {
     "errorCode" : "100",
     "message" : "[(root).entities.volumes.items.[0].properties.sshKeys] An image template not found to use SSH keys."
    } ]
    }
    )
  2. Using image_name = "Ubuntu-20.04-LTS-server-2021-08-02" results in a similar but different error:

    Error: Could not find an image/imagealias/snapshot that matches Ubuntu-20.04-LTS-server-2021-08-02

    I checked the spelling but can see no typo.

  3. Using image_name = "ubuntu:latest", which currently is the same image as the previous ones initially runs in the RAM error described i the previous comment. Whenn I change the RAM to 1024 MiB, it works w/o errors.

Yesterday, where my quick tests were successful, I used the same plugin version 5.2.6. Only the Terraform version was different (0.15.5) which makes it even more miraculous.

That said, I just want to point out, that the public images are updated once a month and thus will change their UUID. Thus, it is recommended to use aliases like ubuntu:latest or ubuntu:20.04.

[update]: I tried the image UUID once again w/ 1024 MiB but that didn't make a difference. No clue!

carcuevas commented 3 years ago

Thanks !!! Actually now it is working :))) , but is really interesting thing, so somehow I cannot specify one image UUID, but the alias??

So I guess if somebody needs an specific version of a public image, it would be better to do some custom image with it right?

jbuchhammer commented 3 years ago

Yes, If you need a specific image over a longer period you should custom images or snapshots (which honestly are a bit slow for large images, because the ar snapshotting the whole disk, even empty areas). However, you have to take care of updates too.

carcuevas commented 3 years ago

Thanks very much for you time... Interestingly maybe it is a correct way how to do things, always better to install the latest version, but somehow I am used to for example in AWS specify exactly the image we want to install so some specific servers have exactly the same version.... but as I said I would be creating specific images for specifics servers so it should be ok for me... :) Just it was a bit cryptic error :)

So I guess, we can close this one then right?

jbuchhammer commented 3 years ago

No, we shouldn't close this - I think I got it:

disk_type could be HDD, SSD STANDARD, SSD PREMIUM == SSD But it looks like the plugin only knows about HDD and SSD when getting the image. Since images are always stored on HDD (it's cheaper), the image_type (not the disk_type) is internally mapped to HDD if it's an SSD. But s.th. like SSD STANDARD is not catched. Honestly, I don't see why there are different messages if you're using the name or the UUID but that's the point where I stop now.

@mflorin : can you please take over at this point?

One remark on SSD and size: I now that this is 5 GB SSD is in the example (needs to be fixed too) but be ensured that a 5 GB SSD wouldn't make fun: The perfomance of SSDs scales with the size, so we recommend to use 100 GB at minimum for SSDs. And in addition: If you use public images, you shouldn't set the license_type: It's already set accordingly and will 'enjoy' you with another error message.

carcuevas commented 3 years ago

Thanks @jbuchhammer , well actually it was just my first test with IONOS in Terraform, so I wanted just to try to see how it goes...

Well the error message for me was a bit disorienting, because I would have never suspect that the problem is because using the UUID of the HDD Image instead of the alias of the same image.

Actually I wouldn't use a 5GB SSD for anything else than a test ... maybe maximum a jump server :D about the license_type I read in the ionoscloud_server TF documentation just I wanted to try if it was the cause, I tried a few things before I posted it here, I didn't want to bother you guys with debugging if I had some parameter missing...

carcuevas commented 3 years ago

Thanks guys !!! :)