-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Fixed what-if functionality with -QueryString parameter #14328
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 4 commits
dcff842
c608cd3
39c53f0
7731a98
313600d
3fe7d81
971ec2c
7df85e4
1584bea
0f681c6
fa42dd3
18614a8
36d8201
9639ca0
acaf849
45c4600
8853e83
dc1a2f5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -797,17 +797,36 @@ function Test-NewDeploymentWithQueryString | |
| # Setup | ||
| $rgname = Get-ResourceGroupName | ||
| $rname = Get-ResourceName | ||
| $saname = "querystringpstests" | ||
| $rglocation = "West US 2" | ||
| $subId = (Get-AzContext).Subscription.SubscriptionId | ||
|
|
||
| try | ||
| { | ||
| # Prepare our RG and basic template spec: | ||
|
|
||
| # Prepare our RG | ||
| New-AzResourceGroup -Name $rgname -Location $rglocation | ||
|
|
||
| #Prepare our Storage Account | ||
| $account = New-AzStorageAccount -ResourceGroupName $rgname -AccountName $saname -Location $rglocation -SkuName "Standard_LRS" | ||
|
|
||
| #Get StorageAccountKey | ||
| $key = (Get-AzStorageAccountKey -ResourceGroupName $rgname -AccountName $saname)| Where-Object {$_.KeyName -eq "key1"} | ||
|
|
||
| #Get StorageAccount context | ||
| $context = New-AzStorageContext -StorageAccountName $saname -StorageAccountKey $key.Value | ||
|
|
||
| #Create FileShare | ||
| New-AzStorageShare -Name "querystringshare" -Context $context | ||
|
|
||
| #Upload files to the StorageAccount | ||
| Set-AzStorageFileContent -ShareName "querystringshare" -Source "sampleLinkedTemplateParent.json" -Path "sampleLinkedTemplateParent.json" -Context $context | ||
| Set-AzStorageFileContent -ShareName "querystringshare" -Source "sampleLinkedTemplateChild.json" -Path "sampleLinkedTemplateChild.json" -Context $context | ||
|
|
||
| #Get SAStoken | ||
| $token = New-AzStorageAccountSASToken -Service File -ResourceType Service,Container,Object -Permission "r" -Context $context -ExpiryTime (Get-Date).AddMinutes(2) | ||
|
|
||
| #Create deployment | ||
| $deployment =New-AzResourceGroupDeployment -Name $rname -ResourceGroupName $rgname -TemplateUri "https://querystringtesting.blob.core.windows.net/testqsblob/linkedTemplateParent.json" -QueryString "foo" | ||
| $deployment =New-AzResourceGroupDeployment -Name $rname -ResourceGroupName $rgname -TemplateUri "https://querystringpstests.file.core.windows.net/querystringshare/sampleLinkedTemplateParent.json" -QueryString $token.Substring(1) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this URL valid? I cannot access it in my environment.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. They are urls for a storage account created during the test and deleted after it is completed. So you will not be able to access it outside of the test. But at the time of the test execution (recording), the urls are valid.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yunchi Wang (@wyunchi-ms) any idea on what is happening with this error? |
||
|
|
||
| # Assert | ||
| Assert-AreEqual Succeeded $deployment.ProvisioningState | ||
|
|
@@ -816,6 +835,7 @@ function Test-NewDeploymentWithQueryString | |
| finally | ||
| { | ||
| # Cleanup | ||
| Remove-AzStorageAccount -Force -ResourceGroupName $rgname -Name $saname; | ||
| Clean-ResourceGroup $rgname | ||
| } | ||
| } | ||
|
|
@@ -884,4 +904,62 @@ function Test-TestDeploymentFromBicepFile | |
| # Cleanup | ||
| Clean-ResourceGroup $rgname | ||
| } | ||
| } | ||
|
|
||
| <# | ||
| .SYNOPSIS | ||
| Tests what-if on a deployment from a template in a storage account using a query string. | ||
| #> | ||
| function Test-WhatIfWithQueryString | ||
| { | ||
| # Setup | ||
| $rgname = Get-ResourceGroupName | ||
| $rname = Get-ResourceName | ||
| $saname = "querystringpstests" | ||
| $rglocation = "West US 2" | ||
| $subId = (Get-AzContext).Subscription.SubscriptionId | ||
|
|
||
| try | ||
| { | ||
| # Prepare our RG | ||
| New-AzResourceGroup -Name $rgname -Location $rglocation | ||
|
|
||
| #Prepare our Storage Account | ||
| $account = New-AzStorageAccount -ResourceGroupName $rgname -AccountName $saname -Location $rglocation -SkuName "Standard_LRS" | ||
|
|
||
| #Get StorageAccountKey | ||
| $key = (Get-AzStorageAccountKey -ResourceGroupName $rgname -AccountName $saname)| Where-Object {$_.KeyName -eq "key1"} | ||
|
|
||
| #Get StorageAccount context | ||
| $context = New-AzStorageContext -StorageAccountName $saname -StorageAccountKey $key.Value | ||
|
|
||
| #Create FileShare | ||
| New-AzStorageShare -Name "querystringshare" -Context $context | ||
|
|
||
| #Upload files to the StorageAccount | ||
| Set-AzStorageFileContent -ShareName "querystringshare" -Source "sampleLinkedTemplateParent.json" -Path "sampleLinkedTemplateParent.json" -Context $context | ||
| Set-AzStorageFileContent -ShareName "querystringshare" -Source "sampleLinkedTemplateChild.json" -Path "sampleLinkedTemplateChild.json" -Context $context | ||
|
|
||
| #Get SAStoken | ||
| $token = New-AzStorageAccountSASToken -Service File -ResourceType Service,Container,Object -Permission "r" -Context $context -ExpiryTime (Get-Date).AddMinutes(3) | ||
|
|
||
| #Create deployment | ||
| $deployment =New-AzResourceGroupDeployment -Name $rname -ResourceGroupName $rgname -TemplateUri "https://querystringpstests.file.core.windows.net/querystringshare/sampleLinkedTemplateParent.json" -QueryString $token.Substring(1) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this URL valid? I cannot access it in my environment.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same reasoning as the comment below |
||
|
|
||
| # Assert | ||
| Assert-AreEqual Succeeded $deployment.ProvisioningState | ||
|
|
||
| #Run What-if | ||
| $result = New-AzResourceGroupDeployment -Name $rname -ResourceGroupName $rgname -TemplateUri "https://querystringpstests.file.core.windows.net/querystringshare/sampleLinkedTemplateParent.json" -QueryString $token.Substring(1) -WhatIf | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this URL valid? I cannot access it in my environment.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same reasoning as the comment below |
||
|
|
||
| #assert that nothing has changed. | ||
| Assert-AreEqual 0 ($result).Count | ||
| } | ||
|
|
||
| finally | ||
| { | ||
| # Cleanup | ||
| Remove-AzStorageAccount -Force -ResourceGroupName $rgname -Name $saname; | ||
| Clean-ResourceGroup $rgname | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -43,7 +43,8 @@ protected ResourceTestRunner(ITestOutputHelper output) | |
| .WithExtraRmModules(helper => new[] | ||
| { | ||
| helper.RMResourceModule, | ||
| helper.GetRMModulePath("AzureRM.Monitor.psd1") | ||
| helper.GetRMModulePath("AzureRM.Monitor.psd1"), | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yunchi Wang (@wyunchi-ms) I made the suggested changes, but now it fails with "Device not configured" |
||
| helper.GetRMModulePath("AzureRM.Storage.psd1") | ||
| }) | ||
| .WithRecordMatcher( | ||
| (ignoreResourcesClient, resourceProviders, userAgentsToIgnore) => | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add a test for this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pushed a test case