-
Notifications
You must be signed in to change notification settings - Fork 8
/
createorupdate.ps1
executable file
·52 lines (46 loc) · 1.84 KB
/
createorupdate.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
41
42
43
44
45
46
47
48
49
50
51
52
#!/usr/bin/env pwsh
# Runs post create commands to prep Codespace for project
# Determine directory locations (may vary based on what branch has been cloned initially)
$repoDirectory = (Split-Path $PSScriptRoot -Parent)
$terraformDirectory = Join-Path $repoDirectory "terraform"
# Get Terraform version as saved in the repo
$terraformVersion = (Get-Content $terraformDirectory/.terraform-version)
# This will be the location where we save a PowerShell profile
$profileTemplate = (Join-Path (Split-Path -Parent -Path $MyInvocation.MyCommand.Path) profile.ps1)
# Update relevant packages
sudo apt-get update
#sudo apt-get install --only-upgrade -y azure-cli powershell
if (!(Get-Command tmux -ErrorAction SilentlyContinue)) {
sudo apt-get install -y tmux
}
# Use geekzter/bootstrap-os for PowerShell setup
if (!(Test-Path ~/bootstrap-os)) {
git clone https://github.com/geekzter/bootstrap-os.git ~/bootstrap-os
} else {
git -C ~/bootstrap-os pull
# This has been run before, upgrade packages this time
sudo apt-get upgrade -y
}
. ~/bootstrap-os/common/common_setup.ps1 -NoPackages
. ~/bootstrap-os/common/functions/functions.ps1
AddorUpdateModule Posh-Git
# Get/update tfenv, for Terraform versioning
if (!(Get-Command tfenv -ErrorAction SilentlyContinue)) {
Write-Host 'Installing tfenv...'
git clone https://github.com/tfutils/tfenv.git ~/.tfenv
sudo ln -s ~/.tfenv/bin/* /usr/local/bin
} else {
Write-Host 'Installing tfenv...'
git -C ~/.tfenv pull
}
# Get the desired version of Terraform
tfenv install $terraformVersion
tfenv use $terraformVersion
# We may as well initialize Terraform
Push-Location $terraformDirectory
terraform init -upgrade
Pop-Location
# Link PowerShell Profile
if (!(Test-Path $Profile)) {
New-Item -ItemType symboliclink -Path $Profile -Target $profileTemplate -Force | Select-Object -ExpandProperty Name
}