diff --git a/eng/common/TestResources/New-TestResources.ps1 b/eng/common/TestResources/New-TestResources.ps1 index 0c63c29d7..0f997fd1e 100644 --- a/eng/common/TestResources/New-TestResources.ps1 +++ b/eng/common/TestResources/New-TestResources.ps1 @@ -92,6 +92,9 @@ param ( [Parameter()] [switch] $SuppressVsoCommands = ($null -eq $env:SYSTEM_TEAMPROJECTID), + [Parameter()] + [switch] $UserAuth, + # Captures any arguments not declared here (no parameter errors) # This enables backwards compatibility with old script versions in # hotfix branches if and when the dynamic subscription configuration @@ -611,8 +614,17 @@ try { } } + if ($UserAuth) { + if ($TestApplicationId) { + Write-Warning "The specified TestApplicationId '$TestApplicationId' will be ignored when UserAuth is set." + } + + $TestApplicationOid = (Get-AzADUser -UserPrincipalName (Get-AzContext).Account).Id + $TestApplicationId = $testApplicationOid + Log "User-based app id '$TestApplicationId' will be used." + } # If no test application ID was specified during an interactive session, create a new service principal. - if (!$CI -and !$TestApplicationId) { + elseif (!$CI -and !$TestApplicationId) { # Cache the created service principal in this session for frequent reuse. $servicePrincipal = if ($AzureTestPrincipal -and (Get-AzADServicePrincipal -ApplicationId $AzureTestPrincipal.AppId) -and $AzureTestSubscription -eq $SubscriptionId) { Log "TestApplicationId was not specified; loading cached service principal '$($AzureTestPrincipal.AppId)'" @@ -1001,6 +1013,14 @@ The environment file will be named for the test resources template that it was generated for. For ARM templates, it will be test-resources.json.env. For Bicep templates, test-resources.bicep.env. +.PARAMETER UserAuth +Create the resource group and deploy the template using the signed in user's credentials. +No service principal will be created or used. + +The environment file will be named for the test resources template that it was +generated for. For ARM templates, it will be test-resources.json.env. For +Bicep templates, test-resources.bicep.env. + .PARAMETER SuppressVsoCommands By default, the -CI parameter will print out secrets to logs with Azure Pipelines log commands that cause them to be redacted. For CI environments that don't support this (like diff --git a/eng/common/TestResources/New-TestResources.ps1.md b/eng/common/TestResources/New-TestResources.ps1.md index a18e2e5b8..b09ba04df 100644 --- a/eng/common/TestResources/New-TestResources.ps1.md +++ b/eng/common/TestResources/New-TestResources.ps1.md @@ -15,21 +15,25 @@ Deploys live test resources defined for a service directory to Azure. ### Default (Default) ``` New-TestResources.ps1 [-BaseName ] [-ResourceGroupName ] [-ServiceDirectory] - [-TestApplicationId ] [-TestApplicationSecret ] [-TestApplicationOid ] - [-SubscriptionId ] [-DeleteAfterHours ] [-Location ] [-Environment ] - [-ArmTemplateParameters ] [-AdditionalParameters ] [-EnvironmentVariables ] - [-CI] [-Force] [-OutFile] [-SuppressVsoCommands] [-WhatIf] [-Confirm] [] + [-TestResourcesDirectory ] [-TestApplicationId ] [-TestApplicationSecret ] + [-TestApplicationOid ] [-SubscriptionId ] [-DeleteAfterHours ] [-Location ] + [-Environment ] [-ResourceType ] [-ArmTemplateParameters ] + [-AdditionalParameters ] [-EnvironmentVariables ] [-CI] [-Force] [-OutFile] + [-SuppressVsoCommands] [-UserAuth] [-NewTestResourcesRemainingArguments ] + [-ProgressAction ] [-WhatIf] [-Confirm] [] ``` ### Provisioner ``` New-TestResources.ps1 [-BaseName ] [-ResourceGroupName ] [-ServiceDirectory] - [-TestApplicationId ] [-TestApplicationSecret ] [-TestApplicationOid ] - -TenantId [-SubscriptionId ] -ProvisionerApplicationId + [-TestResourcesDirectory ] [-TestApplicationId ] [-TestApplicationSecret ] + [-TestApplicationOid ] -TenantId [-SubscriptionId ] + -ProvisionerApplicationId [-ProvisionerApplicationOid ] -ProvisionerApplicationSecret [-DeleteAfterHours ] [-Location ] - [-Environment ] [-ArmTemplateParameters ] [-AdditionalParameters ] - [-EnvironmentVariables ] [-CI] [-Force] [-OutFile] [-SuppressVsoCommands] [-WhatIf] [-Confirm] - [] + [-Environment ] [-ResourceType ] [-ArmTemplateParameters ] + [-AdditionalParameters ] [-EnvironmentVariables ] [-CI] [-Force] [-OutFile] + [-SuppressVsoCommands] [-UserAuth] [-NewTestResourcesRemainingArguments ] + [-ProgressAction ] [-WhatIf] [-Confirm] [] ``` ## DESCRIPTION @@ -206,8 +210,10 @@ Accept wildcard characters: False A directory under 'sdk' in the repository root - optionally with subdirectories specified - in which to discover ARM templates named 'test-resources.json' and Bicep templates named 'test-resources.bicep'. -This can also be an absolute path +This can be an absolute path or specify parent directories. +ServiceDirectory is also used for resource and +environment variable naming. ```yaml Type: String @@ -221,6 +227,24 @@ Accept pipeline input: False Accept wildcard characters: False ``` +### -TestResourcesDirectory +An override directory in which to discover ARM templates named 'test-resources.json' and +Bicep templates named 'test-resources.bicep'. +This can be an absolute path +or specify parent directories. + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + ### -TestApplicationId Optional Azure Active Directory Application ID to authenticate the test runner against deployed resources. @@ -376,6 +400,21 @@ Accept pipeline input: False Accept wildcard characters: False ``` +### -ProvisionerApplicationOid +{{ Fill ProvisionerApplicationOid Description }} + +```yaml +Type: String +Parameter Sets: Provisioner +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + ### -ProvisionerApplicationSecret A service principal secret (password) used to provision test resources when a provisioner is specified. @@ -456,6 +495,21 @@ Accept pipeline input: False Accept wildcard characters: False ``` +### -ResourceType +{{ Fill ResourceType Description }} + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: Test +Accept pipeline input: False +Accept wildcard characters: False +``` + ### -ArmTemplateParameters Optional key-value pairs of parameters to pass to the ARM template(s). @@ -560,7 +614,7 @@ Accept wildcard characters: False ### -SuppressVsoCommands By default, the -CI parameter will print out secrets to logs with Azure Pipelines log commands that cause them to be redacted. -For CI environments that don't support this (like +For CI environments that don't support this (like stress test clusters), this flag can be set to $false to avoid printing out these secrets to the logs. ```yaml @@ -575,6 +629,46 @@ Accept pipeline input: False Accept wildcard characters: False ``` +### -UserAuth +Create the resource group and deploy the template using the signed in user's credentials. +No service principal will be created or used. + +The environment file will be named for the test resources template that it was +generated for. +For ARM templates, it will be test-resources.json.env. +For +Bicep templates, test-resources.bicep.env. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: False +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -NewTestResourcesRemainingArguments +Captures any arguments not declared here (no parameter errors) +This enables backwards compatibility with old script versions in +hotfix branches if and when the dynamic subscription configuration +secrets get updated to add new parameters. + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + ### -WhatIf Shows what would happen if the cmdlet runs. The cmdlet is not run. @@ -606,6 +700,21 @@ Accept pipeline input: False Accept wildcard characters: False ``` +### -ProgressAction +{{ Fill ProgressAction Description }} + +```yaml +Type: ActionPreference +Parameter Sets: (All) +Aliases: proga + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + ### CommonParameters This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](https://go.microsoft.com/fwlink/?LinkID=113216).