From 7730d091234d8145d520a78cd42d6fa4bea71aca Mon Sep 17 00:00:00 2001 From: Azad Abbasi Date: Wed, 22 Sep 2021 13:34:43 -0700 Subject: [PATCH] Remove ARM template to reduce overhead. (#24270) --- .../prerequisite/prerequisite readme.md | 2 +- .../src/test/resources/prerequisite/setup.ps1 | 9 +- sdk/digitaltwins/test-resources.json | 143 ------------------ 3 files changed, 9 insertions(+), 145 deletions(-) delete mode 100644 sdk/digitaltwins/test-resources.json diff --git a/sdk/digitaltwins/azure-digitaltwins-core/src/test/resources/prerequisite/prerequisite readme.md b/sdk/digitaltwins/azure-digitaltwins-core/src/test/resources/prerequisite/prerequisite readme.md index 31822a792c68b..58463c94f87ee 100644 --- a/sdk/digitaltwins/azure-digitaltwins-core/src/test/resources/prerequisite/prerequisite readme.md +++ b/sdk/digitaltwins/azure-digitaltwins-core/src/test/resources/prerequisite/prerequisite readme.md @@ -30,7 +30,7 @@ The script outputs [test-resources.bicep](https://github.com/Azure/azure-sdk-for ### Generate the ARM template -The ARM template [test-resources.json](https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/digitaltwins/test-resources.json) is generated from the [test-resources.bicep](https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/digitaltwins/test-resources.bicep) file by running the following script +The ARM template is generated from the [test-resources.bicep](https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/digitaltwins/test-resources.bicep) file by running the following script - `.\generateArmTemplate.ps1` diff --git a/sdk/digitaltwins/azure-digitaltwins-core/src/test/resources/prerequisite/setup.ps1 b/sdk/digitaltwins/azure-digitaltwins-core/src/test/resources/prerequisite/setup.ps1 index fc768d2540607..ae150b05f9b68 100644 --- a/sdk/digitaltwins/azure-digitaltwins-core/src/test/resources/prerequisite/setup.ps1 +++ b/sdk/digitaltwins/azure-digitaltwins-core/src/test/resources/prerequisite/setup.ps1 @@ -82,13 +82,17 @@ if ($rgExists -eq "False") az group create --name $ResourceGroup --location $Region --output none } +Write-Host "`nGenerating the ARM template using the cli bicep extention." +$bicepFilePath = Join-Path -Path $PSScriptRoot -ChildPath "../../../../../test-resources.bicep"; +az bicep build --f $bicepFilePath + Write-Host "`nDeploying resources to $ResourceGroup in $Region`n" $armTemplateFile = Join-Path -Path $PSScriptRoot -ChildPath "../../../../../test-resources.json"; if (-not (Test-Path $armTemplateFile -PathType leaf)) { - throw "`nARM template was not found. Please make sure you have an ARM template file named test-resources.json in the root of the service directory`n" + throw "`nARM template was not found. Please make sure you have a bicep file called test-resources.bicep in the root of the service directory`n" } # Deploy test-resources.json ARM template. @@ -128,4 +132,7 @@ $protectedBytes = [Security.Cryptography.ProtectedData]::Protect($bytes, $null, Set-Content $outputFile -Value $protectedBytes -AsByteStream -Force Write-Host "`nTest environment settings stored into encrypted $outputFile`n" +Write-Host "`nRemoving generated ARM template JSON file." +rm -r $armTemplateFile + Write-Host "Done!" diff --git a/sdk/digitaltwins/test-resources.json b/sdk/digitaltwins/test-resources.json deleted file mode 100644 index bec784dcde9da..0000000000000 --- a/sdk/digitaltwins/test-resources.json +++ /dev/null @@ -1,143 +0,0 @@ -{ - "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#", - "contentVersion": "1.0.0.0", - "metadata": { - "_generator": { - "name": "bicep", - "version": "0.4.63.48766", - "templateHash": "7080001263714194046" - } - }, - "parameters": { - "testApplicationOid": { - "type": "string", - "metadata": { - "description": "The client OID to grant access to test resources." - } - }, - "baseName": { - "type": "string", - "defaultValue": "[resourceGroup().name]", - "metadata": { - "description": "The base resource name." - }, - "maxLength": 50, - "minLength": 6 - }, - "location": { - "type": "string", - "defaultValue": "[resourceGroup().location]", - "metadata": { - "description": "The location of the resource. By default, this is the same as the resource group." - } - } - }, - "functions": [], - "variables": { - "adtOwnerRoleDefinitionId": "[format('/subscriptions/{0}/providers/Microsoft.Authorization/roleDefinitions/bcd981a7-7f74-457b-83e1-cceb9e632ffe', subscription().subscriptionId)]" - }, - "resources": [ - { - "type": "Microsoft.DigitalTwins/digitalTwinsInstances", - "apiVersion": "2020-03-01-preview", - "name": "[parameters('baseName')]", - "location": "[parameters('location')]", - "sku": { - "name": "S1" - }, - "properties": {} - }, - { - "type": "Microsoft.DigitalTwins/digitalTwinsInstances/providers/roleAssignments", - "apiVersion": "2020-03-01-preview", - "name": "[format('{0}/Microsoft.Authorization/{1}', parameters('baseName'), guid(uniqueString(parameters('baseName'))))]", - "properties": { - "roleDefinitionId": "[variables('adtOwnerRoleDefinitionId')]", - "principalId": "[parameters('testApplicationOid')]" - }, - "dependsOn": [ - "[resourceId('Microsoft.DigitalTwins/digitalTwinsInstances', parameters('baseName'))]" - ] - }, - { - "type": "Microsoft.EventHub/namespaces", - "apiVersion": "2018-01-01-preview", - "name": "[parameters('baseName')]", - "location": "[parameters('location')]", - "sku": { - "name": "Standard", - "tier": "Standard", - "capacity": 1 - }, - "properties": { - "zoneRedundant": false, - "isAutoInflateEnabled": false, - "maximumThroughputUnits": 0, - "kafkaEnabled": false - } - }, - { - "type": "Microsoft.EventHub/namespaces/eventhubs", - "apiVersion": "2017-04-01", - "name": "[format('{0}/{1}', parameters('baseName'), parameters('baseName'))]", - "properties": { - "messageRetentionInDays": 7, - "partitionCount": 4, - "status": "Active" - }, - "dependsOn": [ - "[resourceId('Microsoft.EventHub/namespaces', parameters('baseName'))]" - ] - }, - { - "type": "Microsoft.EventHub/namespaces/authorizationRules", - "apiVersion": "2017-04-01", - "name": "[format('{0}/RootManageSharedAccessKey', parameters('baseName'))]", - "properties": { - "rights": [ - "Listen", - "Manage", - "Send" - ] - }, - "dependsOn": [ - "[resourceId('Microsoft.EventHub/namespaces', parameters('baseName'))]" - ] - }, - { - "type": "Microsoft.EventHub/namespaces/eventhubs/authorizationRules", - "apiVersion": "2017-04-01", - "name": "[format('{0}/owner', format('{0}/{1}', parameters('baseName'), parameters('baseName')))]", - "properties": { - "rights": [ - "Listen", - "Manage", - "Send" - ] - }, - "dependsOn": [ - "[resourceId('Microsoft.EventHub/namespaces/eventhubs', split(format('{0}/{1}', parameters('baseName'), parameters('baseName')), '/')[0], split(format('{0}/{1}', parameters('baseName'), parameters('baseName')), '/')[1])]" - ] - }, - { - "type": "Microsoft.DigitalTwins/digitalTwinsInstances/endpoints", - "apiVersion": "2020-03-01-preview", - "name": "[format('{0}/someEventHubEndpoint', parameters('baseName'))]", - "properties": { - "endpointType": "EventHub", - "connectionString-PrimaryKey": "[listKeys(resourceId('Microsoft.EventHub/namespaces/eventhubs/authorizationRules', split(format('{0}/owner', format('{0}/{1}', parameters('baseName'), parameters('baseName'))), '/')[0], split(format('{0}/owner', format('{0}/{1}', parameters('baseName'), parameters('baseName'))), '/')[1], split(format('{0}/owner', format('{0}/{1}', parameters('baseName'), parameters('baseName'))), '/')[2]), '2017-04-01').primaryConnectionString]", - "connectionString-SecondaryKey": "[listKeys(resourceId('Microsoft.EventHub/namespaces/eventhubs/authorizationRules', split(format('{0}/owner', format('{0}/{1}', parameters('baseName'), parameters('baseName'))), '/')[0], split(format('{0}/owner', format('{0}/{1}', parameters('baseName'), parameters('baseName'))), '/')[1], split(format('{0}/owner', format('{0}/{1}', parameters('baseName'), parameters('baseName'))), '/')[2]), '2017-04-01').secondaryConnectionString]" - }, - "dependsOn": [ - "[resourceId('Microsoft.DigitalTwins/digitalTwinsInstances', parameters('baseName'))]", - "[resourceId('Microsoft.EventHub/namespaces/eventhubs/authorizationRules', split(format('{0}/owner', format('{0}/{1}', parameters('baseName'), parameters('baseName'))), '/')[0], split(format('{0}/owner', format('{0}/{1}', parameters('baseName'), parameters('baseName'))), '/')[1], split(format('{0}/owner', format('{0}/{1}', parameters('baseName'), parameters('baseName'))), '/')[2])]" - ] - } - ], - "outputs": { - "DIGITALTWINS_URL": { - "type": "string", - "value": "[format('https://{0}', reference(resourceId('Microsoft.DigitalTwins/digitalTwinsInstances', parameters('baseName'))).hostName)]" - } - } -} \ No newline at end of file