From e6d70b19bed565644314824ca03017b8d361525b Mon Sep 17 00:00:00 2001 From: Hope Aitchison Date: Mon, 9 Oct 2023 15:33:37 +0100 Subject: [PATCH 1/9] feat: on going work to automate the pre-ami steps --- .../ssm-documents/pre-ami-config.yaml | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 terraform/environments/corporate-staff-rostering/ssm-documents/pre-ami-config.yaml diff --git a/terraform/environments/corporate-staff-rostering/ssm-documents/pre-ami-config.yaml b/terraform/environments/corporate-staff-rostering/ssm-documents/pre-ami-config.yaml new file mode 100644 index 00000000000..76132bffb24 --- /dev/null +++ b/terraform/environments/corporate-staff-rostering/ssm-documents/pre-ami-config.yaml @@ -0,0 +1,46 @@ +--- +schemaVersion: "2.2" +description: "SSM Document to convert MGN-replicated Azure VMs into AWS EC2s. Also baking in necessary configuration to CSR app / web AMIs" +parameters: +mainSteps: + - name: UninstallDiscoveryAgent + action: aws:runPowerShellScript + # precondition: + # StringEquals: + # - platformType + # - Windows + inputs: + runCommand: + - | + # Check if AWS discovery agent installed + if (-Not (Get-Service -Name AWS Discovery Agent)) { + Write-Host "AWS Discovery agent not installed, skipping" + } else { + wmic product where name='AWS Discovery Agent' call uninstall + } + + # Install firefox + # Invoke call to internet + Invoke-WebRequest -URI "https://download.mozilla.org/?product=firefox-esr-next-latest-ssl&os=win64&lang=en-GB" -OutFile "$ENV:TEMP\MozillaFirefox.exe" + # Need to invoke the installer + Invoke-Item "$ENV:TEMP\MozillaFirefox.exe" + + # Install nmap tool + # Invoke call to internet + Invoke-WebRequest -URI "https://nmap.org/download" -OutFile "$ENV:TEMP\nmap.exe" + # Need to invoke the installer + Invoke-Item "$ENV:TEMP\nmap.exe" + + # Install AD module + Install-WindowsFeature -Name "RSAT-AD-PowerShell" -IncludeAllSubFeature + + # Install EC2LaunchV2 + + New-Item -Path "$env:USERPROFILE\Desktop\EC2Launchv2" -ItemType Directory + $Url = " https://s3.amazonaws.com/amazon-ec2launch-v2/windows/amd64/latest/AmazonEC2Launch.msi/AmazonEC2Launch.msi" + $DownloadFile = "$env:USERPROFILE\Desktop\EC2Launchv2\" + $(Split-Path -Path $Url -Leaf) + Invoke-WebRequest -Uri $Url -OutFile $DownloadFile + msiexec /i "$DownloadFile" + + # verify the install + C:\ProgramData\Amazon\EC2Launch \ No newline at end of file From 2675a8f48a45aca034c88c6a0004c61531ae3dd3 Mon Sep 17 00:00:00 2001 From: Hope Aitchison Date: Tue, 17 Oct 2023 17:26:57 +0100 Subject: [PATCH 2/9] more steps defined --- .../ssm-documents/pre-ami-config.yaml | 55 +++++++++++++++---- 1 file changed, 43 insertions(+), 12 deletions(-) diff --git a/terraform/environments/corporate-staff-rostering/ssm-documents/pre-ami-config.yaml b/terraform/environments/corporate-staff-rostering/ssm-documents/pre-ami-config.yaml index 76132bffb24..00926d5e746 100644 --- a/terraform/environments/corporate-staff-rostering/ssm-documents/pre-ami-config.yaml +++ b/terraform/environments/corporate-staff-rostering/ssm-documents/pre-ami-config.yaml @@ -2,13 +2,27 @@ schemaVersion: "2.2" description: "SSM Document to convert MGN-replicated Azure VMs into AWS EC2s. Also baking in necessary configuration to CSR app / web AMIs" parameters: + InstanceId: + type: "String" + description: "ID of the MGN replicated server being turned into an AMIs" + VolumeId: + type: "String" + description: "Root volume ID to be snapshotted" + SnapshotName: + type: "String" + description: "Name of the snapshot" + mainSteps: + - name: CreateSnapshot + action: aws:createSnapshot + inputs: + InstanceId: "{{ InstanceId }}" + VolumeId: "{{ VolumeId }}" + description: "{{ SnapshotName }}" + onFailure: Stop + - name: UninstallDiscoveryAgent action: aws:runPowerShellScript - # precondition: - # StringEquals: - # - platformType - # - Windows inputs: runCommand: - | @@ -19,28 +33,45 @@ mainSteps: wmic product where name='AWS Discovery Agent' call uninstall } + - name: InstallFirefoxBrowser + action: aws:runPowerShellScript + inputs: + runCommand: + - | # Install firefox # Invoke call to internet Invoke-WebRequest -URI "https://download.mozilla.org/?product=firefox-esr-next-latest-ssl&os=win64&lang=en-GB" -OutFile "$ENV:TEMP\MozillaFirefox.exe" # Need to invoke the installer Invoke-Item "$ENV:TEMP\MozillaFirefox.exe" + - name: InstallNmapTool + action: aws:runPowerShellScript + inputs: + runCommand: + - | # Install nmap tool # Invoke call to internet Invoke-WebRequest -URI "https://nmap.org/download" -OutFile "$ENV:TEMP\nmap.exe" # Need to invoke the installer Invoke-Item "$ENV:TEMP\nmap.exe" + - name: InstallActiveDirectoryModule + action: aws:runPowerShellScript + inputs: + runCommand: + - | # Install AD module Install-WindowsFeature -Name "RSAT-AD-PowerShell" -IncludeAllSubFeature - # Install EC2LaunchV2 - - New-Item -Path "$env:USERPROFILE\Desktop\EC2Launchv2" -ItemType Directory - $Url = " https://s3.amazonaws.com/amazon-ec2launch-v2/windows/amd64/latest/AmazonEC2Launch.msi/AmazonEC2Launch.msi" - $DownloadFile = "$env:USERPROFILE\Desktop\EC2Launchv2\" + $(Split-Path -Path $Url -Leaf) - Invoke-WebRequest -Uri $Url -OutFile $DownloadFile - msiexec /i "$DownloadFile" + - name: InstallEC2LaunchV2 + action: aws:runShellScript + inputs: + runCommand: + - # Download the EC2LaunchV2 installer script + - wget https://s3.amazonaws.com/ec2-downloads-windows/SSM-Agent/EC2Launch/latest/install.ps1 -OutFile $env:TEMP\install.ps1 + - # Run the installer script + - powershell -ExecutionPolicy Bypass -File $env:TEMP\install.ps1 # verify the install - C:\ProgramData\Amazon\EC2Launch \ No newline at end of file + C:\ProgramData\Amazon\EC2Launch + - name: \ No newline at end of file From d1550a9dd6582040e6a84a4071fe5e6e4b42bb09 Mon Sep 17 00:00:00 2001 From: Hope Aitchison Date: Thu, 19 Oct 2023 19:36:15 +0100 Subject: [PATCH 3/9] adding in more steps to automate AMI build from replicated MGN instance --- .../ssm-documents/pre-ami-config.yaml | 137 +++++++++++++++--- 1 file changed, 114 insertions(+), 23 deletions(-) diff --git a/terraform/environments/corporate-staff-rostering/ssm-documents/pre-ami-config.yaml b/terraform/environments/corporate-staff-rostering/ssm-documents/pre-ami-config.yaml index 00926d5e746..d3768de3d96 100644 --- a/terraform/environments/corporate-staff-rostering/ssm-documents/pre-ami-config.yaml +++ b/terraform/environments/corporate-staff-rostering/ssm-documents/pre-ami-config.yaml @@ -11,8 +11,31 @@ parameters: SnapshotName: type: "String" description: "Name of the snapshot" + AMIName: + type: "String" + description: "Name of the AMI being created" mainSteps: + - name: getRootVolumeSpace + action: aws:runPowerShellScript + inputs: + runCommand: + - | + - $rootVolume = Get-WmiObject -Query "SELECT * FROM Win32_LogicalDisk WHERE DeviceID = 'C:'" + - $availableSpaceGB = [math]::Round(($rootVolume.FreeSpace / 1GB), 2) + - Write-Output "Available space on the C drive is $availableSpaceGB" + + - name: spaceAvailable + action: aws:runPowerShellScript + inputs: + runCommand: + - | + - $totalSpaceGB = [math]::Round(($rootVolume.Size / 1GB), 2) + - $availablePercentage = [math]::Round((($availableSpaceGB / $totalSpaceGB) * 100), 2) + - Write-Output "Available space on the root volume (C:) is $availablePercentage% of the total space" + +# add a step that stops the process if the available space is less than 50% + - name: CreateSnapshot action: aws:createSnapshot inputs: @@ -21,57 +44,125 @@ mainSteps: description: "{{ SnapshotName }}" onFailure: Stop + - name: stopDiscoveryAgent + action: aws:runPowerShellScript + inputs: + runCommand: + - | + - Stop-Service -Name 'AWSDiscoveryService' -ErrorAction SilentlyContinue + - name: UninstallDiscoveryAgent action: aws:runPowerShellScript inputs: runCommand: - | - # Check if AWS discovery agent installed - if (-Not (Get-Service -Name AWS Discovery Agent)) { - Write-Host "AWS Discovery agent not installed, skipping" - } else { - wmic product where name='AWS Discovery Agent' call uninstall - } + - if (Test-Path 'C:\Program Files\Amazon\Amazon AppStream\aws-discovery-agent\uninstall.exe') { + - Start-Process 'C:\Program Files\Amazon\Amazon AppStream\aws-discovery-agent\uninstall.exe' -ArgumentList '/S' -Wait + - } elseif (Test-Path 'C:\Program Files\AWS\AWS Discovery Agent\uninstall.exe') { + - Start-Process 'C:\Program Files\AWS\AWS Discovery Agent\uninstall.exe' -ArgumentList '/S' -Wait + - } else { + - Write-Host "AWS Discovery Agent not found for uninstallation." + - } + + - name: verifyUninstallation + action: aws:runPowerShellScript + inputs: + runCommand: + - | + - if (-not (Test-Path 'C:\Program Files\Amazon\Amazon AppStream\aws-discovery-agent\uninstall.exe') -and -not (Test-Path 'C:\Program Files\AWS\AWS Discovery Agent\uninstall.exe')) { + - Write-Host "AWS Discovery Agent is successfully uninstalled." + - } else { + - Write-Host "AWS Discovery Agent uninstallation may have failed." + - } + onFailure: Stop - name: InstallFirefoxBrowser action: aws:runPowerShellScript inputs: runCommand: - | - # Install firefox - # Invoke call to internet - Invoke-WebRequest -URI "https://download.mozilla.org/?product=firefox-esr-next-latest-ssl&os=win64&lang=en-GB" -OutFile "$ENV:TEMP\MozillaFirefox.exe" - # Need to invoke the installer - Invoke-Item "$ENV:TEMP\MozillaFirefox.exe" + - Invoke-WebRequest -URI "https://download.mozilla.org/?product=firefox-esr-next-latest-ssl&os=win64&lang=en-GB" -OutFile "$ENV:TEMP\MozillaFirefox.exe" + - Invoke-Item "$ENV:TEMP\MozillaFirefox.exe" - name: InstallNmapTool action: aws:runPowerShellScript inputs: runCommand: - | - # Install nmap tool - # Invoke call to internet - Invoke-WebRequest -URI "https://nmap.org/download" -OutFile "$ENV:TEMP\nmap.exe" - # Need to invoke the installer - Invoke-Item "$ENV:TEMP\nmap.exe" + - Invoke-WebRequest -URI "https://nmap.org/download" -OutFile "$ENV:TEMP\nmap.exe" + - Invoke-Item "$ENV:TEMP\nmap.exe" + + - name: checkADModulePresent + action: aws:runPowerShellScript + inputs: + runCommand: + - | + - $module = Get-Module -ListAvailable -Name ActiveDirectory + - if (-not $module) { + - Write-Error "Active Directory module is not installed. Installing..." + - } - name: InstallActiveDirectoryModule action: aws:runPowerShellScript inputs: runCommand: - | - # Install AD module Install-WindowsFeature -Name "RSAT-AD-PowerShell" -IncludeAllSubFeature - name: InstallEC2LaunchV2 - action: aws:runShellScript + action: aws:runPowerShellScript inputs: runCommand: - - # Download the EC2LaunchV2 installer script + - | - wget https://s3.amazonaws.com/ec2-downloads-windows/SSM-Agent/EC2Launch/latest/install.ps1 -OutFile $env:TEMP\install.ps1 - - # Run the installer script - powershell -ExecutionPolicy Bypass -File $env:TEMP\install.ps1 + + - name: verifyInstallation + action: aws:runPowerShellScript + inputs: + runCommand: + - | + - if (Get-Service -Name EC2Launch | Where-Object {$_.Status -eq 'Running'}) { + - Write-Output "EC2LaunchV2 driver installed and running successfully." + - } else { + - Write-Output "EC2LaunchV2 driver installation or service startup failed." + - } + + - name: stopInstance + action: aws:changeInstanceState + inputs: + instaneID: "{{ InstanceId }}" + desiredState: stopped - # verify the install - C:\ProgramData\Amazon\EC2Launch - - name: \ No newline at end of file + - name: createImage + action: aws:createImage + inputs: + InstanceId: "{{ InstanceId }}" + name: "{{ AMIName }}" + description: AMI created from "{{ InstanceId }}" + noReboot: true + + # BlockDeviceMappings to exclude specific EBS volumes - check if this is needed + # blockDeviceMappings: + # - deviceName: /dev/sdb # Replace with the device name of the volume to exclude + # noDevice: true + + - name: outputImageId + action: aws:runPowerShellScript + inputs: + runCommand: + - | + - Write-Output "Image ID: $ImageId" + + - name: waitForAMI + action: aws:waitForImages + inputs: + imageIds: ["{{ createImage.ImageId }}"] + state: available + maxResults: 1 + + - name: startInstance + action: aws:changeInstanceState + inputs: + instanceId: "{{ InstanceId }}" + desiredState: running From 8b8a85d732b1d19af0eb520e0151aa1be5b5d562 Mon Sep 17 00:00:00 2001 From: Hope Aitchison Date: Fri, 20 Oct 2023 12:52:40 +0100 Subject: [PATCH 4/9] adding in stoppage step if the disk needs extending --- .../ssm-documents/pre-ami-config.yaml | 28 +++++++++++++------ 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/terraform/environments/corporate-staff-rostering/ssm-documents/pre-ami-config.yaml b/terraform/environments/corporate-staff-rostering/ssm-documents/pre-ami-config.yaml index d3768de3d96..c84d8b82ebd 100644 --- a/terraform/environments/corporate-staff-rostering/ssm-documents/pre-ami-config.yaml +++ b/terraform/environments/corporate-staff-rostering/ssm-documents/pre-ami-config.yaml @@ -16,6 +16,14 @@ parameters: description: "Name of the AMI being created" mainSteps: + - name: CreateSnapshot + action: aws:createSnapshot + inputs: + InstanceId: "{{ InstanceId }}" + VolumeId: "{{ VolumeId }}" + description: "{{ SnapshotName }}" + onFailure: Stop + - name: getRootVolumeSpace action: aws:runPowerShellScript inputs: @@ -34,15 +42,17 @@ mainSteps: - $availablePercentage = [math]::Round((($availableSpaceGB / $totalSpaceGB) * 100), 2) - Write-Output "Available space on the root volume (C:) is $availablePercentage% of the total space" -# add a step that stops the process if the available space is less than 50% - - - name: CreateSnapshot - action: aws:createSnapshot - inputs: - InstanceId: "{{ InstanceId }}" - VolumeId: "{{ VolumeId }}" - description: "{{ SnapshotName }}" + - name: extendDiskStop + action: aws:runPowerShellScript + maxAttempts: 1 onFailure: Stop + inputs: + runCommand: + - | + - if ($availablePercentage% -lt 50) { + - Write-Output "Available disk space is less than 50%. Stopping doc execution." + - Exit 1 + - } - name: stopDiscoveryAgent action: aws:runPowerShellScript @@ -165,4 +175,4 @@ mainSteps: action: aws:changeInstanceState inputs: instanceId: "{{ InstanceId }}" - desiredState: running + desiredState: running \ No newline at end of file From 83483a768a2005d928b81dabdec117165497a8e2 Mon Sep 17 00:00:00 2001 From: Hope Aitchison Date: Fri, 20 Oct 2023 15:33:26 +0100 Subject: [PATCH 5/9] updating syntax --- .../ssm-documents/pre-ami-config.yaml | 87 +++++++++---------- 1 file changed, 42 insertions(+), 45 deletions(-) diff --git a/terraform/environments/corporate-staff-rostering/ssm-documents/pre-ami-config.yaml b/terraform/environments/corporate-staff-rostering/ssm-documents/pre-ami-config.yaml index c84d8b82ebd..3a714f669e0 100644 --- a/terraform/environments/corporate-staff-rostering/ssm-documents/pre-ami-config.yaml +++ b/terraform/environments/corporate-staff-rostering/ssm-documents/pre-ami-config.yaml @@ -29,18 +29,18 @@ mainSteps: inputs: runCommand: - | - - $rootVolume = Get-WmiObject -Query "SELECT * FROM Win32_LogicalDisk WHERE DeviceID = 'C:'" - - $availableSpaceGB = [math]::Round(($rootVolume.FreeSpace / 1GB), 2) - - Write-Output "Available space on the C drive is $availableSpaceGB" + $rootVolume = Get-WmiObject -Query "SELECT * FROM Win32_LogicalDisk WHERE DeviceID = 'C:'" + $availableSpaceGB = [math]::Round(($rootVolume.FreeSpace / 1GB), 2) + Write-Output "Available space on the C drive is $availableSpaceGB" - name: spaceAvailable action: aws:runPowerShellScript inputs: runCommand: - | - - $totalSpaceGB = [math]::Round(($rootVolume.Size / 1GB), 2) - - $availablePercentage = [math]::Round((($availableSpaceGB / $totalSpaceGB) * 100), 2) - - Write-Output "Available space on the root volume (C:) is $availablePercentage% of the total space" + $totalSpaceGB = [math]::Round(($rootVolume.Size / 1GB), 2) + $availablePercentage = [math]::Round((($availableSpaceGB / $totalSpaceGB) * 100), 2) + Write-Output "Available space on the root volume (C:) is $availablePercentage% of the total space" - name: extendDiskStop action: aws:runPowerShellScript @@ -49,41 +49,41 @@ mainSteps: inputs: runCommand: - | - - if ($availablePercentage% -lt 50) { - - Write-Output "Available disk space is less than 50%. Stopping doc execution." - - Exit 1 - - } + if ($availablePercentage% -lt 50) { + Write-Output "Available disk space is less than 50%. Stopping doc execution." + Exit 1 + } - name: stopDiscoveryAgent action: aws:runPowerShellScript inputs: runCommand: - | - - Stop-Service -Name 'AWSDiscoveryService' -ErrorAction SilentlyContinue + Stop-Service -Name 'AWSDiscoveryService' -ErrorAction SilentlyContinue - name: UninstallDiscoveryAgent action: aws:runPowerShellScript inputs: runCommand: - | - - if (Test-Path 'C:\Program Files\Amazon\Amazon AppStream\aws-discovery-agent\uninstall.exe') { - - Start-Process 'C:\Program Files\Amazon\Amazon AppStream\aws-discovery-agent\uninstall.exe' -ArgumentList '/S' -Wait - - } elseif (Test-Path 'C:\Program Files\AWS\AWS Discovery Agent\uninstall.exe') { - - Start-Process 'C:\Program Files\AWS\AWS Discovery Agent\uninstall.exe' -ArgumentList '/S' -Wait - - } else { - - Write-Host "AWS Discovery Agent not found for uninstallation." - - } + if (Test-Path 'C:\Program Files\Amazon\Amazon AppStream\aws-discovery-agent\uninstall.exe') { + Start-Process 'C:\Program Files\Amazon\Amazon AppStream\aws-discovery-agent\uninstall.exe' -ArgumentList '/S' -Wait + } elseif (Test-Path 'C:\Program Files\AWS\AWS Discovery Agent\uninstall.exe') { + Start-Process 'C:\Program Files\AWS\AWS Discovery Agent\uninstall.exe' -ArgumentList '/S' -Wait + } else { + Write-Host "AWS Discovery Agent not found for uninstallation." + } - name: verifyUninstallation action: aws:runPowerShellScript inputs: runCommand: - | - - if (-not (Test-Path 'C:\Program Files\Amazon\Amazon AppStream\aws-discovery-agent\uninstall.exe') -and -not (Test-Path 'C:\Program Files\AWS\AWS Discovery Agent\uninstall.exe')) { - - Write-Host "AWS Discovery Agent is successfully uninstalled." - - } else { - - Write-Host "AWS Discovery Agent uninstallation may have failed." - - } + if (-not (Test-Path 'C:\Program Files\Amazon\Amazon AppStream\aws-discovery-agent\uninstall.exe') -and -not (Test-Path 'C:\Program Files\AWS\AWS Discovery Agent\uninstall.exe')) { + Write-Host "AWS Discovery Agent is successfully uninstalled." + } else { + Write-Host "AWS Discovery Agent uninstallation may have failed." + } onFailure: Stop - name: InstallFirefoxBrowser @@ -91,26 +91,28 @@ mainSteps: inputs: runCommand: - | - - Invoke-WebRequest -URI "https://download.mozilla.org/?product=firefox-esr-next-latest-ssl&os=win64&lang=en-GB" -OutFile "$ENV:TEMP\MozillaFirefox.exe" - - Invoke-Item "$ENV:TEMP\MozillaFirefox.exe" + Invoke-WebRequest -URI "https://download.mozilla.org/?product=firefox-esr-next-latest-ssl&os=win64&lang=en-GB" -OutFile "$ENV:TEMP\MozillaFirefox.exe" + Invoke-Item "$ENV:TEMP\MozillaFirefox.exe" + +# wireshark - name: InstallNmapTool action: aws:runPowerShellScript inputs: runCommand: - | - - Invoke-WebRequest -URI "https://nmap.org/download" -OutFile "$ENV:TEMP\nmap.exe" - - Invoke-Item "$ENV:TEMP\nmap.exe" + Invoke-WebRequest -URI "https://nmap.org/download" -OutFile "$ENV:TEMP\nmap.exe" + Invoke-Item "$ENV:TEMP\nmap.exe" - name: checkADModulePresent action: aws:runPowerShellScript inputs: runCommand: - - | - - $module = Get-Module -ListAvailable -Name ActiveDirectory - - if (-not $module) { - - Write-Error "Active Directory module is not installed. Installing..." - - } + - | + $module = Get-Module -ListAvailable -Name ActiveDirectory + if (-not $module) { + Write-Error "Active Directory module is not installed. Installing..." + } - name: InstallActiveDirectoryModule action: aws:runPowerShellScript @@ -124,19 +126,19 @@ mainSteps: inputs: runCommand: - | - - wget https://s3.amazonaws.com/ec2-downloads-windows/SSM-Agent/EC2Launch/latest/install.ps1 -OutFile $env:TEMP\install.ps1 - - powershell -ExecutionPolicy Bypass -File $env:TEMP\install.ps1 + Invoke-WebRequest -URI https://s3.amazonaws.com/ec2-downloads-windows/SSM-Agent/EC2Launch/latest/install.ps1 -OutFile $env:TEMP\install.ps1 + powershell -ExecutionPolicy Bypass -File $env:TEMP\install.ps1 - name: verifyInstallation action: aws:runPowerShellScript inputs: runCommand: - | - - if (Get-Service -Name EC2Launch | Where-Object {$_.Status -eq 'Running'}) { - - Write-Output "EC2LaunchV2 driver installed and running successfully." - - } else { - - Write-Output "EC2LaunchV2 driver installation or service startup failed." - - } + if (Get-Service -Name EC2Launch | Where-Object {$_.Status -eq 'Running'}) { + Write-Output "EC2LaunchV2 driver installed and running successfully." + } else { + Write-Output "EC2LaunchV2 driver installation or service startup failed." + } - name: stopInstance action: aws:changeInstanceState @@ -152,17 +154,12 @@ mainSteps: description: AMI created from "{{ InstanceId }}" noReboot: true - # BlockDeviceMappings to exclude specific EBS volumes - check if this is needed - # blockDeviceMappings: - # - deviceName: /dev/sdb # Replace with the device name of the volume to exclude - # noDevice: true - - name: outputImageId action: aws:runPowerShellScript inputs: runCommand: - | - - Write-Output "Image ID: $ImageId" + Write-Output "Image ID: $ImageId" - name: waitForAMI action: aws:waitForImages From f3cf2f8582abd1f4be51ae7551b4bad5935a2f0a Mon Sep 17 00:00:00 2001 From: Hope Aitchison Date: Fri, 20 Oct 2023 15:34:39 +0100 Subject: [PATCH 6/9] renaming ssm doc --- .../ssm-documents/{pre-ami-config.yaml => ami-creation.yaml} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename terraform/environments/corporate-staff-rostering/ssm-documents/{pre-ami-config.yaml => ami-creation.yaml} (100%) diff --git a/terraform/environments/corporate-staff-rostering/ssm-documents/pre-ami-config.yaml b/terraform/environments/corporate-staff-rostering/ssm-documents/ami-creation.yaml similarity index 100% rename from terraform/environments/corporate-staff-rostering/ssm-documents/pre-ami-config.yaml rename to terraform/environments/corporate-staff-rostering/ssm-documents/ami-creation.yaml From 9efb05f058cb7c3a08a781545015f9ce357f05e3 Mon Sep 17 00:00:00 2001 From: Hope Aitchison Date: Fri, 20 Oct 2023 15:49:25 +0100 Subject: [PATCH 7/9] lding the ami build ssm resource --- .../corporate-staff-rostering/ec2_common.tf | 14 ++++++++++++++ .../{ami-creation.yaml => ami-build.yaml} | 0 2 files changed, 14 insertions(+) rename terraform/environments/corporate-staff-rostering/ssm-documents/{ami-creation.yaml => ami-build.yaml} (100%) diff --git a/terraform/environments/corporate-staff-rostering/ec2_common.tf b/terraform/environments/corporate-staff-rostering/ec2_common.tf index d27588c2c46..c66e4c0a112 100644 --- a/terraform/environments/corporate-staff-rostering/ec2_common.tf +++ b/terraform/environments/corporate-staff-rostering/ec2_common.tf @@ -38,4 +38,18 @@ resource "aws_ssm_document" "cloud_watch_agent" { Name = "windows-cloudwatch-agent-config" }, ) +} + +resource "aws_ssm_document" "ami_build" { + name = "ami-build" + document_type = "Command" + document_format = "YAML" + content = file("./ssm-documents/ami-build.yaml") + + tags = merge( + local.tags, + { + Name = "ami-build" + }, + ) } \ No newline at end of file diff --git a/terraform/environments/corporate-staff-rostering/ssm-documents/ami-creation.yaml b/terraform/environments/corporate-staff-rostering/ssm-documents/ami-build.yaml similarity index 100% rename from terraform/environments/corporate-staff-rostering/ssm-documents/ami-creation.yaml rename to terraform/environments/corporate-staff-rostering/ssm-documents/ami-build.yaml From 57517b6b064fcf188d900917b5ebcbadafd6fd07 Mon Sep 17 00:00:00 2001 From: Hope Aitchison Date: Fri, 20 Oct 2023 15:52:14 +0100 Subject: [PATCH 8/9] making the descriptions a bit less rubbish --- .../ssm-documents/ami-build.yaml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/terraform/environments/corporate-staff-rostering/ssm-documents/ami-build.yaml b/terraform/environments/corporate-staff-rostering/ssm-documents/ami-build.yaml index 3a714f669e0..b0ac16ea9ba 100644 --- a/terraform/environments/corporate-staff-rostering/ssm-documents/ami-build.yaml +++ b/terraform/environments/corporate-staff-rostering/ssm-documents/ami-build.yaml @@ -1,19 +1,19 @@ --- schemaVersion: "2.2" -description: "SSM Document to convert MGN-replicated Azure VMs into AWS EC2s. Also baking in necessary configuration to CSR app / web AMIs" +description: "SSM Document to convert an Azure VM into an AWS AMI." parameters: InstanceId: type: "String" - description: "ID of the MGN replicated server being turned into an AMIs" + description: "ID of the MGN replicated Azure server" VolumeId: type: "String" description: "Root volume ID to be snapshotted" SnapshotName: type: "String" - description: "Name of the snapshot" + description: "Name of the resultant snapshot" AMIName: type: "String" - description: "Name of the AMI being created" + description: "Name of the AMI being built" mainSteps: - name: CreateSnapshot From a377097161a5aebe166d6e75ea61bba7be565377 Mon Sep 17 00:00:00 2001 From: Hope Aitchison Date: Fri, 20 Oct 2023 16:03:50 +0100 Subject: [PATCH 9/9] brakcet error resolved --- .../corporate-staff-rostering/ssm-documents/ami-build.yaml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/terraform/environments/corporate-staff-rostering/ssm-documents/ami-build.yaml b/terraform/environments/corporate-staff-rostering/ssm-documents/ami-build.yaml index b0ac16ea9ba..71bffd270a1 100644 --- a/terraform/environments/corporate-staff-rostering/ssm-documents/ami-build.yaml +++ b/terraform/environments/corporate-staff-rostering/ssm-documents/ami-build.yaml @@ -79,7 +79,8 @@ mainSteps: inputs: runCommand: - | - if (-not (Test-Path 'C:\Program Files\Amazon\Amazon AppStream\aws-discovery-agent\uninstall.exe') -and -not (Test-Path 'C:\Program Files\AWS\AWS Discovery Agent\uninstall.exe')) { + if (-not (Test-Path 'C:\Program Files\Amazon\Amazon AppStream\aws-discovery-agent\uninstall.exe') -and -not (Test-Path 'C:\Program Files\AWS\AWS Discovery Agent\uninstall.exe')) + { Write-Host "AWS Discovery Agent is successfully uninstalled." } else { Write-Host "AWS Discovery Agent uninstallation may have failed."