-
Notifications
You must be signed in to change notification settings - Fork 47
/
Copy pathimport_file_shares.ps1
executable file
·46 lines (37 loc) · 1.95 KB
/
import_file_shares.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
#!/usr/bin/env pwsh
<#
.SYNOPSIS
Imports file shares into Terraform state
.DESCRIPTION
When upgrading to multi-instance (module based) model and using 'terraform apply' instead of deploy.ps1,
this is needed to reconcile Terraform state
#>
#Requires -Version 7
param (
[parameter(Mandatory=$false)][string]$ConfigurationName="primary"
)
. (Join-Path $PSScriptRoot functions.ps1)
try {
AzLogin
$tfdirectory = $(Join-Path (Get-Item $PSScriptRoot).Parent.FullName "terraform")
Push-Location $tfdirectory
$resourceGroupName = (Get-TerraformOutput "resource_group")
$storageAccount = (Get-TerraformOutput "storage_account")
$suffix = $storageAccount.Substring($storageAccount.Length-4)
if (![string]::IsNullOrEmpty($storageAccount)) {
$deletedFileShares = $(az storage share-rm list --resource-group $resourceGroupName --storage-account $storageAccountName --include-deleted --query "[?deleted]" -o json | ConvertFrom-Json)
foreach ($deletedFileShare in $deletedFileShares) {
Write-Host "Undeleting file share '$($deletedFileShare.name)'..."
az storage share-rm restore -n $deletedFileShare.name --deleted-version $deletedFileShare.version -g $resourceGroupName --storage-account $storageAccount
}
$dataShareUrl = "https://${storageAccount}.file.core.windows.net/minecraft-aci-data-${suffix}"
Import-TerraformResource -ResourceName "module.minecraft[`"$ConfigurationName`"].azurerm_storage_share.minecraft_share" -ResourceID "${dataShareUrl}"
$modePackShareUrl = "https://${storageAccount}.file.core.windows.net/minecraft-aci-modpacks-${suffix}"
Import-TerraformResource -ResourceName "module.minecraft[`"$ConfigurationName`"].azurerm_storage_share.minecraft_modpacks" -ResourceID "${modePackShareUrl}"
} else {
Write-Warning "Storage Account has not been created, nothing to do"
exit
}
} finally {
Pop-Location
}