Skip to content

Commit

Permalink
Example - ARM Template Deployment Script development environment (#1961)
Browse files Browse the repository at this point in the history
* Added example Deployment Script dev environment

* changed version to dev

* Update test baselines

Co-authored-by: Bicep Automation <bicep@noreply.github.com>
  • Loading branch information
StefanIvemo and Bicep Automation authored Mar 31, 2021
1 parent 9f64be8 commit 81fccbb
Show file tree
Hide file tree
Showing 7 changed files with 730 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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
}
}
]
}
}
Original file line number Diff line number Diff line change
@@ -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"
}
}
}
35 changes: 35 additions & 0 deletions docs/examples/301/deployment-script-dev-environment/main.bicep
Original file line number Diff line number Diff line change
@@ -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
}
}
Loading

0 comments on commit 81fccbb

Please sign in to comment.