diff --git a/sdk/cosmos/test-resources.bicep b/sdk/cosmos/test-resources.bicep new file mode 100644 index 000000000000..d2f4bd657905 --- /dev/null +++ b/sdk/cosmos/test-resources.bicep @@ -0,0 +1,66 @@ +param baseName string + +@description('Flag to enable or disable multiple write locations on CosmosDB Account') +param enableMultipleWriteLocations bool + +@description('Default Cosmosdb Account level consistency') +param defaultConsistencyLevel string = 'Session' + +@description('Enable multiple regions, default value is false') +param enableMultipleRegions bool = false + +@description('Location for the Cosmos DB account.') +param location string = resourceGroup().location + +@description('The api version to be used by Bicep to create resources') +param apiVersion string = '2020-04-01' + +var accountName = toLower(baseName) +var resourceId = cosmosAccount.id +var singleRegionConfiguration = [ + { + locationName: 'East US 2' + provisioningState: 'Succeeded' + failoverPriority: 0 + isZoneRedundant: false + } +] +var multiRegionConfiguration = [ + { + locationName: 'East US 2' + provisioningState: 'Succeeded' + failoverPriority: 0 + isZoneRedundant: false + } + { + locationName: 'East US' + provisioningState: 'Succeeded' + failoverPriority: 1 + isZoneRedundant: false + } +] +var locationsConfiguration = (enableMultipleRegions ? multiRegionConfiguration : singleRegionConfiguration) + +resource cosmosAccount 'Microsoft.DocumentDB/databaseAccounts@2020-04-01' = { + name: toLower(accountName) + location: location + kind: 'GlobalDocumentDB' + properties: { + publicNetworkAccess: 'Enabled' + enableAutomaticFailover: false + enableMultipleWriteLocations: enableMultipleWriteLocations + isVirtualNetworkFilterEnabled: false + disableKeyBasedMetadataWriteAccess: false + enableFreeTier: false + enableAnalyticalStorage: false + databaseAccountOfferType: 'Standard' + consistencyPolicy: { + defaultConsistencyLevel: defaultConsistencyLevel + } + locations: locationsConfiguration + } +} + + +output ACCOUNT_HOST string = reference(resourceId, apiVersion).documentEndpoint +output ACCOUNT_KEY string = listKeys(resourceId, apiVersion).primaryMasterKey diff --git a/sdk/cosmos/tests.yml b/sdk/cosmos/tests.yml index 55a530ce2394..56fba72fe30f 100644 --- a/sdk/cosmos/tests.yml +++ b/sdk/cosmos/tests.yml @@ -3,29 +3,12 @@ trigger: none stages: - template: ../../eng/pipelines/templates/stages/archetype-sdk-tests.yml parameters: + CloudConfig: + Cosmos_Public: + SubscriptionConfigurations: + - $(sub-config-azure-cloud-test-resources) + - $(sub-config-cosmos-azure-cloud-test-resources) + Clouds: 'Cosmos_Public' MaxParallel: 1 + BuildTargetingString: azure-cosmos ServiceDirectory: cosmos - TestMarkArgument: not globaldb - EnvVars: - ACCOUNT_KEY: $(python-cosmos-live-account-key) - ACCOUNT_HOST: $(python-cosmos-live-account-host) - - # Workaround to ensure deletion of databases from a statically defined - # CosmosDB account. - PreSteps: - - pwsh: | - $testDatabaseId = "Python Test Database " + (New-Guid).ToString() - Write-Host Test Database ID: $testDatabaseId - Write-Host "##vso[task.setvariable variable=COSMOS_TEST_DATABASE_ID]$testDatabaseId" - displayName: Set COSMOS_TEST_DATABASE_ID - PostSteps: - - pwsh: > - az cosmosdb sql database delete - --db-name $env:COSMOS_TEST_DATABASE_ID - --url-connection $(python-cosmos-live-account-host) - --key $(python-cosmos-live-account-key) - ignoreLASTEXITCODE: true - # Always clean up the database (works when a build is canceled) - condition: always() - displayName: Cleanup test database -