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

Specify subscription ID for test resources #10983

Merged
merged 2 commits into from
Apr 2, 2020
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
14 changes: 13 additions & 1 deletion eng/New-TestResources.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ param (
[ValidateNotNullOrEmpty()]
[string] $TenantId,

[Parameter(ParameterSetName = 'Provisioner')]
[ValidatePattern('^[0-9a-f]{8}(-[0-9a-f]{4}){3}-[0-9a-f]{12}$')]
[string] $SubscriptionId,

[Parameter(ParameterSetName = 'Provisioner', Mandatory = $true)]
[ValidatePattern('^[0-9a-f]{8}(-[0-9a-f]{4}){3}-[0-9a-f]{12}$')]
[string] $ProvisionerApplicationId,
Expand Down Expand Up @@ -130,8 +134,13 @@ if ($ProvisionerApplicationId) {
$provisionerSecret = ConvertTo-SecureString -String $ProvisionerApplicationSecret -AsPlainText -Force
$provisionerCredential = [System.Management.Automation.PSCredential]::new($ProvisionerApplicationId, $provisionerSecret)

# Use the given subscription ID if provided.
$subscriptionArgs = if ($SubscriptionId) {
@{SubscriptionId = $SubscriptionId}
}

$provisionerAccount = Retry {
Connect-AzAccount -Tenant $TenantId -Credential $provisionerCredential -ServicePrincipal
Connect-AzAccount -Tenant $TenantId -Credential $provisionerCredential -ServicePrincipal @subscriptionArgs
}

$exitActions += {
Expand Down Expand Up @@ -320,6 +329,9 @@ Optional service principal secret (password) to authenticate the test runner aga
.PARAMETER TenantId
The tenant ID of a service principal when a provisioner is specified.

.PARAMETER SubscriptionId
Optional subscription ID to use for new resources when logging in as a provisioner. You can also use Set-AzContext if not provisioning.

.PARAMETER ProvisionerApplicationId
A service principal ID to provision test resources when a provisioner is specified.

Expand Down
16 changes: 15 additions & 1 deletion eng/Remove-TestResources.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ param (
[ValidateNotNullOrEmpty()]
[string] $TenantId,

[Parameter(ParameterSetName = 'Default+Provisioner')]
[Parameter(ParameterSetName = 'ResourceGroup+Provisioner')]
[ValidatePattern('^[0-9a-f]{8}(-[0-9a-f]{4}){3}-[0-9a-f]{12}$')]
[string] $SubscriptionId,

[Parameter(ParameterSetName = 'Default+Provisioner', Mandatory = $true)]
[Parameter(ParameterSetName = 'ResourceGroup+Provisioner', Mandatory = $true)]
[ValidatePattern('^[0-9a-f]{8}(-[0-9a-f]{4}){3}-[0-9a-f]{12}$')]
Expand Down Expand Up @@ -86,8 +91,14 @@ if ($ProvisionerApplicationId) {
Log "Logging into service principal '$ProvisionerApplicationId'"
$provisionerSecret = ConvertTo-SecureString -String $ProvisionerApplicationSecret -AsPlainText -Force
$provisionerCredential = [System.Management.Automation.PSCredential]::new($ProvisionerApplicationId, $provisionerSecret)

# Use the given subscription ID if provided.
$subscriptionArgs = if ($SubscriptionId) {
@{SubscriptionId = $SubscriptionId}
}

$provisionerAccount = Retry {
Connect-AzAccount -Tenant $TenantId -Credential $provisionerCredential -ServicePrincipal
Connect-AzAccount -Tenant $TenantId -Credential $provisionerCredential -ServicePrincipal @subscriptionArgs
}

$exitActions += {
Expand Down Expand Up @@ -126,6 +137,9 @@ The name of the resource group to delete.
.PARAMETER TenantId
The tenant ID of a service principal when a provisioner is specified.

.PARAMETER SubscriptionId
Optional subscription ID to use for new resources when logging in as a provisioner. You can also use Set-AzContext if not provisioning.

.PARAMETER ProvisionerApplicationId
A service principal ID to provision test resources when a provisioner is specified.

Expand Down
2 changes: 2 additions & 0 deletions eng/pipelines/templates/jobs/archetype-sdk-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ jobs:
-BaseName 'Generated'
-ServiceDirectory '${{ parameters.ServiceDirectory }}'
-TenantId '$(aad-azure-sdk-test-tenant-id)'
-SubscriptionId '$(azure-subscription-id)'
-ProvisionerApplicationId '$(aad-azure-sdk-test-client-id)'
-ProvisionerApplicationSecret '$(aad-azure-sdk-test-client-secret)'
-TestApplicationId '$(aad-azure-sdk-test-client-id)'
Expand Down Expand Up @@ -102,6 +103,7 @@ jobs:
eng/Remove-TestResources.ps1
-ResourceGroupName "${env:AZURE_RESOURCEGROUP_NAME}"
-TenantId '$(aad-azure-sdk-test-tenant-id)'
-SubscriptionId '$(azure-subscription-id)'
-ProvisionerApplicationId '$(aad-azure-sdk-test-client-id)'
-ProvisionerApplicationSecret '$(aad-azure-sdk-test-client-secret)'
-Force
Expand Down