2

Is there a way I can cache an ISO being downloaded?

Right now if I terraform destroy, and terraform apply it'll once again download the ISO.

I'm using the libvirt provider and the related resource is:

resource "libvirt_volume" "ubuntu-qcow3" {
  name   = "ubuntu-qcow3"
  pool   = "default"
  source = "https://cloud-images.ubuntu.com/releases/xenial/release/ubuntu-16.04-server-cloudimg-amd64-disk1.img"
  format = "qcow2"
}
Chris Stryczynski
  • 30,145
  • 48
  • 175
  • 286

1 Answers1

3

You could download the image manually to a specific location (e.g. /opt/images)

wget https://cloud-images.ubuntu.com/releases/16.04/release/ubuntu-16.04-server-cloudimg-amd64-disk1.img -P /opt/images

and simply refer to this path, since source accepts local paths as well as remote urls:

resource "libvirt_volume" "ubuntu-qcow3" {
  name   = "ubuntu-qcow3"
  pool   = "default"
  source = "/opt/images/ubuntu-16.04-server-cloudimg-amd64-disk1.img"
  format = "qcow2"
}

Seems very usefull for testing purpose. I learned it from this tutorial where using local file paths was commented out. Since I don't want to mix config files with binary images, I moved them to /opt but feel free to place them where you like.

Lion
  • 16,606
  • 23
  • 86
  • 148
  • I've found if you download the images direct from a URL it's crazy slow. For me it was 20 mins with wget vs 2.5hrs for the URL before I gave up. I have no idea how much longer it would have taken. – MikeKulls Aug 21 '23 at 05:30