-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.bicep
134 lines (120 loc) · 3 KB
/
main.bicep
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
targetScope = 'resourceGroup'
/*** PARAMETERS ***/
@description('The region for all resources to be deployed into. Defaults to the resource group\'s location for highest reliability.')
param location string = resourceGroup().location
@description('The Spot VM ssh public key')
param sshPublicKey string
@description('The Spot Subnet Resource Id')
param snetId string
@description('The Storage Queue Data Message Processor Role Assigment name')
param raName string
/*** EXISTING RESOURCES ***/
resource ga 'Microsoft.Compute/galleries@2022-01-03' existing = {
name: 'ga'
resource app 'applications' existing = {
name: 'app'
resource ver 'versions' existing = {
name: '0.1.0'
}
}
}
resource miSpot 'Microsoft.ManagedIdentity/userAssignedIdentities@2018-11-30' existing = {
name: 'mi-spot'
}
// Grant the User assigned identity with Storage Queue Data Message Processor Role permissions.
resource sqMiSpotVMStorageQueueDataMessageProcessorRole_roleAssignment 'Microsoft.Authorization/roleAssignments@2022-04-01' existing = {
name: raName
}
/*** RESOURCES ***/
resource nic 'Microsoft.Network/networkInterfaces@2021-08-01' = {
name: 'nic-spot'
location: location
properties: {
ipConfigurations: [
{
name: 'ipconfig'
properties: {
subnet: {
id: snetId
}
privateIPAllocationMethod: 'Dynamic'
}
}
]
}
}
resource vm 'Microsoft.Compute/virtualMachines@2022-03-01' = {
name: 'vm-spot'
location: location
identity: {
type: 'UserAssigned'
userAssignedIdentities: {
'${miSpot.id}': {}
}
}
properties: {
hardwareProfile: {
vmSize: 'Standard_D2s_v3'
}
storageProfile: {
osDisk: {
createOption: 'FromImage'
managedDisk: {
storageAccountType: 'Premium_LRS'
}
}
imageReference: {
publisher: 'Canonical'
offer: '0001-com-ubuntu-server-jammy'
sku: '22_04-lts-gen2'
version: 'latest'
}
}
networkProfile: {
networkInterfaces: [
{
id: nic.id
}
]
}
osProfile: {
computerName: 'spot'
#disable-next-line adminusername-should-not-be-literal
adminUsername: 'azureuser'
linuxConfiguration: {
disablePasswordAuthentication: true
ssh: {
publicKeys: [
{
keyData: sshPublicKey
path: '/home/azureuser/.ssh/authorized_keys'
}
]
}
}
secrets: []
}
diagnosticsProfile: {
bootDiagnostics: {
enabled: false
}
}
priority: 'Spot'
evictionPolicy: 'Deallocate'
billingProfile: {
maxPrice: -1
}
applicationProfile: {
galleryApplications: [
{
packageReferenceId: ga::app::ver.id
enableAutomaticUpgrade: false
treatFailureAsDeploymentFailure: false
}
]
}
}
dependsOn: [
sqMiSpotVMStorageQueueDataMessageProcessorRole_roleAssignment
]
}