forked from mspnp/aks-baseline
-
Notifications
You must be signed in to change notification settings - Fork 0
/
acr-stamp.bicep
211 lines (190 loc) · 5.36 KB
/
acr-stamp.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
205
206
207
208
209
210
211
targetScope = 'resourceGroup'
/*** PARAMETERS ***/
@description('The regional network spoke VNet Resource ID that the cluster will be joined to.')
@minLength(79)
param targetVnetResourceId string
@allowed([
'australiaeast'
'canadacentral'
'centralus'
'eastus'
'eastus2'
'westus2'
'francecentral'
'germanywestcentral'
'northeurope'
'southafricanorth'
'southcentralus'
'uksouth'
'westeurope'
'japaneast'
'southeastasia'
])
@description('AKS Service, Node Pool, and supporting services (KeyVault, App Gateway, etc) region. This needs to be the same region as the vnet provided in these parameters.')
param location string = 'eastus2'
@allowed([
'australiasoutheast'
'canadaeast'
'eastus2'
'westus'
'centralus'
'westcentralus'
'francesouth'
'germanynorth'
'westeurope'
'ukwest'
'northeurope'
'japanwest'
'southafricawest'
'northcentralus'
'eastasia'
'eastus'
'westus2'
'francecentral'
'uksouth'
'japaneast'
'southeastasia'
])
@description('For Azure resources that support native geo-redunancy, provide the location the redundant service will have its secondary. Should be different than the location parameter and ideally should be a paired region - https://docs.microsoft.com/azure/best-practices-availability-paired-regions. This region does not need to support availability zones.')
param geoRedundancyLocation string = 'centralus'
/*** VARIABLES ***/
var subRgUniqueString = uniqueString('aks', subscription().subscriptionId, resourceGroup().id)
/*** EXISTING RESOURCES ***/
resource spokeResourceGroup 'Microsoft.Resources/resourceGroups@2021-04-01' existing = {
scope: subscription()
name: '${split(targetVnetResourceId,'/')[4]}'
}
resource spokeVirtualNetwork 'Microsoft.Network/virtualNetworks@2021-05-01' existing = {
scope: spokeResourceGroup
name: '${last(split(targetVnetResourceId,'/'))}'
resource snetPrivateLinkEndpoints 'subnets@2021-05-01' existing = {
name: 'snet-privatelinkendpoints'
}
}
/*** RESOURCES ***/
// This Log Analytics workspace will be the log sink for all resources in the cluster resource group. This includes ACR, the AKS cluster, Key Vault, etc. It also is the Container Insights log sink for the AKS cluster.
resource laAks 'Microsoft.OperationalInsights/workspaces@2021-06-01' = {
name: 'la-aks-${subRgUniqueString}'
location: location
properties: {
sku: {
name: 'PerGB2018'
}
retentionInDays: 30
}
}
// Azure Container Registry will be exposed via Private Link, set up the related Private DNS zone and virtual network link to the spoke.
resource dnsPrivateZoneAcr 'Microsoft.Network/privateDnsZones@2020-06-01' = {
name: 'privatelink.azurecr.io'
location: 'global'
properties: {}
resource dnsVnetLinkAcrToSpoke 'virtualNetworkLinks@2020-06-01' = {
name: 'to_${spokeVirtualNetwork.name}'
location: 'global'
properties: {
virtualNetwork: {
id: targetVnetResourceId
}
registrationEnabled: false
}
}
}
// The Container Registry that the AKS cluster will be authorized to use to pull images.
resource acrAks 'Microsoft.ContainerRegistry/registries@2021-09-01' = {
name: 'acraks${subRgUniqueString}'
location: location
sku: {
name: 'Premium'
}
properties: {
adminUserEnabled: false
networkRuleSet: {
defaultAction: 'Deny'
ipRules: []
}
policies: {
quarantinePolicy: {
status: 'disabled'
}
trustPolicy: {
type: 'Notary'
status: 'disabled'
}
retentionPolicy: {
days: 15
status: 'enabled'
}
}
publicNetworkAccess: 'Disabled'
encryption: {
status: 'disabled'
}
dataEndpointEnabled: true
networkRuleBypassOptions: 'AzureServices'
zoneRedundancy: 'Disabled' // This Preview feature only supports three regions at this time, and eastus2's paired region (centralus), does not support this. So disabling for now.
}
resource acrReplication 'replications@2021-09-01' = {
name: geoRedundancyLocation
location: geoRedundancyLocation
properties: {}
}
}
resource acrAks_diagnosticsSettings 'Microsoft.Insights/diagnosticSettings@2021-05-01-preview' = {
name: 'default'
scope: acrAks
properties: {
workspaceId: laAks.id
metrics: [
{
timeGrain: 'PT1M'
category: 'AllMetrics'
enabled: true
}
]
logs: [
{
categoryGroup: 'allLogs'
enabled: true
}
]
}
}
// Expose Azure Container Registry via Private Link, into the cluster nodes subnet.
resource privateEndpointAcrToVnet 'Microsoft.Network/privateEndpoints@2021-05-01' = {
name: 'pe-${acrAks.name}'
location: location
dependsOn: [
acrAks::acrReplication
]
properties: {
subnet: {
id: spokeVirtualNetwork::snetPrivateLinkEndpoints.id
}
privateLinkServiceConnections: [
{
name: 'to_${spokeVirtualNetwork.name}'
properties: {
privateLinkServiceId: acrAks.id
groupIds: [
'registry'
]
}
}
]
}
resource privateDnsZoneGroupAcr 'privateDnsZoneGroups@2021-05-01' = {
name: 'default'
properties: {
privateDnsZoneConfigs: [
{
name: 'privatelink-azurecr-io'
properties: {
privateDnsZoneId: dnsPrivateZoneAcr.id
}
}
]
}
}
}
/*** OUTPUTS ***/
output containerRegistryName string = acrAks.name