[pve-devel] API Return Values

Adam Krone adam.krone at thirdwavellc.com
Fri Oct 20 18:24:23 CEST 2017


(Re-sending as my first try was rejected. Forgot to remove my signature
that contains an attachment)

I need the backup ID because I may need to make an update or delete call at
some point in the future. This may not be an issue if I were building
something interactive like a CLI or web UI, where the user could just get
all the backups and then find the ID they're looking for. In my case,
Terraform is a more automated tool that needs to save the ID for subsequent
operations.

A brief overview of Terraform:

It allows you to define your infrastructure as code, so that any
modifications can be checked in and managed in a repo. Anything that can be
managed with an API can have a provider written so that those resources
exist as simple configuration files, and are managed by Terraform.

For containers or groups, the ID would actually be a part of the
configuration:

resource "proxmox_container" "pvetest01" {
  node = "pve01"
  vmid = 100
  os_template = "local:vztmpl/ubuntu-16.04-standard_16.04-1_amd64.tar.gz"
  root_fs = "local-lvm:20"
  cores = 1
  memory = 512
  swap = 512
  hostname = "pvetest01.thirdwave.local"
}

For backups, we don't know the ID until it's created, and it technically
doesn't need to be a part of the configuration, as long as Terraform saves
it in its state:

resource "proxmox_backup" "daily" {
  start_time = "03:00"
  all = true
  compress = "gzip"
}

Let's say I want to change the start time to "02:00", or delete that backup
schedule all together. At the moment, I can't update/delete any backups
because I don't know the backup ID necessary for making those requests.
Ideally this would be something transparently managed by Terraform, and
wouldn't need to be added to the config file after creation.

There are also some other situations I've found where receiving the
resource in the response could be useful. When creating a container, for
example, if I submit a network configuration without specifying the MAC
address, it looks like the API generates one. If the response included the
newly created resource, with any updates the API may have made behind the
scenes, I would be able to immediately send that along to Terraform to save.



More information about the pve-devel mailing list