From f3822ca69109834f6fb07262fad2963ce7fdbcf0 Mon Sep 17 00:00:00 2001 From: robertsweetman Date: Sun, 12 May 2024 15:43:36 +0100 Subject: [PATCH 1/6] add component to upgrade 2012 r2 base image to Powershell 5.1 --- commonimages/base/windows_2012_r2/locals.tf | 5 +++++ .../base/windows_2012_r2/terraform.tfvars | 2 +- .../components/templates/powershell_5_1.yml | 22 +++++++++++++++++++ 3 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 commonimages/components/templates/powershell_5_1.yml diff --git a/commonimages/base/windows_2012_r2/locals.tf b/commonimages/base/windows_2012_r2/locals.tf index 8d093bcc..2164ae91 100644 --- a/commonimages/base/windows_2012_r2/locals.tf +++ b/commonimages/base/windows_2012_r2/locals.tf @@ -19,6 +19,11 @@ locals { name = "git_windows" version = "0.0.2" parameters = [] + }, + { + name = "powershell_5_1" + version = "0.0.1" + parameters = [] } ] diff --git a/commonimages/base/windows_2012_r2/terraform.tfvars b/commonimages/base/windows_2012_r2/terraform.tfvars index 1728db72..86dbcc20 100644 --- a/commonimages/base/windows_2012_r2/terraform.tfvars +++ b/commonimages/base/windows_2012_r2/terraform.tfvars @@ -4,7 +4,7 @@ region = "eu-west-2" ami_base_name = "windows_server_2012_r2" -configuration_version = "0.2.2" +configuration_version = "0.2.3" release_or_patch = "release" # or "patch", see nomis AMI image building strategy doc description = "Windows Server 2012 R2" diff --git a/commonimages/components/templates/powershell_5_1.yml b/commonimages/components/templates/powershell_5_1.yml new file mode 100644 index 00000000..3d6cc78d --- /dev/null +++ b/commonimages/components/templates/powershell_5_1.yml @@ -0,0 +1,22 @@ +--- +name: powershell_5_1 +description: Component to install Windows Management Framework 5.1 on Windows Server 2012. This includes PowerShell 5.1 and will supercede Powershell 4.0 so we can use more modern commandlets. +SchemaVersion: 1.0 +parameters: + - Version: + type: string + default: 0.0.1 + description: Component version (update this each time the file changes) + - Platform: + type: string + default: "Windows" + description: Platform. +phases: + - name: build + steps: + - name: InstallPowerShell_5_1 + action: ExecutePowerShell + inputs: + commands: + - | + choco install -y powershell From 8d159709a364d7a6100e9a69dac9e607302fcadd Mon Sep 17 00:00:00 2001 From: robertsweetman Date: Mon, 13 May 2024 09:55:06 +0100 Subject: [PATCH 2/6] correct spelling and update version --- commonimages/base/windows_2012_r2/locals.tf | 2 +- commonimages/base/windows_2012_r2/terraform.tfvars | 2 +- commonimages/components/templates/powershell_5_1.yml | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/commonimages/base/windows_2012_r2/locals.tf b/commonimages/base/windows_2012_r2/locals.tf index 2164ae91..c18acf50 100644 --- a/commonimages/base/windows_2012_r2/locals.tf +++ b/commonimages/base/windows_2012_r2/locals.tf @@ -22,7 +22,7 @@ locals { }, { name = "powershell_5_1" - version = "0.0.1" + version = "0.0.2" parameters = [] } ] diff --git a/commonimages/base/windows_2012_r2/terraform.tfvars b/commonimages/base/windows_2012_r2/terraform.tfvars index 86dbcc20..ba61a6e5 100644 --- a/commonimages/base/windows_2012_r2/terraform.tfvars +++ b/commonimages/base/windows_2012_r2/terraform.tfvars @@ -4,7 +4,7 @@ region = "eu-west-2" ami_base_name = "windows_server_2012_r2" -configuration_version = "0.2.3" +configuration_version = "0.2.4" release_or_patch = "release" # or "patch", see nomis AMI image building strategy doc description = "Windows Server 2012 R2" diff --git a/commonimages/components/templates/powershell_5_1.yml b/commonimages/components/templates/powershell_5_1.yml index 3d6cc78d..6454ccc1 100644 --- a/commonimages/components/templates/powershell_5_1.yml +++ b/commonimages/components/templates/powershell_5_1.yml @@ -1,11 +1,11 @@ --- name: powershell_5_1 description: Component to install Windows Management Framework 5.1 on Windows Server 2012. This includes PowerShell 5.1 and will supercede Powershell 4.0 so we can use more modern commandlets. -SchemaVersion: 1.0 +schemaVersion: 1.0 parameters: - Version: type: string - default: 0.0.1 + default: 0.0.2 description: Component version (update this each time the file changes) - Platform: type: string From 715c91a095b9a34c5ccd22dce1c0b55d196ca996 Mon Sep 17 00:00:00 2001 From: robertsweetman Date: Mon, 13 May 2024 14:49:28 +0100 Subject: [PATCH 3/6] see if adding a reboot here works? --- commonimages/base/windows_2012_r2/locals.tf | 2 +- commonimages/base/windows_2012_r2/terraform.tfvars | 2 +- commonimages/components/templates/powershell_5_1.yml | 3 ++- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/commonimages/base/windows_2012_r2/locals.tf b/commonimages/base/windows_2012_r2/locals.tf index c18acf50..d0a4ebc3 100644 --- a/commonimages/base/windows_2012_r2/locals.tf +++ b/commonimages/base/windows_2012_r2/locals.tf @@ -22,7 +22,7 @@ locals { }, { name = "powershell_5_1" - version = "0.0.2" + version = "0.0.3" parameters = [] } ] diff --git a/commonimages/base/windows_2012_r2/terraform.tfvars b/commonimages/base/windows_2012_r2/terraform.tfvars index ba61a6e5..f6e3f88d 100644 --- a/commonimages/base/windows_2012_r2/terraform.tfvars +++ b/commonimages/base/windows_2012_r2/terraform.tfvars @@ -4,7 +4,7 @@ region = "eu-west-2" ami_base_name = "windows_server_2012_r2" -configuration_version = "0.2.4" +configuration_version = "0.2.5" release_or_patch = "release" # or "patch", see nomis AMI image building strategy doc description = "Windows Server 2012 R2" diff --git a/commonimages/components/templates/powershell_5_1.yml b/commonimages/components/templates/powershell_5_1.yml index 6454ccc1..2a215889 100644 --- a/commonimages/components/templates/powershell_5_1.yml +++ b/commonimages/components/templates/powershell_5_1.yml @@ -5,7 +5,7 @@ schemaVersion: 1.0 parameters: - Version: type: string - default: 0.0.2 + default: 0.0.3 description: Component version (update this each time the file changes) - Platform: type: string @@ -20,3 +20,4 @@ phases: commands: - | choco install -y powershell + exit 3010 From e3a0570c34c0ef7410d78c625265aec15202eb37 Mon Sep 17 00:00:00 2001 From: robertsweetman Date: Tue, 14 May 2024 16:57:35 +0100 Subject: [PATCH 4/6] fix idempotent problem with Powershell Version upgrade --- commonimages/base/windows_2012_r2/locals.tf | 2 +- commonimages/base/windows_2012_r2/terraform.tfvars | 2 +- commonimages/components/templates/powershell_5_1.yml | 12 +++++++++--- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/commonimages/base/windows_2012_r2/locals.tf b/commonimages/base/windows_2012_r2/locals.tf index d0a4ebc3..2bf88c24 100644 --- a/commonimages/base/windows_2012_r2/locals.tf +++ b/commonimages/base/windows_2012_r2/locals.tf @@ -22,7 +22,7 @@ locals { }, { name = "powershell_5_1" - version = "0.0.3" + version = "0.0.4" parameters = [] } ] diff --git a/commonimages/base/windows_2012_r2/terraform.tfvars b/commonimages/base/windows_2012_r2/terraform.tfvars index f6e3f88d..4473ebdb 100644 --- a/commonimages/base/windows_2012_r2/terraform.tfvars +++ b/commonimages/base/windows_2012_r2/terraform.tfvars @@ -4,7 +4,7 @@ region = "eu-west-2" ami_base_name = "windows_server_2012_r2" -configuration_version = "0.2.5" +configuration_version = "0.2.6" release_or_patch = "release" # or "patch", see nomis AMI image building strategy doc description = "Windows Server 2012 R2" diff --git a/commonimages/components/templates/powershell_5_1.yml b/commonimages/components/templates/powershell_5_1.yml index 2a215889..4a29b502 100644 --- a/commonimages/components/templates/powershell_5_1.yml +++ b/commonimages/components/templates/powershell_5_1.yml @@ -5,7 +5,7 @@ schemaVersion: 1.0 parameters: - Version: type: string - default: 0.0.3 + default: 0.0.4 description: Component version (update this each time the file changes) - Platform: type: string @@ -19,5 +19,11 @@ phases: inputs: commands: - | - choco install -y powershell - exit 3010 + if ( $PSVersionTable.PSVersion.Major -ge 5 ) { + Write-Host "PowerShell 5 or higher is already installed" + exit 0 + } else { + Write-Host "Installing PowerShell 5.1" + choco install -y powershell + exit 3010 + } From b04b220f9938a6de367781ac04b34d67bac82ef5 Mon Sep 17 00:00:00 2001 From: robertsweetman Date: Wed, 15 May 2024 09:03:25 +0100 Subject: [PATCH 5/6] uprev versions for merge into main --- commonimages/base/windows_2012_r2/locals.tf | 2 +- commonimages/base/windows_2012_r2/terraform.tfvars | 2 +- commonimages/components/templates/powershell_5_1.yml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/commonimages/base/windows_2012_r2/locals.tf b/commonimages/base/windows_2012_r2/locals.tf index 2bf88c24..a870691c 100644 --- a/commonimages/base/windows_2012_r2/locals.tf +++ b/commonimages/base/windows_2012_r2/locals.tf @@ -22,7 +22,7 @@ locals { }, { name = "powershell_5_1" - version = "0.0.4" + version = "0.0.5" parameters = [] } ] diff --git a/commonimages/base/windows_2012_r2/terraform.tfvars b/commonimages/base/windows_2012_r2/terraform.tfvars index 4473ebdb..0829d4ec 100644 --- a/commonimages/base/windows_2012_r2/terraform.tfvars +++ b/commonimages/base/windows_2012_r2/terraform.tfvars @@ -4,7 +4,7 @@ region = "eu-west-2" ami_base_name = "windows_server_2012_r2" -configuration_version = "0.2.6" +configuration_version = "0.2.7" release_or_patch = "release" # or "patch", see nomis AMI image building strategy doc description = "Windows Server 2012 R2" diff --git a/commonimages/components/templates/powershell_5_1.yml b/commonimages/components/templates/powershell_5_1.yml index 4a29b502..4fa46a4c 100644 --- a/commonimages/components/templates/powershell_5_1.yml +++ b/commonimages/components/templates/powershell_5_1.yml @@ -5,7 +5,7 @@ schemaVersion: 1.0 parameters: - Version: type: string - default: 0.0.4 + default: 0.0.5 description: Component version (update this each time the file changes) - Platform: type: string From a84032ed5ffd6b9999deb7e975df4f72958a0cf7 Mon Sep 17 00:00:00 2001 From: robertsweetman Date: Wed, 15 May 2024 09:14:17 +0100 Subject: [PATCH 6/6] improve get version logic --- commonimages/components/templates/powershell_5_1.yml | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/commonimages/components/templates/powershell_5_1.yml b/commonimages/components/templates/powershell_5_1.yml index 4fa46a4c..6c04974c 100644 --- a/commonimages/components/templates/powershell_5_1.yml +++ b/commonimages/components/templates/powershell_5_1.yml @@ -19,11 +19,12 @@ phases: inputs: commands: - | - if ( $PSVersionTable.PSVersion.Major -ge 5 ) { - Write-Host "PowerShell 5 or higher is already installed" - exit 0 - } else { + $PSMajorVersion = $PSVersionTable.PSVersion.Major + if ( $PSMajorVersion -le 4 ) { Write-Host "Installing PowerShell 5.1" choco install -y powershell exit 3010 + } else { + Write-Host "PowerShell $PSMajorVersion is installed" + exit 0 }