diff --git a/examples/rpm/main.tf b/examples/rpm/main.tf deleted file mode 100644 index 0b5fe22..0000000 --- a/examples/rpm/main.tf +++ /dev/null @@ -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" -} diff --git a/examples/rpm/output.tf b/examples/rpm/output.tf deleted file mode 100644 index c6d5d24..0000000 --- a/examples/rpm/output.tf +++ /dev/null @@ -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 -} \ No newline at end of file diff --git a/examples/rpm/variables.tf b/examples/rpm/variables.tf deleted file mode 100644 index 9838307..0000000 --- a/examples/rpm/variables.tf +++ /dev/null @@ -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 -} diff --git a/examples/rpm/versions.tf b/examples/rpm/versions.tf deleted file mode 100644 index 3a910d9..0000000 --- a/examples/rpm/versions.tf +++ /dev/null @@ -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" - } - } -} diff --git a/main.tf b/main.tf index ab20f95..a60c29f 100644 --- a/main.tf +++ b/main.tf @@ -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" { diff --git a/variables.tf b/variables.tf index ad493c1..03d43c9 100644 --- a/variables.tf +++ b/variables.tf @@ -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 -} \ No newline at end of file