-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.bicep
204 lines (180 loc) · 5.83 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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
@description('Name of the existing VNET to inject Cloud Shell into.')
param existingVNETName string
@description('Name of Azure Relay Namespace.')
param relayNamespaceName string
@description('Object Id of Azure Container Instance Service Principal. We have to grant this permission to create hybrid connections in the Azure Relay you specify. To get it: Get-AzADServicePrincipal -DisplayNameBeginsWith \'Azure Container Instance\'')
param azureContainerInstanceOID string
@description('Name of the subnet to use for cloud shell containers.')
param containerSubnetName string = 'cloudshellsubnet'
@description('Address space of the subnet to add for cloud shell. e.g. 10.0.1.0/26')
param containerSubnetAddressPrefix string
@description('Name of the subnet to use for private link of relay namespace.')
param relaySubnetName string = 'relaysubnet'
@description('Address space of the subnet to add for relay. e.g. 10.0.2.0/26')
param relaySubnetAddressPrefix string
@description('Name of the subnet to use for storage account.')
param storageSubnetName string = 'storagesubnet'
@description('Address space of the subnet to add for storage. e.g. 10.0.3.0/26')
param storageSubnetAddressPrefix string
@description('Name of Private Endpoint for Azure Relay.')
param privateEndpointName string = 'cloudshellRelayEndpoint'
@description('Location for all resources.')
param location string = resourceGroup().location
var networkProfileName = 'aci-networkProfile-${location}'
var contributorRoleDefinitionId = resourceId('Microsoft.Authorization/roleDefinitions', 'b24988ac-6180-42a0-ab88-20f7382dd24c')
var networkRoleDefinitionId = resourceId('Microsoft.Authorization/roleDefinitions', '4d97b98b-1d4f-4787-a291-c67834d212e7')
var privateDnsZoneName = ((toLower(environment().name) == 'azureusgovernment') ? 'privatelink.servicebus.usgovcloudapi.net' : 'privatelink.servicebus.windows.net')
var vnetResourceId = resourceId('Microsoft.Network/virtualNetworks', existingVNETName)
resource existingVNET 'Microsoft.Network/virtualNetworks@2020-04-01' existing = {
name: existingVNETName
}
resource containerSubnet 'Microsoft.Network/virtualNetworks/subnets@2020-04-01' = {
parent: existingVNET
name: containerSubnetName
properties: {
addressPrefix: containerSubnetAddressPrefix
serviceEndpoints: [
{
service: 'Microsoft.Storage'
locations: [
location
]
}
]
delegations: [
{
name: 'CloudShellDelegation'
properties: {
serviceName: 'Microsoft.ContainerInstance/containerGroups'
}
}
]
}
}
resource networkProfile 'Microsoft.Network/networkProfiles@2019-11-01' = {
name: networkProfileName
location: location
properties: {
containerNetworkInterfaceConfigurations: [
{
name: 'eth-${containerSubnetName}'
properties: {
ipConfigurations: [
{
name: 'ipconfig-${containerSubnetName}'
properties: {
subnet: {
id: containerSubnet.id
}
}
}
]
}
}
]
}
}
resource networkProfile_roleAssignment 'Microsoft.Authorization/roleAssignments@2020-04-01-preview' = {
scope: networkProfile
name: guid(networkRoleDefinitionId, azureContainerInstanceOID, networkProfile.name)
properties: {
roleDefinitionId: networkRoleDefinitionId
principalId: azureContainerInstanceOID
}
}
resource relayNamespace 'Microsoft.Relay/namespaces@2018-01-01-preview' = {
name: relayNamespaceName
location: location
sku: {
name: 'Standard'
tier: 'Standard'
}
}
resource relayNamespace_roleAssignment 'Microsoft.Authorization/roleAssignments@2020-04-01-preview' = {
scope: relayNamespace
name: guid(contributorRoleDefinitionId, azureContainerInstanceOID, relayNamespace.name)
properties: {
roleDefinitionId: contributorRoleDefinitionId
principalId: azureContainerInstanceOID
}
}
resource relaySubnet 'Microsoft.Network/virtualNetworks/subnets@2020-04-01' = {
parent: existingVNET
name: relaySubnetName
properties: {
addressPrefix: relaySubnetAddressPrefix
privateEndpointNetworkPolicies: 'Disabled'
privateLinkServiceNetworkPolicies: 'Enabled'
}
dependsOn: [
containerSubnet
]
}
resource privateEndpoint 'Microsoft.Network/privateEndpoints@2020-04-01' = {
name: privateEndpointName
location: location
properties: {
privateLinkServiceConnections: [
{
name: privateEndpointName
properties: {
privateLinkServiceId: relayNamespace.id
groupIds: [
'namespace'
]
}
}
]
subnet: {
id: relaySubnet.id
}
}
}
resource storageSubnet 'Microsoft.Network/virtualNetworks/subnets@2020-04-01' = {
parent: existingVNET
name: storageSubnetName
properties: {
addressPrefix: storageSubnetAddressPrefix
serviceEndpoints: [
{
service: 'Microsoft.Storage'
locations: [
location
]
}
]
}
dependsOn: [
relaySubnet
]
}
resource privateDnsZone 'Microsoft.Network/privateDnsZones@2020-01-01' = {
name: privateDnsZoneName
location: 'global'
}
resource privateDnsZoneARecord 'Microsoft.Network/privateDnsZones/A@2020-01-01' = {
parent: privateDnsZone
name: relayNamespaceName
properties: {
ttl: 3600
aRecords: [
{
ipv4Address: first(first(privateEndpoint.properties.customDnsConfigs).ipAddresses)
}
]
}
}
resource privateDnsZoneVnetLink 'Microsoft.Network/privateDnsZones/virtualNetworkLinks@2020-01-01' = {
parent: privateDnsZone
name: relayNamespaceName
location: 'global'
properties: {
registrationEnabled: false
virtualNetwork: {
id: vnetResourceId
}
}
}
output vnetId string = vnetResourceId
output containerSubnetId string = containerSubnet.id
output storageSubnetId string = storageSubnet.id