Created
October 18, 2022 16:52
-
-
Save lazyfrosch/3ed2b8ac5a6401df9b489e76597dd829 to your computer and use it in GitHub Desktop.
Example of creative loops and local variables
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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