-
Notifications
You must be signed in to change notification settings - Fork 1
/
Deploy.ps1
40 lines (36 loc) · 1.54 KB
/
Deploy.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
param (
[string] $Region = "ap-southeast-2",
[switch] $SkipOpeningAwsConsole,
[switch] $Force
)
$ErrorActionPreference = "Stop"
$ProgressPreference = "SilentlyContinue"
$terraformInstalled = Get-Command "terraform" -ErrorAction "SilentlyContinue"
Push-Location
try {
Set-Location "./infra"
if($terraformInstalled) {
if(!(Test-Path ".terraform")) {
Write-Host -ForegroundColor Green "Terraform init to get terraform ready"
terraform init
}
Write-Host -ForegroundColor Green "Terraform apply to deploy PwshRaytracer in AWS"
$userArn = Read-Host "Your AWS IAM User ARN is required for setting up the SQS/SNS policies that will allow you to publish and retrieve messages from the command line. Enter your ARN e.g. 'arn:aws:iam::1122334455:user/myusername'"
if($Force) {
terraform apply -var="region=$Region" -var="iam_user_arn=$userArn" -auto-approve
} else {
terraform apply -var="region=$Region" -var="iam_user_arn=$userArn"
}
if($LASTEXITCODE -ne 0) {
Write-Error "Terraform apply failed"
}
if(!$SkipOpeningAwsConsole -and !$Force) {
Write-Host -ForegroundColor Green "Opening resource group view in the AWS console"
Start-Process "https://$Region.console.aws.amazon.com/resource-groups/group/rg-pwshraytracer?region=$Region"
}
} else {
Write-Warning "Terraform is not installed so this cannot apply the changes to your AWS account"
}
} finally {
Pop-Location
}