Skip to content

Instantly share code, notes, and snippets.

@lazyfrosch
Last active October 18, 2022 16:53
Show Gist options
  • Save lazyfrosch/f4eaccbb44e87e74e3a7077be9ba98b3 to your computer and use it in GitHub Desktop.
Save lazyfrosch/f4eaccbb44e87e74e3a7077be9ba98b3 to your computer and use it in GitHub Desktop.
Example of creative loops and local variables, here updating Flatcar Container Linux images in a vSphere Content Library
variable "flatcar_stages" {
type = list(string)
default = [ "stable", "beta", "lts" ]
}
data "http" "flatcar_version_data" {
for_each = toset(var.flatcar_stages)
url = "https://${each.key}.release.flatcar-linux.net/amd64-usr/current/version.txt"
}
locals {
flatcar_versions = { for k, v in data.http.flatcar_version_data:
k => regex("FLATCAR_VERSION=(\\S+)", v.response_body)[0]
}
}
output "flatcar_versions" {
value = local.flatcar_versions
}
resource "vsphere_content_library_item" "flatcar" {
for_each = local.flatcar_versions
name = "flatcar-production-${each.key}"
description = "Flatcar Container Linux (${each.value}) - Channel ${each.key}"
file_url = "https://${each.key}.release.flatcar-linux.net/amd64-usr/${each.value}/flatcar_production_vmware_ova.ova"
library_id = resource.vsphere_content_library.kubernetes.id
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment