You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: common/functions/terraform.ps1
+9-5Lines changed: 9 additions & 5 deletions
Original file line number
Diff line number
Diff line change
@@ -391,13 +391,16 @@ function Get-Blobs (
391
391
Write-Verbose"Environment variable ARM_ACCESS_KEY or ARM_SAS_TOKEN not set, trying az auth"
392
392
$blobs= az storage blob list -c $BackendStorageContainerName--account-name $BackendStorageAccountName--auth-mode login --query $JmesPath|ConvertFrom-Json
393
393
if (!$blobs) {
394
-
Write-Verbose"No access to storage using KEY, SAS or SSO. Trying to obtain key..."
395
-
$storageKey= az storage account keys list -n $BackendStorageAccountName--query "[?keyName=='key1'].value"-o tsv
396
-
if ($storageKey) {
394
+
az storage account show -n $BackendStorageAccountName--query allowSharedKeyAccess -o json |ConvertFrom-Json|Set-Variable allowSharedKeyAccess
395
+
Write-Verbose"No access to storage using KEY or SAS"
396
+
if ($allowSharedKeyAccess) {
397
+
Write-Verbose"Trying to obtain key..."
398
+
$storageKey= az storage account keys list -n $BackendStorageAccountName--query "[?keyName=='key1'].value"-o tsv
397
399
$blobs= az storage blob list -c $BackendStorageContainerName--account-name $BackendStorageAccountName--account-key $storageKey--query $JmesPath|ConvertFrom-Json
398
400
} else {
399
-
Write-Error"Insufficient permissions (set environment variable ARM_SAS_TOKEN or ARM_ACCESS_KEY)"
400
-
return
401
+
Write-Verbose"Trying with Azure RBAC permission..."
402
+
Write-Debug"az storage blob list -c $BackendStorageContainerName --account-name $BackendStorageAccountName --query $JmesPath"
403
+
$blobs= az storage blob list -c $BackendStorageContainerName--account-name $BackendStorageAccountName--auth-mode login --query $JmesPath|ConvertFrom-Json
401
404
}
402
405
}
403
406
}
@@ -630,6 +633,7 @@ function Unlock-TerraformState (
630
633
if (!$ticks) {
631
634
Write-Verbose"No access to storage using KEY, SAS or SSO. Trying to obtain key..."
632
635
$storageKey= az storage account keys list -n $BackendStorageAccountName--query "[?keyName=='key1'].value"-o tsv
636
+
Write-Debug"Storage Key: $storageKey"
633
637
if ($storageKey) {
634
638
$ticks= az storage blob lease break-b $blobName-c $backendStorageContainerName--account-name $BackendStorageAccountName--account-key $storageKey
0 commit comments