Skip to content

Commit

Permalink
Bump default rke2 version, remove naming convention check, bump azure…
Browse files Browse the repository at this point in the history
… provider version, add better dev scripts
  • Loading branch information
HarrisonWAffel committed Feb 10, 2025
1 parent 675b1f2 commit 13510be
Show file tree
Hide file tree
Showing 21 changed files with 162 additions and 74 deletions.
2 changes: 1 addition & 1 deletion terraform/azure_active_directory/providers.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ terraform {
required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = "3.56.0"
version = "3.90.0"
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion terraform/azure_docker_rancher/providers.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ terraform {
required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = "3.56.0"
version = "3.90.0"
}
digitalocean = {
source = "digitalocean/digitalocean"
Expand Down
2 changes: 1 addition & 1 deletion terraform/azure_rke2_cluster/providers.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ terraform {
required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = "3.56.0"
version = "3.90.0"
}
kubernetes = {
source = "hashicorp/kubernetes"
Expand Down
2 changes: 1 addition & 1 deletion terraform/azure_rke2_cluster/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ variable "name" {
variable "kubernetes_version" {
type = string
description = "The version of RKE2 that you would like to use to provision a cluster."
default = "v1.25.16+rke2r1"
default = "v1.30.9+rke2r1"
}

variable "active_directory" {
Expand Down
2 changes: 2 additions & 0 deletions terraform/azure_server/examples/windows_advanced_dev.tfvars
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
image = "windows-2022"
advanced_dev_tools = true
2 changes: 2 additions & 0 deletions terraform/azure_server/examples/windows_debug.tfvars
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
image = "windows-2022"
debug_tools = true
2 changes: 1 addition & 1 deletion terraform/azure_server/examples/windows_dev.tfvars
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
image = "windows"
image = "windows-2022"
dev_tools = true
12 changes: 12 additions & 0 deletions terraform/azure_server/files/enable_advanced_features.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
$restart = $false

$requiredFeatures = @("Microsoft-Windows-Subsystem-Linux", "VirtualMachinePlatform", "Microsoft-Hyper-V")
foreach ($feature in $requiredFeatures) {
$state = $(Get-WindowsOptionalFeature -Online -FeatureName $feature).State
if ($state -eq "Enabled") {
Write-Host "$feature is installed." -ForegroundColor Green
continue
}
$restart = $true
Enable-WindowsOptionalFeature -Online -FeatureName $feature -All -NoRestart
}
27 changes: 0 additions & 27 deletions terraform/azure_server/files/install_choco.ps1

This file was deleted.

4 changes: 4 additions & 0 deletions terraform/azure_server/files/install_debug_tools.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Install sys internals
scoop install git
scoop bucket add extras
scoop install extras/sysinternals
5 changes: 5 additions & 0 deletions terraform/azure_server/files/install_scoop.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
$env:SCOOP='C:\Applications\Scoop'
$env:SCOOP_GLOBAL='C:\GlobalScoopApps'
[Environment]::SetEnvironmentVariable('SCOOP_GLOBAL', $env:SCOOP_GLOBAL, 'Machine')

iex "& {$(irm get.scoop.sh)} -RunAsAdmin"
5 changes: 5 additions & 0 deletions terraform/azure_server/files/install_scoop_tools.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
scoop install go
scoop install git
scoop install mage
scoop install kubectl

85 changes: 65 additions & 20 deletions terraform/azure_server/files/setup_profile.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@
$toolsPsm1 = @'
function Clone-Repo {
param (
[Parameter(Position=0)]
[string]$RepoName
[Parameter(Position=0)]
[string]
$RepoName
)
# If the repository name does not contain a slash, assume repository is rancher/$RepoName
if ($RepoName -notmatch '/') {
$RepoName = "rancher/$RepoName"
$RepoName = "rancher/$RepoName"
}
# Define the directory where the repository will be cloned
Expand All @@ -19,13 +20,14 @@ function Clone-Repo {
function Go-Repo {
param (
[Parameter(Position=0)]
[string]$RepoName
[Parameter(Position=0)]
[string]
$RepoName
)
# If the repository name does not contain a slash, assume the user wants to go to /go/src/github.com/rancher/$RepoName
if ($RepoName -notmatch '/') {
$RepoName = "rancher/$RepoName"
$RepoName = "rancher/$RepoName"
}
# Define the directory where the repository is located
Expand All @@ -39,31 +41,74 @@ function Go-Repo {
Write-Host "The directory $dir does not exist."
}
}
function Get-RemoteFile {
param (
[Parameter()]
[string]
$RemoteDrive,
[Parameter(Mandatory)]
[string]
$File,
[Parameter(Mandatory)]
[string]
$Destination
)
if ($RemoteDrive -eq "" ) {
Write-Host "RemoteDrive parameter was omitted, defaulting to 'windows'"
$RemoteDrive = "windows"
}
Import-Module BitsTransfer
Start-BitsTransfer \\tsclient\$RemoteDrive\$File -Destination $Destination -Description "Downloading $File from remote drive $RemoteDrive" -DisplayName $File
}
'@

$profileFilePath = $PROFILE.AllUsersCurrentHost
$profileFileDirectory = Split-Path -Path $profileFilePath
$toolsPsm1Path = Join-Path -Path $profileFileDirectory -ChildPath "rancher_tools.psm1"
# Create a powershell module to include useful functions.

Set-Content -Path $toolsPsm1Path -Value $toolsPsm1
# Note: A Powershell module must be placed in a default module path, such as
#
# C:\Users\adminuser\Documents\WindowsPowerShell\Modules
# C:\Program Files\WindowsPowerShell\Modules
# C:\Windows\system32\WindowsPowerShell\v1.0\Modules

# Or if an additional path is desired, it must be created and added to $env:PsModulePath

# Point to script to setup git helpers in profile
# A module must be placed inside a directory with the name of that module (e.g. "RancherTools")
# and the module file must match the module directory name ("RancherTools.psm1").
# Modules can be imported by name using "Import-Module -Name <ModuleName>".

if (!(Test-Path -Path $PROFILE.AllUsersCurrentHost)) {
New-Item -ItemType File -Force -Path $PROFILE.AllUsersCurrentHost
# The scheduled task does not use the standard user created by terraform (adminuser)
# so the $PROFILE variable should not be used.
$profileFileDirectory = "C:\Users\adminuser\Documents\WindowsPowerShell"
if (-not (Test-Path $profileFileDirectory)) {
New-Item -ItemType Directory -Force -Path $profileFileDirectory
}

$toolsModulePath = $profileFileDirectory + "\Modules\" + "RancherTools"
if (-not (Test-Path -Path $toolsModulePath)) {
New-Item -ItemType Directory -Force -Path $toolsModulePath
}

$toolsPsm1Path = Join-Path -Path $toolsModulePath -ChildPath "RancherTools.psm1"
Set-Content -Path $toolsPsm1Path -Value $toolsPsm1

$profileFile = @"
`$env:PATH += ";C:\ProgramData\chocolatey\bin"
`Import-Module -WarningAction Ignore -Name RancherTools
`$null = Import-Module C:\ProgramData\chocolatey\helpers\chocolateyProfile.psm1
`$null = refreshenv
`$null = Import-Module -WarningAction Ignore -Name `"$toolsPsm1Path`"
`$env:PATH += ";C:\Applications\Scoop\shims"
Set-Item -Path Env:\CRI_CONFIG_FILE -Value `$env:ProgramData\crictl\crictl.yaml
"@
Set-Content -Path $PROFILE.AllUsersCurrentHost -Value $profileFile

# Load newly created profile
$profileFilePath = Join-Path -Path $profileFileDirectory -ChildPath "Microsoft.PowerShell_profile.ps1"

. $PROFILE.AllUsersCurrentHost
# Note: This will overwrite any content stored in the profile
Set-Content -Path $profileFilePath -Value $profileFile

# Load newly created profile
. $profileFilePath
53 changes: 41 additions & 12 deletions terraform/azure_server/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,46 @@ module "images" {
}

locals {
scripts = var.dev_tools && module.images.source_images[var.image].os == "windows" ? concat(
[
file("${path.module}/files/enable_features.ps1"),
file("${path.module}/files/install_choco.ps1"),
file("${path.module}/files/setup_profile.ps1"),
file("${path.module}/files/install_docker.ps1"),
file("${path.module}/files/install_containerd.ps1"),
file("${path.module}/files/install_wsl.ps1")
],
var.scripts
) : var.scripts

packageManager = [
file("${path.module}/files/install_scoop.ps1"),
]

commonDevScripts = concat(local.packageManager, [
file("${path.module}/files/enable_standard_features.ps1"),
file("${path.module}/files/install_docker.ps1"),
file("${path.module}/files/install_scoop_tools.ps1"),
file("${path.module}/files/setup_profile.ps1"),
])

advancedDevScripts = concat(local.commonDevScripts, [
file("${path.module}/files/enable_advanced_features.ps1"),
file("${path.module}/files/install_wsl.ps1"),
file("${path.module}/files/install_containerd.ps1"),
])

debugScripts = concat(local.packageManager, [
file("${path.module}/files/install_debug_tools.ps1"),
file("${path.module}/files/install_containerd.ps1"),
file("${path.module}/files/setup_profile.ps1"),
])

scriptMap = {
"devtools" = {
enabled = var.dev_tools
scripts = local.commonDevScripts
},
"advancedDev" = {
enabled = var.advanced_dev_tools
scripts = local.advancedDevScripts
},
"debug" = {
enabled = var.debug_tools
scripts = local.debugScripts
}
}

scripts = [for scriptType in local.scriptMap : scriptType.scripts if scriptType.enabled]
}

module "server" {
Expand All @@ -33,7 +62,7 @@ module "server" {
{
name = "${var.name}-${i}"
image = module.images.source_images[var.image]
scripts = local.scripts
scripts = length(local.scripts) > 0 ? local.scripts[0] : []
domain_join = var.active_directory != null && var.domain_join
}
]
Expand Down
2 changes: 1 addition & 1 deletion terraform/azure_server/providers.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ terraform {
required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = "3.56.0"
version = "3.90.0"
}
}
}
Expand Down
19 changes: 13 additions & 6 deletions terraform/azure_server/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,6 @@
variable "name" {
type = string
description = "The name of the server you would like to provision."

validation {
condition = endswith(var.name, "-server")
error_message = "Name must end with -server"
}
}

variable "replicas" {
Expand Down Expand Up @@ -49,9 +44,21 @@ variable "image" {
default = "linux"
}

variable "debug_tools" {
type = bool
description = "Whether to debugging tools (i.e. system-internals, etc.) onto this host. Only supported for Windows hosts today."
default = false
}

variable "dev_tools" {
type = bool
description = "Whether to install developer tools (i.e. kubectl, git, golang, docker, etc.) onto this host. Only supported for Windows hosts today."
description = "Whether to install standard developer tools (i.e. kubectl, git, golang, docker, scoop, etc.) onto this host. Only supported for Windows hosts today."
default = false
}

variable "advanced_dev_tools" {
type = bool
description = "Whether to install advanced developer tools (i.e. WSL2, HyperV, etc.) onto this host. Only supported for Windows hosts today."
default = false
}

Expand Down
4 changes: 2 additions & 2 deletions terraform/internal/azure/servers/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ variable "location" {

variable "name" {
type = string
description = "The name of the group of servers you would like to provision."
description = "The name of the group of servers you would like to provision or destroy."
}

variable "network" {
Expand Down Expand Up @@ -49,7 +49,7 @@ variable "servers" {
scripts = optional(list(string), [])
domain_join = optional(bool, false)
}))
description = "The group of servers you would like to provision."
description = "The group of servers you would like to provision or destroy."
default = []
}

Expand Down
4 changes: 4 additions & 0 deletions terraform/internal/azure/vm/output.tf
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ locals {
</Query>
</QueryList>
"@
# Monitor the initialization scripts. These can take several minutes to complete.
while(1){Get-ScheduledTask -TaskPath "\Rancher\Terraform\"; sleep 5; clear}
EOT
linux = <<-EOT
# Check all stderr logs from initialization scripts
Expand Down
2 changes: 1 addition & 1 deletion terraform/internal/rancher/rke2/cluster/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ variable "name" {
variable "kubernetes_version" {
type = string
description = "The version of RKE2 that you would like to use to provision a cluster."
default = "v1.24.13+rke2r1"
default = "v1.30.9+rke2r1"
}

0 comments on commit 13510be

Please sign in to comment.