hetznercloud / terraform-provider-hcloud

Terraform Hetzner Cloud provider
https://registry.terraform.io/providers/hetznercloud/hcloud/latest
Mozilla Public License 2.0
513 stars 74 forks source link

"image" is NULL IF server was created from snapshot #143

Closed Sudokamikaze closed 4 years ago

Sudokamikaze commented 4 years ago

Hi there, I have an instance, which was provisioned from snapshot. When I do import from Hetzner, I have following piece of code in tfstate:

      "instances": [
        {
          "schema_version": 0,
          "attributes": {
            "backup_window": "",
            "backups": false,
            "datacenter": "fsn1-dc14",
            "id": "someid",
            "image": null,
            "ipv4_address": "someip",
            "ipv6_address": "someip",
            "ipv6_network": someip",
            "iso": null,
            "keep_disk": null,
            "labels": {},
            "location": "fsn1",
            "name": "somename",
            "rescue": null,
            "server_type": "cx21",
            "ssh_keys": null,
            "status": "running",
            "user_data": null
          },

How to handle such behavior, is there any option to ignore image or use snapshot?

Sudokamikaze commented 4 years ago

Output from hcloud:

Image:
  No Image

Similar server:

  ID:       1
  Type:     system
  Status:   available
  Name:     ubuntu-16.04
  Description:  Ubuntu 16.04
  Image size:   -
  Disk size:    5 GB
  Created:  Mon Jan 15 13:34:45 EET 2018 (2 years ago)
  OS flavor:    ubuntu
  OS version:   16.04
  Rapid deploy: yes

So, that snapshot was deleted way back in past, how to workaround this issue?

shibumi commented 4 years ago

Hi, I ran into a similar issue. You can fix this via doing this:

resource "hcloud_server" "kurisu" {
  name        = "kurisu"
  server_type = "cx11-ceph"
  location    = "fsn1"
  image       = "fedora-31"
  lifecycle {
    ignore_changes = [image]
  }
}

You can basically set in image everything you want.. just set a lifecycle for it and ignore changes to it.