generated from ministryofjustice/template-repository
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of https://github.com/ministryofjustice/modernisa…
…tion-platform-environments into LAWS-3514-Backup-Lambda to merge apex codebuild resources
- Loading branch information
Showing
32 changed files
with
463 additions
and
222 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
178 changes: 178 additions & 0 deletions
178
terraform/environments/corporate-staff-rostering/ssm-documents/ami-build.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,178 @@ | ||
--- | ||
schemaVersion: "2.2" | ||
description: "SSM Document to convert an Azure VM into an AWS AMI." | ||
parameters: | ||
InstanceId: | ||
type: "String" | ||
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 resultant snapshot" | ||
AMIName: | ||
type: "String" | ||
description: "Name of the AMI being built" | ||
|
||
mainSteps: | ||
- name: CreateSnapshot | ||
action: aws:runDocument | ||
inputs: | ||
documentType: SSMDocument | ||
documentPath: AWS-CreateSnapshot | ||
documentParameters: | ||
VolumeId: "{{ VolumeId }}" | ||
description: "{{ SnapshotName }}" | ||
onFailure: Abort | ||
|
||
- 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" | ||
- name: extendDiskStop | ||
action: aws:runPowerShellScript | ||
maxAttempts: 1 | ||
inputs: | ||
runCommand: | ||
- | | ||
if ($availablePercentage% -lt 50) { | ||
Write-Output "Available disk space is less than 50%. Stopping doc execution." | ||
Exit 1 | ||
} | ||
onFailure: Abort | ||
|
||
- name: stopDiscoveryAgent | ||
action: aws:runPowerShellScript | ||
inputs: | ||
runCommand: | ||
- | | ||
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." | ||
} | ||
- 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: Abort | ||
|
||
- name: InstallFirefoxBrowser | ||
action: aws:runPowerShellScript | ||
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" | ||
# 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" | ||
- 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-WindowsFeature -Name "RSAT-AD-PowerShell" -IncludeAllSubFeature | ||
- name: InstallEC2LaunchV2 | ||
action: aws:runPowerShellScript | ||
inputs: | ||
runCommand: | ||
- | | ||
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." | ||
} | ||
- name: stopInstance | ||
action: aws:changeInstanceState | ||
inputs: | ||
instaneID: "{{ InstanceId }}" | ||
desiredState: stopped | ||
|
||
- name: createImage | ||
action: aws:createImage | ||
inputs: | ||
InstanceId: "{{ InstanceId }}" | ||
name: "{{ AMIName }}" | ||
description: AMI created from "{{ InstanceId }}" | ||
noReboot: true | ||
|
||
- name: outputImageId | ||
action: aws:runPowerShellScript | ||
inputs: | ||
runCommand: | ||
- | | ||
Write-Output "Image ID: $ImageId" | ||
- name: waitForAMI # update this | ||
action: aws:waitForImages | ||
inputs: | ||
imageIds: ["{{ createImage.ImageId }}"] | ||
state: available | ||
maxResults: 1 | ||
|
||
- name: startInstance | ||
action: aws:changeInstanceState | ||
inputs: | ||
instanceId: "{{ InstanceId }}" | ||
desiredState: running |
28 changes: 28 additions & 0 deletions
28
...environments/corporate-staff-rostering/ssm-documents/windows-cloudwatch-agent-config.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
--- | ||
schemaVersion: "2.2" | ||
description: Ensure Cloudwatch agent is installed and configured | ||
parameters: | ||
optionalConfigurationLocation: | ||
description: name of ssm parameter that contains the CW Agent config | ||
type: String | ||
default: "cloud-watch-config-windows" | ||
mainSteps: | ||
- name: installCWAgent | ||
action: aws:runDocument | ||
inputs: | ||
documentType: SSMDocument | ||
documentPath: AWS-ConfigureAWSPackage | ||
documentParameters: | ||
action: Install | ||
name: AmazonCloudWatchAgent | ||
- name: configureCWAgent | ||
action: aws:runDocument | ||
inputs: | ||
documentType: SSMDocument | ||
documentPath: AmazonCloudWatch-ManageAgent | ||
documentParameters: | ||
action: configure | ||
mode: ec2 | ||
optionalConfigurationSource: ssm | ||
optionalConfigurationLocation: "{{ optionalConfigurationLocation }}" | ||
optionalRestart: "yes" |
Oops, something went wrong.