diff --git a/docs/examples/301/deployment-script-dev-environment/containergroups.bicep b/docs/examples/301/deployment-script-dev-environment/containergroups.bicep new file mode 100644 index 00000000000..8e9f25cc71b --- /dev/null +++ b/docs/examples/301/deployment-script-dev-environment/containergroups.bicep @@ -0,0 +1,86 @@ +param name string + +@description('Specify which type of dev environment to deploy') +@allowed([ + 'AzureCLI' + 'AzurePowerShell' +]) +param type string = 'AzureCLI' + +@description('Use to overide the version to use for Azure CLI or AzurePowerShell') +param toolVersion string = '' + +@description('This is the path in the container instance where it\'s mounted to the file share.') +param mountPath string = '/mnt/azscripts/azscriptinput' + +@description('Time in second before the container instance is suspended') +param sessionTime string = '1800' + +param fileShareName string +param storageName string +param storageId string +param location string = resourceGroup().location + +// Specifies which version to use if no specific toolVersion is provided (Azure CLI latest or Azure PowerShell 5.6) +var version = (type == 'AzureCLI' && toolVersion == '' ? 'latest' : type == 'AzurePowerShell' && toolVersion == '' ? '5.6' : toolVersion) + +var azcliImage = 'mcr.microsoft.com/azure-cli:${version}' +var azpwshImage = 'mcr.microsoft.com/azuredeploymentscripts-powershell:az${version}' + +var azpwshCommand = [ + '/bin/sh' + '-c' + 'pwsh -c \'Start-Sleep -Seconds ${sessionTime}\'' +] + +var azcliCommand = [ + '/bin/bash' + '-c' + 'echo hello; sleep ${sessionTime}' +] + +resource containerGroupName 'Microsoft.ContainerInstance/containerGroups@2019-12-01' = { + name: name + location: location + properties: { + containers: [ + { + name: '${name}cg' + properties: { + image: type == 'AzureCLI' ? azcliImage : type == 'AzurePowerShell' ? azpwshImage : json('null') + resources: { + requests: { + cpu: 1 + memoryInGB: 2 + } + } + ports: [ + { + protocol: 'TCP' + port: 80 + } + ] + volumeMounts: [ + { + name: 'filesharevolume' + mountPath: mountPath + } + ] + command: type == 'AzureCLI' ? azcliCommand : type == 'AzurePowerShell' ? azpwshCommand : json('null') + } + } + ] + osType: 'Linux' + volumes: [ + { + name: 'filesharevolume' + azureFile: { + readOnly: false + shareName: fileShareName + storageAccountName: storageName + storageAccountKey: listKeys(storageId, '2019-06-01').keys[0].value + } + } + ] + } +} diff --git a/docs/examples/301/deployment-script-dev-environment/containergroups.json b/docs/examples/301/deployment-script-dev-environment/containergroups.json new file mode 100644 index 00000000000..a695b595f42 --- /dev/null +++ b/docs/examples/301/deployment-script-dev-environment/containergroups.json @@ -0,0 +1,126 @@ +{ + "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#", + "contentVersion": "1.0.0.0", + "parameters": { + "name": { + "type": "string" + }, + "type": { + "type": "string", + "defaultValue": "AzureCLI", + "allowedValues": [ + "AzureCLI", + "AzurePowerShell" + ], + "metadata": { + "description": "Specify which type of dev environment to deploy" + } + }, + "toolVersion": { + "type": "string", + "defaultValue": "", + "metadata": { + "description": "Use to overide the version to use for Azure CLI or AzurePowerShell" + } + }, + "mountPath": { + "type": "string", + "defaultValue": "/mnt/azscripts/azscriptinput", + "metadata": { + "description": "This is the path in the container instance where it's mounted to the file share." + } + }, + "sessionTime": { + "type": "string", + "defaultValue": "1800", + "metadata": { + "description": "Time in second before the container instance is suspended" + } + }, + "fileShareName": { + "type": "string" + }, + "storageName": { + "type": "string" + }, + "storageId": { + "type": "string" + }, + "location": { + "type": "string", + "defaultValue": "[resourceGroup().location]" + } + }, + "functions": [], + "variables": { + "version": "[if(and(equals(parameters('type'), 'AzureCLI'), equals(parameters('toolVersion'), '')), 'latest', if(and(equals(parameters('type'), 'AzurePowerShell'), equals(parameters('toolVersion'), '')), '5.6', parameters('toolVersion')))]", + "azcliImage": "[format('mcr.microsoft.com/azure-cli:{0}', variables('version'))]", + "azpwshImage": "[format('mcr.microsoft.com/azuredeploymentscripts-powershell:az{0}', variables('version'))]", + "azpwshCommand": [ + "/bin/sh", + "-c", + "[format('pwsh -c ''Start-Sleep -Seconds {0}''', parameters('sessionTime'))]" + ], + "azcliCommand": [ + "/bin/bash", + "-c", + "[format('echo hello; sleep {0}', parameters('sessionTime'))]" + ] + }, + "resources": [ + { + "type": "Microsoft.ContainerInstance/containerGroups", + "apiVersion": "2019-12-01", + "name": "[parameters('name')]", + "location": "[parameters('location')]", + "properties": { + "containers": [ + { + "name": "[format('{0}cg', parameters('name'))]", + "properties": { + "image": "[if(equals(parameters('type'), 'AzureCLI'), variables('azcliImage'), if(equals(parameters('type'), 'AzurePowerShell'), variables('azpwshImage'), json('null')))]", + "resources": { + "requests": { + "cpu": 1, + "memoryInGB": 2 + } + }, + "ports": [ + { + "protocol": "TCP", + "port": 80 + } + ], + "volumeMounts": [ + { + "name": "filesharevolume", + "mountPath": "[parameters('mountPath')]" + } + ], + "command": "[if(equals(parameters('type'), 'AzureCLI'), variables('azcliCommand'), if(equals(parameters('type'), 'AzurePowerShell'), variables('azpwshCommand'), json('null')))]" + } + } + ], + "osType": "Linux", + "volumes": [ + { + "name": "filesharevolume", + "azureFile": { + "readOnly": false, + "shareName": "[parameters('fileShareName')]", + "storageAccountName": "[parameters('storageName')]", + "storageAccountKey": "[listKeys(parameters('storageId'), '2019-06-01').keys[0].value]" + } + } + ] + } + } + ], + "metadata": { + "_generator": { + "name": "bicep", + "version": "dev", + "templateHash": "15599825500787498936" + } + } +} \ No newline at end of file diff --git a/docs/examples/301/deployment-script-dev-environment/main.bicep b/docs/examples/301/deployment-script-dev-environment/main.bicep new file mode 100644 index 00000000000..93e7a442a2f --- /dev/null +++ b/docs/examples/301/deployment-script-dev-environment/main.bicep @@ -0,0 +1,35 @@ +param storageName string = toLower('${take('deployscript${uniqueString(resourceGroup().id)}', 22)}st') +param containerName string = toLower('${take('deployscript${uniqueString(resourceGroup().id)}', 22)}ci') + +@description('Specify which type of dev environment to deploy') +@allowed([ + 'AzureCLI' + 'AzurePowerShell' +]) +param type string = 'AzureCLI' + +@description('Use to specify the version to use for Azure CLI or AzurePowerShell, if no version is specified latest will be used for AzCLI and 5.6 for AzPwsh') +param toolVersion string = '' + +param location string = resourceGroup().location + +module storage './storage.bicep' = { + name: '${storageName}-deploy' + params: { + name: storageName + location: location + } +} + +module container './containergroups.bicep' = { + name: '${containerName}-deploy' + params: { + name: containerName + location: location + storageName: storage.outputs.storageName + storageId: storage.outputs.resourceId + fileShareName: storage.outputs.fileShareName + type: type + toolVersion: toolVersion + } +} diff --git a/docs/examples/301/deployment-script-dev-environment/main.json b/docs/examples/301/deployment-script-dev-environment/main.json new file mode 100644 index 00000000000..a27867bd133 --- /dev/null +++ b/docs/examples/301/deployment-script-dev-environment/main.json @@ -0,0 +1,318 @@ +{ + "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#", + "contentVersion": "1.0.0.0", + "parameters": { + "storageName": { + "type": "string", + "defaultValue": "[toLower(format('{0}st', take(format('deployscript{0}', uniqueString(resourceGroup().id)), 22)))]" + }, + "containerName": { + "type": "string", + "defaultValue": "[toLower(format('{0}ci', take(format('deployscript{0}', uniqueString(resourceGroup().id)), 22)))]" + }, + "type": { + "type": "string", + "defaultValue": "AzureCLI", + "allowedValues": [ + "AzureCLI", + "AzurePowerShell" + ], + "metadata": { + "description": "Specify which type of dev environment to deploy" + } + }, + "toolVersion": { + "type": "string", + "defaultValue": "", + "metadata": { + "description": "Use to specify the version to use for Azure CLI or AzurePowerShell, if no version is specified latest will be used for AzCLI and 5.6 for AzPwsh" + } + }, + "location": { + "type": "string", + "defaultValue": "[resourceGroup().location]" + } + }, + "functions": [], + "resources": [ + { + "type": "Microsoft.Resources/deployments", + "apiVersion": "2019-10-01", + "name": "[format('{0}-deploy', parameters('storageName'))]", + "properties": { + "expressionEvaluationOptions": { + "scope": "inner" + }, + "mode": "Incremental", + "parameters": { + "name": { + "value": "[parameters('storageName')]" + }, + "location": { + "value": "[parameters('location')]" + } + }, + "template": { + "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#", + "contentVersion": "1.0.0.0", + "parameters": { + "name": { + "type": "string" + }, + "sku": { + "type": "string", + "defaultValue": "Standard_LRS", + "allowedValues": [ + "Standard_LRS", + "Standard_GRS", + "Standard_RAGRS", + "Standard_ZRS", + "Premium_LRS", + "Premium_ZRS", + "Standard_GZRS", + "Standard_RAGZRS" + ] + }, + "tier": { + "type": "string", + "defaultValue": "Standard", + "allowedValues": [ + "Standard", + "Premium" + ] + }, + "kind": { + "type": "string", + "defaultValue": "StorageV2", + "allowedValues": [ + "Storage", + "StorageV2", + "BlobStorage", + "FileStorage", + "BlockBlobStorage" + ] + }, + "accessTier": { + "type": "string", + "defaultValue": "Hot", + "allowedValues": [ + "Hot", + "Cool" + ] + }, + "fileShareName": { + "type": "string", + "defaultValue": "deployscript" + }, + "location": { + "type": "string", + "defaultValue": "[resourceGroup().id]" + } + }, + "functions": [], + "resources": [ + { + "type": "Microsoft.Storage/storageAccounts", + "apiVersion": "2019-06-01", + "name": "[parameters('name')]", + "location": "[parameters('location')]", + "sku": { + "name": "[parameters('sku')]", + "tier": "[parameters('tier')]" + }, + "kind": "[parameters('kind')]", + "properties": { + "accessTier": "[parameters('accessTier')]" + } + }, + { + "type": "Microsoft.Storage/storageAccounts/fileServices/shares", + "apiVersion": "2019-06-01", + "name": "[format('{0}/default/{1}', parameters('name'), parameters('fileShareName'))]", + "dependsOn": [ + "[resourceId('Microsoft.Storage/storageAccounts', parameters('name'))]" + ] + } + ], + "outputs": { + "resourceId": { + "type": "string", + "value": "[resourceId('Microsoft.Storage/storageAccounts', parameters('name'))]" + }, + "storageName": { + "type": "string", + "value": "[parameters('name')]" + }, + "fileShareName": { + "type": "string", + "value": "[parameters('fileShareName')]" + } + } + } + } + }, + { + "type": "Microsoft.Resources/deployments", + "apiVersion": "2019-10-01", + "name": "[format('{0}-deploy', parameters('containerName'))]", + "properties": { + "expressionEvaluationOptions": { + "scope": "inner" + }, + "mode": "Incremental", + "parameters": { + "name": { + "value": "[parameters('containerName')]" + }, + "location": { + "value": "[parameters('location')]" + }, + "storageName": { + "value": "[reference(resourceId('Microsoft.Resources/deployments', format('{0}-deploy', parameters('storageName'))), '2019-10-01').outputs.storageName.value]" + }, + "storageId": { + "value": "[reference(resourceId('Microsoft.Resources/deployments', format('{0}-deploy', parameters('storageName'))), '2019-10-01').outputs.resourceId.value]" + }, + "fileShareName": { + "value": "[reference(resourceId('Microsoft.Resources/deployments', format('{0}-deploy', parameters('storageName'))), '2019-10-01').outputs.fileShareName.value]" + }, + "type": { + "value": "[parameters('type')]" + }, + "toolVersion": { + "value": "[parameters('toolVersion')]" + } + }, + "template": { + "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#", + "contentVersion": "1.0.0.0", + "parameters": { + "name": { + "type": "string" + }, + "type": { + "type": "string", + "defaultValue": "AzureCLI", + "allowedValues": [ + "AzureCLI", + "AzurePowerShell" + ], + "metadata": { + "description": "Specify which type of dev environment to deploy" + } + }, + "toolVersion": { + "type": "string", + "defaultValue": "", + "metadata": { + "description": "Use to overide the version to use for Azure CLI or AzurePowerShell" + } + }, + "mountPath": { + "type": "string", + "defaultValue": "/mnt/azscripts/azscriptinput", + "metadata": { + "description": "This is the path in the container instance where it's mounted to the file share." + } + }, + "sessionTime": { + "type": "string", + "defaultValue": "1800", + "metadata": { + "description": "Time in second before the container instance is suspended" + } + }, + "fileShareName": { + "type": "string" + }, + "storageName": { + "type": "string" + }, + "storageId": { + "type": "string" + }, + "location": { + "type": "string", + "defaultValue": "[resourceGroup().location]" + } + }, + "functions": [], + "variables": { + "version": "[if(and(equals(parameters('type'), 'AzureCLI'), equals(parameters('toolVersion'), '')), 'latest', if(and(equals(parameters('type'), 'AzurePowerShell'), equals(parameters('toolVersion'), '')), '5.6', parameters('toolVersion')))]", + "azcliImage": "[format('mcr.microsoft.com/azure-cli:{0}', variables('version'))]", + "azpwshImage": "[format('mcr.microsoft.com/azuredeploymentscripts-powershell:az{0}', variables('version'))]", + "azpwshCommand": [ + "/bin/sh", + "-c", + "[format('pwsh -c ''Start-Sleep -Seconds {0}''', parameters('sessionTime'))]" + ], + "azcliCommand": [ + "/bin/bash", + "-c", + "[format('echo hello; sleep {0}', parameters('sessionTime'))]" + ] + }, + "resources": [ + { + "type": "Microsoft.ContainerInstance/containerGroups", + "apiVersion": "2019-12-01", + "name": "[parameters('name')]", + "location": "[parameters('location')]", + "properties": { + "containers": [ + { + "name": "[format('{0}cg', parameters('name'))]", + "properties": { + "image": "[if(equals(parameters('type'), 'AzureCLI'), variables('azcliImage'), if(equals(parameters('type'), 'AzurePowerShell'), variables('azpwshImage'), json('null')))]", + "resources": { + "requests": { + "cpu": 1, + "memoryInGB": 2 + } + }, + "ports": [ + { + "protocol": "TCP", + "port": 80 + } + ], + "volumeMounts": [ + { + "name": "filesharevolume", + "mountPath": "[parameters('mountPath')]" + } + ], + "command": "[if(equals(parameters('type'), 'AzureCLI'), variables('azcliCommand'), if(equals(parameters('type'), 'AzurePowerShell'), variables('azpwshCommand'), json('null')))]" + } + } + ], + "osType": "Linux", + "volumes": [ + { + "name": "filesharevolume", + "azureFile": { + "readOnly": false, + "shareName": "[parameters('fileShareName')]", + "storageAccountName": "[parameters('storageName')]", + "storageAccountKey": "[listKeys(parameters('storageId'), '2019-06-01').keys[0].value]" + } + } + ] + } + } + ] + } + }, + "dependsOn": [ + "[resourceId('Microsoft.Resources/deployments', format('{0}-deploy', parameters('storageName')))]" + ] + } + ], + "metadata": { + "_generator": { + "name": "bicep", + "version": "dev", + "templateHash": "6046778294530984417" + } + } +} \ No newline at end of file diff --git a/docs/examples/301/deployment-script-dev-environment/storage.bicep b/docs/examples/301/deployment-script-dev-environment/storage.bicep new file mode 100644 index 00000000000..118de215ef3 --- /dev/null +++ b/docs/examples/301/deployment-script-dev-environment/storage.bicep @@ -0,0 +1,57 @@ +param name string + +@allowed([ + 'Standard_LRS' + 'Standard_GRS' + 'Standard_RAGRS' + 'Standard_ZRS' + 'Premium_LRS' + 'Premium_ZRS' + 'Standard_GZRS' + 'Standard_RAGZRS' +]) +param sku string = 'Standard_LRS' + +@allowed([ + 'Standard' + 'Premium' +]) +param tier string = 'Standard' + +@allowed([ + 'Storage' + 'StorageV2' + 'BlobStorage' + 'FileStorage' + 'BlockBlobStorage' +]) +param kind string = 'StorageV2' + +@allowed([ + 'Hot' + 'Cool' +]) +param accessTier string = 'Hot' +param fileShareName string = 'deployscript' +param location string = resourceGroup().id + +resource storage 'Microsoft.Storage/storageAccounts@2019-06-01' = { + name: name + location: location + sku: { + name: sku + tier: tier + } + kind: kind + properties: { + accessTier: accessTier + } +} + +resource fileshare 'Microsoft.Storage/storageAccounts/fileServices/shares@2019-06-01' = { + name: '${storage.name}/default/${fileShareName}' +} + +output resourceId string = storage.id +output storageName string = storage.name +output fileShareName string = fileShareName diff --git a/docs/examples/301/deployment-script-dev-environment/storage.json b/docs/examples/301/deployment-script-dev-environment/storage.json new file mode 100644 index 00000000000..e9df0efde8b --- /dev/null +++ b/docs/examples/301/deployment-script-dev-environment/storage.json @@ -0,0 +1,104 @@ +{ + "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#", + "contentVersion": "1.0.0.0", + "parameters": { + "name": { + "type": "string" + }, + "sku": { + "type": "string", + "defaultValue": "Standard_LRS", + "allowedValues": [ + "Standard_LRS", + "Standard_GRS", + "Standard_RAGRS", + "Standard_ZRS", + "Premium_LRS", + "Premium_ZRS", + "Standard_GZRS", + "Standard_RAGZRS" + ] + }, + "tier": { + "type": "string", + "defaultValue": "Standard", + "allowedValues": [ + "Standard", + "Premium" + ] + }, + "kind": { + "type": "string", + "defaultValue": "StorageV2", + "allowedValues": [ + "Storage", + "StorageV2", + "BlobStorage", + "FileStorage", + "BlockBlobStorage" + ] + }, + "accessTier": { + "type": "string", + "defaultValue": "Hot", + "allowedValues": [ + "Hot", + "Cool" + ] + }, + "fileShareName": { + "type": "string", + "defaultValue": "deployscript" + }, + "location": { + "type": "string", + "defaultValue": "[resourceGroup().id]" + } + }, + "functions": [], + "resources": [ + { + "type": "Microsoft.Storage/storageAccounts", + "apiVersion": "2019-06-01", + "name": "[parameters('name')]", + "location": "[parameters('location')]", + "sku": { + "name": "[parameters('sku')]", + "tier": "[parameters('tier')]" + }, + "kind": "[parameters('kind')]", + "properties": { + "accessTier": "[parameters('accessTier')]" + } + }, + { + "type": "Microsoft.Storage/storageAccounts/fileServices/shares", + "apiVersion": "2019-06-01", + "name": "[format('{0}/default/{1}', parameters('name'), parameters('fileShareName'))]", + "dependsOn": [ + "[resourceId('Microsoft.Storage/storageAccounts', parameters('name'))]" + ] + } + ], + "outputs": { + "resourceId": { + "type": "string", + "value": "[resourceId('Microsoft.Storage/storageAccounts', parameters('name'))]" + }, + "storageName": { + "type": "string", + "value": "[parameters('name')]" + }, + "fileShareName": { + "type": "string", + "value": "[parameters('fileShareName')]" + } + }, + "metadata": { + "_generator": { + "name": "bicep", + "version": "dev", + "templateHash": "17166751910730401395" + } + } +} \ No newline at end of file diff --git a/docs/examples/index.json b/docs/examples/index.json index 769a3fe0c93..77619c834b8 100644 --- a/docs/examples/index.json +++ b/docs/examples/index.json @@ -494,5 +494,9 @@ { "filePath": "301/deployifnotexists-policy-with-initiative-and-assignment/main.bicep", "description": "301/deployifnotexists-policy-with-initiative-and-assignment" + }, + { + "filePath": "301/deployment-script-dev-environment/main.bicep", + "description": "301/deployment-script-dev-environment" } ]