diff --git a/tests/templates/cosmosdb.bicep b/tests/templates/cosmosdb.bicep new file mode 100644 index 00000000..406d6a39 --- /dev/null +++ b/tests/templates/cosmosdb.bicep @@ -0,0 +1,25 @@ +param python_version string +param location string = resourceGroup().location + +var cosmosdb_name = 'python-worker-${python_version}-cdb' + +resource cosmosdb 'Microsoft.DocumentDB/databaseAccounts@2022-08-15' = { + name: cosmosdb_name + kind: 'GlobalDocumentDB' + location: location + properties: { + consistencyPolicy: { defaultConsistencyLevel: 'Session' } + locations: [ + { + locationName: location + failoverPriority: 0 + isZoneRedundant: false + } + ] + databaseAccountOfferType: 'Standard' + enableAutomaticFailover: false + enableMultipleWriteLocations: false + apiProperties: {} + capabilities: [ { name: 'EnableServerless' } ] + } +} diff --git a/tests/templates/deploy_templates.py b/tests/templates/deploy_templates.py new file mode 100644 index 00000000..83b0d861 --- /dev/null +++ b/tests/templates/deploy_templates.py @@ -0,0 +1,58 @@ +import os +import re +import subprocess + +subscription_id = "0b894477-1614-4c8d-8a9b-a697a24596b8" +resource_group = "AzureFunctionsPythonWorkerCILinuxDevOps" + + +def deploy_bicep_files(): + """ + Deploy selected Bicep files compatible with the specified Python version to the given Azure resource group, + with user-provided parameters for each template. + + :param resource_group: The Azure resource group to deploy to. + :param python_version: The Python version to filter Bicep files. + """ + # Get the current working directory + directory = os.getcwd() + + python_version = input("Enter the Python version (e.g., 3.8): ") + + # Regex pattern to match files compatible with the specified Python version + pattern = ".*\\.bicep$" + + # List all Bicep files in the directory compatible with the specified Python version + all_bicep_files = [f for f in os.listdir(directory) if re.search(pattern, f)] + + if not all_bicep_files: + print(f"No Bicep files found") + return + + # Display the list of files to the user + print("Available Bicep Templates:") + for idx, file in enumerate(all_bicep_files, 1): + print(f"{idx}. {file}") + + # Ask user to select files to deploy + selected = input("Enter the numbers of the templates to deploy (comma separated), or type 'all' to deploy all: ") + if selected.lower() == 'all': + bicep_files_to_deploy = all_bicep_files + else: + selected_indices = [int(i) - 1 for i in selected.split(',') if i.isdigit()] + bicep_files_to_deploy = [all_bicep_files[i] for i in selected_indices if 0 <= i < len(all_bicep_files)] + + # Deploy the selected Bicep files + for bicep_file in bicep_files_to_deploy: + file_path = os.path.join(directory, bicep_file) + + params_string = f"--parameters python_version={python_version.replace('.', '')}" + + # Deploy the Bicep file + print(f"Deploying {bicep_file}...") + deploy_command = (f"az deployment group create --subscription {subscription_id} " + f"--resource-group {resource_group} --template-file {file_path} {params_string}") + subprocess.run(deploy_command, shell=True) + + +deploy_bicep_files() diff --git a/tests/templates/eventgrid.bicep b/tests/templates/eventgrid.bicep new file mode 100644 index 00000000..a5f71be8 --- /dev/null +++ b/tests/templates/eventgrid.bicep @@ -0,0 +1,13 @@ +param python_version string +param location string = resourceGroup().location + +var eventgrid_name = 'python-worker-${python_version}-egt' + +resource eventgrid 'Microsoft.EventGrid/topics@2023-12-15-preview' = { + name: eventgrid_name + location: location + sku: { + name: 'Basic' + } + kind: 'Azure' +} \ No newline at end of file diff --git a/tests/templates/eventhub.bicep b/tests/templates/eventhub.bicep new file mode 100644 index 00000000..694dabd5 --- /dev/null +++ b/tests/templates/eventhub.bicep @@ -0,0 +1,13 @@ +param python_version string +param location string = resourceGroup().location + +var eventhubname = 'python-worker-${python_version}-ehns' + +resource eventhub 'Microsoft.EventHub/namespaces@2022-10-01-preview' = { + name: eventhubname + location: location + sku: { + name: 'Standard' + tier: 'Standard' + } +} diff --git a/tests/templates/servicebus.bicep b/tests/templates/servicebus.bicep new file mode 100644 index 00000000..73398170 --- /dev/null +++ b/tests/templates/servicebus.bicep @@ -0,0 +1,15 @@ +param python_version string +param location string = resourceGroup().location + + +var serviceBusNamespaceName = 'python-worker-${python_version}-sbns' + +resource serviceBusNamespace 'Microsoft.ServiceBus/namespaces@2022-01-01-preview' = { + name: serviceBusNamespaceName + location: location + sku: { + name: 'Standard' + } + properties: {} +} + diff --git a/tests/templates/storage_account.bicep b/tests/templates/storage_account.bicep new file mode 100644 index 00000000..17108f90 --- /dev/null +++ b/tests/templates/storage_account.bicep @@ -0,0 +1,25 @@ +param location string = resourceGroup().location +param python_version string + +var storage_account_name = 'pythonworker${python_version}sa' + +resource storageAccount_input 'Microsoft.Storage/storageAccounts@2022-09-01' = { + name: storage_account_name + location: location + sku: { + name: 'Standard_LRS' + } + kind: 'StorageV2' + properties: { + networkAcls: { + bypass: 'AzureServices' + defaultAction: 'Allow' + } + accessTier: 'Hot' + publicNetworkAccess: 'Enabled' + dnsEndpointType: 'Standard' + allowBlobPublicAccess: true + minimumTlsVersion: 'TLS1_2' + allowSharedKeyAccess: true + } +}