Skip to content

Commit b4d676b

Browse files
authored
Merge pull request #1453 from RylandDeGregory/main
Add modules to approve private endpoints, refactor existing template
2 parents 84bb32b + b7745b7 commit b4d676b

5 files changed

Lines changed: 379 additions & 492 deletions

File tree

Lines changed: 30 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,30 @@
1-
# Bicep Deployment of ACA + Private Endpoint + Azure Front Door
2-
3-
These Bicep files automate the process outlined in these two articles:
4-
5-
* [Create a private link to an Azure Container App with Azure Front Door](https://learn.microsoft.com/en-us/azure/container-apps/how-to-integrate-with-azure-front-door)
6-
* [Use a private endpoint with an Azure Container Apps environment](https://learn.microsoft.com/en-us/azure/container-apps/how-to-use-private-endpoint?pivots=azure-cli)
7-
8-
9-
# Usage
10-
11-
## Deployment
12-
13-
1. Define some variables:
14-
15-
```bash
16-
export RESOURCE_GROUP="my-resource-group"
17-
export LOCATION="centralus"
18-
```
19-
20-
21-
2. Create a resource group of your choosing:
22-
23-
```bash
24-
az group create --location $LOCATION --name $RESOURCE_GROUP
25-
```
26-
27-
28-
3. Deploy the Bicep
29-
If you want to change any of the names for any of the deployed resources please edit the top of `main-mgd-net.bicep`. After you're satisfied we start the deployment.
30-
31-
```bash
32-
az deployment group create --resource-group $RESOURCE_GROUP --template-file main-mgd-net.bicep
33-
```
34-
35-
36-
## Approving the Connection
37-
38-
As the last step you have to approve the private endpoint from AFD into ACA. This can be done by following first [listing your private endpoint](https://learn.microsoft.com/en-us/azure/container-apps/how-to-integrate-with-azure-front-door#list-private-endpoint-connections) connections, and then [approving them](https://learn.microsoft.com/en-us/azure/container-apps/how-to-integrate-with-azure-front-door#approve-the-private-endpoint-connection).
39-
40-
```bash
41-
export ENVIRONMENT_NAME=mycontainerappenv # Assuming names are kept as they are in the Bicep file
42-
43-
az network private-endpoint-connection list \
44-
--name $ENVIRONMENT_NAME \
45-
--resource-group $RESOURCE_GROUP \
46-
--type Microsoft.App/managedEnvironments
47-
48-
# Record the private endpoint connection resource ID from the response. Don't confuse this with the private endpoint ID. Replace the <PLACEHOLDER> with the private endpoint connection resource ID.
49-
az network private-endpoint-connection approve --id <PRIVATE_ENDPOINT_CONNECTION_RESOURCE_ID>
50-
```
51-
52-
53-
# NOTES
54-
55-
* Not all warnings have been eliminated in this Bicep
56-
* The connection approval is still manual, PRs welcome
1+
# Bicep Deployment of ACA + Private Endpoint + Azure Front Door
2+
3+
These Bicep files automate the process outlined in these two articles:
4+
5+
* [Create a private link to an Azure Container App with Azure Front Door](https://learn.microsoft.com/en-us/azure/container-apps/how-to-integrate-with-azure-front-door)
6+
* [Use a private endpoint with an Azure Container Apps environment](https://learn.microsoft.com/en-us/azure/container-apps/how-to-use-private-endpoint?pivots=azure-cli)
7+
8+
# Usage
9+
10+
## Deployment
11+
12+
1. Define some variables:
13+
14+
```bash
15+
export RESOURCE_GROUP="my-resource-group"
16+
export LOCATION="centralus"
17+
```
18+
19+
1. Create a Resource Group:
20+
21+
```bash
22+
az group create --location $LOCATION --name $RESOURCE_GROUP
23+
```
24+
25+
1. Deploy the Bicep Template
26+
If you want to change the name of any of the deployed resources, please edit the top of `main-mgd-net.bicep`. After you're satisfied, start the deployment.
27+
28+
```bash
29+
az deployment group create --resource-group $RESOURCE_GROUP --template-file main-mgd-net.bicep
30+
```
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
@description('Name of the Azure Container Apps environment')
2+
param environmentName string
3+
4+
@sys.description('Private Link resources that will be connected to the Azure Container Apps environment.')
5+
param containerAppsEnvironmentSharedPrivateLinks array
6+
7+
resource containerAppEnv 'Microsoft.App/managedEnvironments@2024-10-02-preview' existing = {
8+
name: environmentName
9+
}
10+
11+
resource containerAppEnvPrivateEndpointAccept 'Microsoft.App/managedEnvironments/privateEndpointConnections@2024-10-02-preview' = [for privateLink in containerAppsEnvironmentSharedPrivateLinks: {
12+
name: privateLink.name
13+
parent: containerAppEnv
14+
properties: {
15+
privateLinkServiceConnectionState: {
16+
status: 'Approved'
17+
}
18+
}
19+
}]
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
@description('Name of the Azure Container Apps environment')
2+
param environmentName string
3+
4+
resource containerAppEnv 'Microsoft.App/managedEnvironments@2024-10-02-preview' existing = {
5+
name: environmentName
6+
}
7+
8+
module containerAppsEnvironmentPrivateAccess 'containerappenv-pe-approve.bicep' = {
9+
name: 'ContainerAppsEnvironment-PrivateAccess'
10+
params: {
11+
environmentName: environmentName
12+
containerAppsEnvironmentSharedPrivateLinks: filter(containerAppEnv.properties.privateEndpointConnections, connection => connection.properties.privateLinkServiceConnectionState.status == 'Pending')
13+
}
14+
}
Lines changed: 30 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,30 @@
1-
param privateDnsZoneName string
2-
param privateEndpointName string
3-
param containerAppEnv object
4-
5-
6-
resource existingPrivateZone 'Microsoft.Network/privateDnsZones@2024-06-01' existing = {
7-
name: privateDnsZoneName
8-
}
9-
10-
resource existingPrivateEndpoint 'Microsoft.Network/privateEndpoints@2021-08-01' existing = {
11-
name: privateEndpointName
12-
}
13-
14-
15-
// use privateEndpoint.customDnsConfigs[0].ipAddresses[0] to get the private IP address
16-
// aca envs default domain containerAppEnv.properties.defaultDomain
17-
resource dnsRecordSet 'Microsoft.Network/privateDnsZones/A@2024-06-01' = {
18-
parent: existingPrivateZone
19-
name: containerAppEnv.properties.defaultDomain
20-
location: 'global'
21-
properties: {
22-
ttl: 3600
23-
aRecords: [
24-
{
25-
// we use the private endpoint IP from the subnet for our private DNS A record below
26-
ipv4Address: existingPrivateEndpoint.properties.customDnsConfigs[0].ipAddresses[0]
27-
}
28-
]
29-
}
30-
31-
}
32-
1+
param privateDnsZoneName string
2+
param privateEndpointName string
3+
param containerAppEnv object
4+
5+
6+
resource existingPrivateZone 'Microsoft.Network/privateDnsZones@2024-06-01' existing = {
7+
name: privateDnsZoneName
8+
}
9+
10+
resource existingPrivateEndpoint 'Microsoft.Network/privateEndpoints@2021-08-01' existing = {
11+
name: privateEndpointName
12+
}
13+
14+
15+
// use privateEndpoint.customDnsConfigs[0].ipAddresses[0] to get the private IP address
16+
// aca envs default domain containerAppEnv.properties.defaultDomain
17+
resource dnsRecordSet 'Microsoft.Network/privateDnsZones/A@2024-06-01' = {
18+
parent: existingPrivateZone
19+
name: containerAppEnv.properties.defaultDomain
20+
properties: {
21+
ttl: 3600
22+
aRecords: [
23+
{
24+
// we use the private endpoint IP from the subnet for our private DNS A record below
25+
ipv4Address: existingPrivateEndpoint.properties.customDnsConfigs[0].ipAddresses[0]
26+
}
27+
]
28+
}
29+
30+
}

0 commit comments

Comments
 (0)