downloaded rpms can't be installed directly, this will need to be in a different module

Signed-off-by: matttrach <matttrach@gmail.com>
This commit is contained in:
matttrach 2023-10-13 17:57:23 -05:00
parent 2f61a6cf19
commit 831824eb48
No known key found for this signature in database
GPG Key ID: C00467FDE2D0231F
6 changed files with 10 additions and 102 deletions

View File

@ -1,13 +0,0 @@
locals {
version = var.release
path = var.path
}
module "download_rpm" {
source = "../../"
release = local.version
path = local.path
rpm = true
# default: os = "rhel"
# default: os_version = "8"
# default: arch = "amd64"
}

View File

@ -1,9 +0,0 @@
output "tag" {
value = module.download_rpm.tag
}
output "path" {
value = module.download_rpm.path
}
output "files" {
value = module.download_rpm.files
}

View File

@ -1,12 +0,0 @@
variable "release" {
type = string
description = <<-EOT
The value of the git tag associated with the release to find.
EOT
}
variable "path" {
type = string
description = <<-EOT
The path to download the files to.
EOT
}

View File

@ -1,13 +0,0 @@
terraform {
required_version = ">= 1.2.0, < 1.6"
required_providers {
github = {
source = "integrations/github"
version = ">= 5.32"
}
local = {
source = "hashicorp/local"
version = ">= 2.4"
}
}
}

32
main.tf
View File

@ -1,35 +1,21 @@
locals {
system = var.system
rpm = var.rpm
release = var.release
latest = (var.release == "latest" ? true : false)
release_tag = (local.latest ? data.github_release.latest.release_tag : var.release)
sem = regex("v([0-9]+)\\.([0-9]+)\\.([0-9]+)", local.release_tag) # extracts the semver from the release string
kube = "${local.sem[0]}.${local.sem[1]}" # build the major.minor version of kubernetes
arch = var.arch
os = (local.rpm ? var.os : "") # should be rhel, but should only be used when downloading RPMs
os_version = (local.rpm ? var.os_version : "") # should only be used when downloading RPMs
install_url = "https://raw.githubusercontent.com/rancher/rke2/master/install.sh"
rpm_os = (local.os == "rhel" ? "centos" : local.os)
rpm_arch = (local.arch == "amd64" ? "x86_64" : local.arch)
rpm_url = "https://rpm.rancher.io/rke2/stable/${local.kube}/${local.rpm_os}/${local.os_version}"
rpm_release = "${local.sem[0]}.${local.sem[1]}.${local.sem[2]}~rke2r1-0.el${local.os_version}.${local.arch}"
system = var.system
arch = var.arch
release = var.release
latest = (var.release == "latest" ? true : false)
release_tag = (local.latest ? data.github_release.latest.release_tag : var.release)
install_url = "https://raw.githubusercontent.com/rancher/rke2/master/install.sh"
path = abspath(var.path)
selected_assets = (can(data.github_release.selected[0].assets) ? { for a in data.github_release.selected[0].assets : a.name => a.browser_download_url } : {})
latest_assets = (can(data.github_release.latest.assets) ? { for a in data.github_release.latest.assets : a.name => a.browser_download_url } : {})
assets = (local.latest ? local.latest_assets : local.selected_assets)
base_files = {
files = {
"rke2-images.${local.system}-${local.arch}.tar.gz" = local.assets["rke2-images.${local.system}-${local.arch}.tar.gz"],
"rke2.${local.system}-${local.arch}.tar.gz" = local.assets["rke2.${local.system}-${local.arch}.tar.gz"],
"sha256sum-${local.arch}.txt" = local.assets["sha256sum-${local.arch}.txt"],
"install.sh" = local.install_url,
}
files = (local.rpm ? merge(local.base_files, {
"rke2-common.rpm" = "${local.rpm_url}/${local.rpm_arch}/rke2-common-${local.rpm_release}.rpm",
"rke2-server.rpm" = "${local.rpm_url}/${local.rpm_arch}/rke2-server-${local.rpm_release}.rpm",
"rke2-agent.rpm" = "${local.rpm_url}/${local.rpm_arch}/rke2-agent-${local.rpm_release}.rpm",
"rke2-selinux.rpm" = "${local.rpm_url}/noarch/rke2-selinux-0.15-1.el${local.os_version}.noarch.rpm",
}) : local.base_files)
path = abspath(var.path)
}
data "github_release" "selected" {

View File

@ -3,7 +3,6 @@ variable "release" {
description = <<-EOT
The value of the git tag associated with the release to find.
Specify "latest" to find the latest release (default).
When downloading RPMs, this must be a specific release, not "latest".
EOT
default = "latest"
}
@ -23,41 +22,11 @@ variable "system" {
EOT
default = "linux"
}
variable "os" {
type = string
description = <<-EOT
The OS to download RPMs for.
This is only used for RPM downloads.
This is ignored when rpm is false.
EOT
default = "rhel"
}
variable "os_version" {
type = string
description = <<-EOT
The version of RHEL to download RPMs for.
This is only used for RPM downloads.
This is ignored when rpm is false.
EOT
default = "8"
}
variable "path" {
type = string
description = <<-EOT
The path to download the files to.
If not specified, the files will be downloaded to a directory named "rke2" in the root of the module.
If not specified, the files will be downloaded to a directory named "rke2" in the root module.
EOT
default = "./rke2"
}
variable "rpm" {
type = bool
description = <<-EOT
Whether or not to download the RPMs.
Defaults to false.
This option requires that the system is linux (specifically RHEL based) and the architecture is amd64(x86_64).
This option requires the computer running terraform to have curl installed.
When using this option, the "release" variable must be set to a specific release, not "latest".
EOT
default = false
}