displague / deprecated-terraform-provider-linode

[OLD] Terraform provider plugin for Linode Cloud resources.. See
https://github.com/terraform-providers/terraform-provider-linode
Mozilla Public License 2.0
15 stars 5 forks source link

implement linode_image resource #8

Closed displague closed 5 years ago

displague commented 6 years ago

Support Linode Image creation (perhaps) using a TF syntax like:

resource "linode_image" "freebsd-iso" {
  ... Effectively instance options go here, or we could force it to a small instance,
  ... since this instance will be used only to create the image, and then destroyed.
  ... Image disk sizes are restricted and typical user restrictions wouldn't allow
  ... for a reusable image beyond a few gigs.

  ... Maybe this creates 2 disks, on an instance, and expects the user to build
  ... an image on the second disk, then tell Linode to shut it down, create an
  ... image from the 2nd disk, and then destroy the instance.

   name = "freebsd-iso"
   script = [ "#!/bin/sh", "curl some_remote_freebsd_disk | dd of=/dev/sdb" ]
}

resource "linode_instance" "freebsd-instance" {
  image = "myusername/${linode_image.freebsd-iso.name}"

  // OR
  disk { label= "freebsd", image= "myusername/${linode_image.freebsd-iso.name}"}
  config { devices { sda = {disk_label="freebsd"} }
}
akerl commented 5 years ago

It feels like having a resource "linode_image" spin up a Linode is a violation of least-surprise. It seems more viable to have this take a disk_id as input and leave it to the user to set up that disk.

It does seem like that would require adjusting the Linode_instance resource to expose disk_ids for their disks.

displague commented 5 years ago

@akerl I like the sound of that..

resource "linode_image" "foo" {
  instance_id = "${linode_instance.foo.id}"
  // I believe this is currently accessible
  disk_id = "${linode_instance.foo.config.0.devices.sda.0.disk_id}"
  // or using a data resource, we could look up the disk id independent from any managed resource

  // or, we could take this approach
  disk_label = "foo"

  label = "foo"
}

There are also questions of what feels right in terms of the lifecycle of an image. Should tainting the Instance (and therefor the disk_id) cause the image to be recreated, causing all the instances spawned from that image to be recreated? The lifecycle management of Terraform could be used to prevent those problems in any case.

akerl commented 5 years ago

Isn't instance_id redundant there? The API doesn't use it for CreateImage