Skip to content
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

Add ResourceType parameter #3457

Merged
1 commit merged into from
Jun 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions eng/common/TestResources/New-TestResources.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ param (
[ValidateSet('AzureCloud', 'AzureUSGovernment', 'AzureChinaCloud', 'Dogfood')]
[string] $Environment = 'AzureCloud',

[Parameter()]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a pain, but I believe the parameter docs (the comments here and the markdown files) also need to be updated. Though to be honest, given that we don't have great automation for this, I'm inclined to delete the markdown @heaths?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will update the docs in a separate PR. I want to unblock the language repo perf test pipelines. And updating the docs is a little tricky since I'm trying to decide if I want to replace test-resources.json with test-resources.json or perf-resources.json, or something like $ResourceType-resources.json.

[ValidateSet('test', 'perf')]
[string] $ResourceType = 'test',

[Parameter()]
[hashtable] $ArmTemplateParameters,

Expand Down Expand Up @@ -223,7 +227,7 @@ function BuildBicepFile([System.IO.FileSystemInfo] $file)
}

$tmp = $env:TEMP ? $env:TEMP : [System.IO.Path]::GetTempPath()
$templateFilePath = Join-Path $tmp "test-resources.$(New-Guid).compiled.json"
$templateFilePath = Join-Path $tmp "$ResourceType-resources.$(New-Guid).compiled.json"

# Az can deploy bicep files natively, but by compiling here it becomes easier to parse the
# outputted json for mismatched parameter declarations.
Expand Down Expand Up @@ -349,7 +353,7 @@ try {
$root = [System.IO.Path]::Combine($repositoryRoot, "sdk", $ServiceDirectory) | Resolve-Path
$templateFiles = @()

'test-resources.json', 'test-resources.bicep' | ForEach-Object {
"$ResourceType-resources.json", "$ResourceType-resources.bicep" | ForEach-Object {
Write-Verbose "Checking for '$_' files under '$root'"
Get-ChildItem -Path $root -Filter "$_" -Recurse | ForEach-Object {
Write-Verbose "Found template '$($_.FullName)'"
Expand Down Expand Up @@ -586,9 +590,9 @@ try {
# Service principals in the Microsoft AAD tenant must end with an @microsoft.com domain; those in other tenants
# are not permitted to do so. Format the non-MS name so there's an assocation with the Azure SDK.
if ($TenantId -eq '72f988bf-86f1-41af-91ab-2d7cd011db47') {
$displayName = "test-resources-$($baseName)$suffix.microsoft.com"
$displayName = "$ResourceType-resources-$($baseName)$suffix.microsoft.com"
} else {
$displayName = "$($baseName)$suffix.test-resources.azure.sdk"
$displayName = "$($baseName)$suffix.$ResourceType-resources.azure.sdk"
}

$servicePrincipalWrapper = NewServicePrincipalWrapper -subscription $SubscriptionId -resourceGroup $ResourceGroupName -displayName $DisplayName
Expand Down Expand Up @@ -705,7 +709,7 @@ try {
}
}

$preDeploymentScript = $templateFile.originalFilePath | Split-Path | Join-Path -ChildPath 'test-resources-pre.ps1'
$preDeploymentScript = $templateFile.originalFilePath | Split-Path | Join-Path -ChildPath "$ResourceType-resources-pre.ps1"
if (Test-Path $preDeploymentScript) {
Log "Invoking pre-deployment script '$preDeploymentScript'"
&$preDeploymentScript -ResourceGroupName $ResourceGroupName @PSBoundParameters
Expand Down Expand Up @@ -745,7 +749,7 @@ try {

$deploymentOutputs = SetDeploymentOutputs $serviceName $context $deployment $templateFile

$postDeploymentScript = $templateFile.originalFilePath | Split-Path | Join-Path -ChildPath 'test-resources-post.ps1'
$postDeploymentScript = $templateFile.originalFilePath | Split-Path | Join-Path -ChildPath "$ResourceType-resources-post.ps1"
if (Test-Path $postDeploymentScript) {
Log "Invoking post-deployment script '$postDeploymentScript'"
&$postDeploymentScript -ResourceGroupName $ResourceGroupName -DeploymentOutputs $deploymentOutputs @PSBoundParameters
Expand Down
8 changes: 6 additions & 2 deletions eng/common/TestResources/Remove-TestResources.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ param (
[Parameter(ParameterSetName = 'ResourceGroup+Provisioner')]
[switch] $CI,

[Parameter()]
[ValidateSet('test', 'perf')]
[string] $ResourceType = 'test',

[Parameter()]
[switch] $Force,

Expand Down Expand Up @@ -198,7 +202,7 @@ Log "Selected subscription '$subscriptionName'"

if ($ServiceDirectory) {
$root = [System.IO.Path]::Combine("$PSScriptRoot/../../../sdk", $ServiceDirectory) | Resolve-Path
$preRemovalScript = Join-Path -Path $root -ChildPath 'remove-test-resources-pre.ps1'
$preRemovalScript = Join-Path -Path $root -ChildPath "remove-$ResourceType-resources-pre.ps1"
if (Test-Path $preRemovalScript) {
Log "Invoking pre resource removal script '$preRemovalScript'"

Expand All @@ -210,7 +214,7 @@ if ($ServiceDirectory) {
}

# Make sure environment files from New-TestResources -OutFile are removed.
Get-ChildItem -Path $root -Filter test-resources.json.env -Recurse | Remove-Item -Force:$Force
Get-ChildItem -Path $root -Filter "$ResourceType-resources.json.env" -Recurse | Remove-Item -Force:$Force
}

$verifyDeleteScript = {
Expand Down
2 changes: 2 additions & 0 deletions eng/common/TestResources/deploy-test-resources.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ parameters:
DeleteAfterHours: 8
Location: ''
SubscriptionConfiguration: $(sub-config-azure-cloud-test-resources)
ResourceType: test

# SubscriptionConfiguration will be splatted into the parameters of the test
# resources script. It should be JSON in the form:
Expand Down Expand Up @@ -48,6 +49,7 @@ steps:
# pass those in via the ArmTemplateParameters flag, and handle any
# additional parameters from the pipelines via AdditionalParameters
eng/common/TestResources/New-TestResources.ps1 `
-ResourceType '${{ parameters.ResourceType }}' `
-ServiceDirectory '${{ parameters.ServiceDirectory }}' `
-Location '${{ parameters.Location }}' `
-DeleteAfterHours '${{ parameters.DeleteAfterHours }}' `
Expand Down
2 changes: 2 additions & 0 deletions eng/common/TestResources/remove-test-resources.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
parameters:
ServiceDirectory: ''
SubscriptionConfiguration: $(sub-config-azure-cloud-test-resources)
ResourceType: test

# SubscriptionConfiguration will be splat into the parameters of the test
# resources script. It should be JSON in the form:
Expand All @@ -29,6 +30,7 @@ steps:

eng/common/TestResources/Remove-TestResources.ps1 `
@subscriptionConfiguration `
-ResourceType '${{ parameters.ResourceType }}' `
-ServiceDirectory "${{ parameters.ServiceDirectory }}" `
-CI `
-Force `
Expand Down