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

Sync eng/common directory with azure-sdk-tools for PR 1408 #18745

Merged
merged 2 commits into from
Feb 13, 2021
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
21 changes: 17 additions & 4 deletions eng/common/TestResources/New-TestResources.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -200,19 +200,32 @@ try {
# Make sure the user is logged in to create a service principal.
$context = Get-AzContext;
if (!$context) {
Log "You are not logged in; connecting to 'Azure SDK Developer Playground'"
$subscriptionName = $SubscriptionId

# Use cache of well-known team subs without having to be authenticated.
$wellKnownSubscriptions = @{
'faa080af-c1d8-40ad-9cce-e1a450ca5b57' = 'Azure SDK Developer Playground'
'a18897a6-7e44-457d-9260-f2854c0aca42' = 'Azure SDK Engineering System'
'2cd617ea-1866-46b1-90e3-fffb087ebf9b' = 'Azure SDK Test Resources'
}

if ($wellKnownSubscriptions.ContainsKey($SubscriptionId)) {
$subscriptionName = '{0} ({1})' -f $wellKnownSubscriptions[$SubscriptionId], $SubscriptionId
}

Log "You are not logged in; connecting to $subscriptionName"
$context = (Connect-AzAccount -Subscription $SubscriptionId).Context
}

# If no test application ID is specified during an interactive session, create a new service principal.
if (!$TestApplicationId) {

# Cache the created service principal in this session for frequent reuse.
$servicePrincipal = if ($AzureTestPrincipal) {
Log "TestApplicationId was not specified; loading the cached service principal"
$servicePrincipal = if ($AzureTestPrincipal -and (Get-AzADServicePrincipal -ApplicationId $AzureTestPrincipal.ApplicationId)) {
Log "TestApplicationId was not specified; loading cached service principal '$($AzureTestPrincipal.ApplicationId)'"
$AzureTestPrincipal
} else {
Log "TestApplicationId was not specified; creating a new service principal"
Log 'TestApplicationId was not specified; creating a new service principal'
$global:AzureTestPrincipal = New-AzADServicePrincipal -Role Owner

Log "Created service principal '$AzureTestPrincipal'"
Expand Down
12 changes: 3 additions & 9 deletions eng/common/TestResources/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ scenarios as well as on hosted agents for continuous integration testing.
## On the Desktop

To set up your Azure account to run live tests, you'll need to log into Azure,
create a service principal, and set up your resources defined in
test-resources.json as shown in the following example using Azure Search.
and set up your resources defined in test-resources.json as shown in the following
example using Azure Search. The script will create a service principal automatically,
or you may create a service principal you can save and reuse subsequently.

Note that `-Subscription` is an optional parameter but recommended if your account
is a member of multiple subscriptions.
Expand Down Expand Up @@ -80,13 +81,6 @@ you can remove the test resources you created above by running:
Remove-TestResources.ps1 -BaseName 'myusername' -Force
```

If you created a new service principal as shown above, you might also remove it:

```powershell
Remove-AzADServicePrincipal -ApplicationId $sp.ApplicationId -Force

```

If you persisted environment variables, you should also remove those as well.

Some test-resources.json templates utilize the `AdditionalParameters` parameter to control additional resource configuration options. For example:
Expand Down