Skip to content

Commit

Permalink
feat: avm/ptn/ai-platform/baseline Use VNet AVM (#3353)
Browse files Browse the repository at this point in the history
## Description

This PR is essentially a revert of
#3054, plus updating
the version of the VNet module to the latest version. The VNet module
now creates subnets as child modules, therefore we can use it instead of
creating the resources ourselves.

<!--
>Thank you for your contribution !
> Please include a summary of the change and which issue is fixed.
> Please also include the context.
> List any dependencies that are required for this change.

Fixes #123
Fixes #456
Closes #123
Closes #456
-->

## Pipeline Reference

<!-- Insert your Pipeline Status Badge below -->

| Pipeline |
| -------- |
|
[![avm.ptn.ai-platform.baseline](https://github.com/cecheta/bicep-registry-modules/actions/workflows/avm.ptn.ai-platform.baseline.yml/badge.svg?branch=vnet-module)](https://github.com/cecheta/bicep-registry-modules/actions/workflows/avm.ptn.ai-platform.baseline.yml)
|

## Type of Change

<!-- Use the checkboxes [x] on the options that are relevant. -->

- [ ] Update to CI Environment or utilities (Non-module affecting
changes)
- [x] Azure Verified Module updates:
- [ ] Bugfix containing backwards-compatible bug fixes, and I have NOT
bumped the MAJOR or MINOR version in `version.json`:
- [ ] Someone has opened a bug report issue, and I have included "Closes
#{bug_report_issue_number}" in the PR description.
- [ ] The bug was found by the module author, and no one has opened an
issue to report it yet.
- [ ] Feature update backwards compatible feature updates, and I have
bumped the MINOR version in `version.json`.
- [x] Breaking changes and I have bumped the MAJOR version in
`version.json`.
  - [ ] Update to documentation

## Checklist

- [x] I'm sure there are no other open Pull Requests for the same
update/change
- [x] I have run `Set-AVMModule` locally to generate the supporting
module files.
- [ ] My corresponding pipelines / checks run clean and green without
any errors or warnings

<!-- Please keep up to date with the contribution guide at
https://aka.ms/avm/contribute/bicep -->
  • Loading branch information
cecheta authored Sep 25, 2024
1 parent 33030a8 commit f08da65
Show file tree
Hide file tree
Showing 4 changed files with 1,644 additions and 158 deletions.
6 changes: 4 additions & 2 deletions avm/ptn/ai-platform/baseline/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,14 @@ By integrating with Microsoft Entra ID for secure identity management and utiliz
| `Microsoft.Network/privateDnsZones/SRV` | [2020-06-01](https://learn.microsoft.com/en-us/azure/templates/Microsoft.Network/2020-06-01/privateDnsZones/SRV) |
| `Microsoft.Network/privateDnsZones/TXT` | [2020-06-01](https://learn.microsoft.com/en-us/azure/templates/Microsoft.Network/2020-06-01/privateDnsZones/TXT) |
| `Microsoft.Network/privateDnsZones/virtualNetworkLinks` | [2020-06-01](https://learn.microsoft.com/en-us/azure/templates/Microsoft.Network/2020-06-01/privateDnsZones/virtualNetworkLinks) |
| `Microsoft.Network/privateEndpoints` | [2023-11-01](https://learn.microsoft.com/en-us/azure/templates/Microsoft.Network/2023-11-01/privateEndpoints) |
| `Microsoft.Network/privateEndpoints` | [2023-04-01](https://learn.microsoft.com/en-us/azure/templates/Microsoft.Network/2023-04-01/privateEndpoints) |
| `Microsoft.Network/privateEndpoints/privateDnsZoneGroups` | [2023-11-01](https://learn.microsoft.com/en-us/azure/templates/Microsoft.Network/2023-11-01/privateEndpoints/privateDnsZoneGroups) |
| `Microsoft.Network/privateEndpoints` | [2023-11-01](https://learn.microsoft.com/en-us/azure/templates/Microsoft.Network/2023-11-01/privateEndpoints) |
| `Microsoft.Network/privateEndpoints/privateDnsZoneGroups` | [2023-04-01](https://learn.microsoft.com/en-us/azure/templates/Microsoft.Network/2023-04-01/privateEndpoints/privateDnsZoneGroups) |
| `Microsoft.Network/privateEndpoints/privateDnsZoneGroups` | [2023-11-01](https://learn.microsoft.com/en-us/azure/templates/Microsoft.Network/2023-11-01/privateEndpoints/privateDnsZoneGroups) |
| `Microsoft.Network/publicIPAddresses` | [2023-09-01](https://learn.microsoft.com/en-us/azure/templates/Microsoft.Network/2023-09-01/publicIPAddresses) |
| `Microsoft.Network/virtualNetworks` | [2024-01-01](https://learn.microsoft.com/en-us/azure/templates/Microsoft.Network/virtualNetworks) |
| `Microsoft.Network/virtualNetworks/subnets` | [2024-01-01](https://learn.microsoft.com/en-us/azure/templates/Microsoft.Network/virtualNetworks/subnets) |
| `Microsoft.Network/virtualNetworks/virtualNetworkPeerings` | [2024-01-01](https://learn.microsoft.com/en-us/azure/templates/Microsoft.Network/virtualNetworks/virtualNetworkPeerings) |
| `Microsoft.OperationalInsights/workspaces` | [2023-09-01](https://learn.microsoft.com/en-us/azure/templates/Microsoft.OperationalInsights/2023-09-01/workspaces) |
| `Microsoft.RecoveryServices/vaults/backupFabrics/protectionContainers/protectedItems` | [2023-01-01](https://learn.microsoft.com/en-us/azure/templates/Microsoft.RecoveryServices/2023-01-01/vaults/backupFabrics/protectionContainers/protectedItems) |
| `Microsoft.Storage/storageAccounts` | [2022-09-01](https://learn.microsoft.com/en-us/azure/templates/Microsoft.Storage/2022-09-01/storageAccounts) |
Expand Down Expand Up @@ -1150,6 +1151,7 @@ This section gives you an overview of all local-referenced module files (i.e., o
| `br/public:avm/res/network/bastion-host:0.2.2` | Remote reference |
| `br/public:avm/res/network/network-security-group:0.3.1` | Remote reference |
| `br/public:avm/res/network/private-dns-zone:0.3.1` | Remote reference |
| `br/public:avm/res/network/virtual-network:0.4.0` | Remote reference |
| `br/public:avm/res/storage/storage-account:0.11.0` | Remote reference |

## Data Collection
Expand Down
88 changes: 39 additions & 49 deletions avm/ptn/ai-platform/baseline/main.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ var createVirtualMachine = createVirtualNetwork && virtualMachineConfiguration.?

var createDefaultNsg = virtualNetworkConfiguration.?subnet.networkSecurityGroupResourceId == null

var subnetResourceId = createVirtualNetwork ? virtualNetwork::defaultSubnet.id : null
var subnetResourceId = createVirtualNetwork ? virtualNetwork.outputs.subnetResourceIds[0] : null

var mlTargetSubResource = 'amlworkspace'

Expand Down Expand Up @@ -103,7 +103,7 @@ module storageAccount_privateDnsZones 'br/public:avm/res/network/private-dns-zon
name: zone
virtualNetworkLinks: [
{
virtualNetworkResourceId: virtualNetwork.id
virtualNetworkResourceId: virtualNetwork.outputs.resourceId
}
]
}
Expand All @@ -117,7 +117,7 @@ module workspaceHub_privateDnsZones 'br/public:avm/res/network/private-dns-zone:
name: zone
virtualNetworkLinks: [
{
virtualNetworkResourceId: virtualNetwork.id
virtualNetworkResourceId: virtualNetwork.outputs.resourceId
}
]
roleAssignments: managedIdentityName != null
Expand Down Expand Up @@ -160,47 +160,37 @@ module defaultNetworkSecurityGroup 'br/public:avm/res/network/network-security-g
}
}

// Not using the br/public:avm/res/network/virtual-network module here to
// allow consumers of the module to add subnets from outside of the module
// https://github.com/Azure/bicep-registry-modules/issues/2689
resource virtualNetwork 'Microsoft.Network/virtualNetworks@2024-01-01' = if (createVirtualNetwork) {
name: virtualNetworkConfiguration.?name ?? 'vnet-${name}'
location: location
tags: tags
properties: {
addressSpace: {
addressPrefixes: [
virtualNetworkConfiguration.?addressPrefix ?? '10.0.0.0/16'
]
}
}

resource defaultSubnet 'subnets@2024-01-01' = {
name: virtualNetworkConfiguration.?subnet.name ?? 'default'
properties: {
addressPrefix: virtualNetworkConfiguration.?subnet.addressPrefix ?? '10.0.0.0/24'
networkSecurityGroup: {
id: createDefaultNsg
? defaultNetworkSecurityGroup.outputs.resourceId
: virtualNetworkConfiguration.?subnet.networkSecurityGroupResourceId
}
}
}

resource bastionSubnet 'subnets@2024-01-01' = if (createBastion) {
name: 'AzureBastionSubnet'
properties: {
addressPrefix: bastionConfiguration.?subnetAddressPrefix ?? '10.0.1.0/26'
networkSecurityGroup: bastionConfiguration.?networkSecurityGroupResourceId != null
? {
id: bastionConfiguration.?networkSecurityGroupResourceId
}
: null
}

dependsOn: [
defaultSubnet
module virtualNetwork 'br/public:avm/res/network/virtual-network:0.4.0' = if (createVirtualNetwork) {
name: '${uniqueString(deployment().name, location)}-virtual-network'
params: {
name: virtualNetworkConfiguration.?name ?? 'vnet-${name}'
location: location
enableTelemetry: enableTelemetry
addressPrefixes: [
virtualNetworkConfiguration.?addressPrefix ?? '10.0.0.0/16'
]
subnets: union(
// The default subnet **must** be the first in the subnets array
[
{
addressPrefix: virtualNetworkConfiguration.?subnet.addressPrefix ?? '10.0.0.0/24'
name: virtualNetworkConfiguration.?subnet.name ?? 'default'
networkSecurityGroupResourceId: createDefaultNsg
? defaultNetworkSecurityGroup.outputs.resourceId
: virtualNetworkConfiguration.?subnet.networkSecurityGroupResourceId
}
],
createBastion
? [
{
addressPrefix: bastionConfiguration.?subnetAddressPrefix ?? '10.0.1.0/26'
name: 'AzureBastionSubnet'
networkSecurityGroupResourceId: bastionConfiguration.?networkSecurityGroupResourceId
}
]
: []
)
tags: tags
}
}

Expand All @@ -211,7 +201,7 @@ module bastion 'br/public:avm/res/network/bastion-host:0.2.2' = if (createBastio
location: location
skuName: bastionConfiguration.?sku ?? 'Standard'
enableTelemetry: enableTelemetry
virtualNetworkResourceId: virtualNetwork.id
virtualNetworkResourceId: virtualNetwork.outputs.resourceId
disableCopyPaste: bastionConfiguration.?disableCopyPaste
enableFileCopy: bastionConfiguration.?enableFileCopy
enableIpConnect: bastionConfiguration.?enableIpConnect
Expand Down Expand Up @@ -240,7 +230,7 @@ module virtualMachine 'br/public:avm/res/compute/virtual-machine:0.5.3' = if (cr
{
name: virtualMachineConfiguration.?nicConfigurationConfiguration.ipConfigName ?? 'nic-vm-${name}-ipconfig'
privateIPAllocationMethod: virtualMachineConfiguration.?nicConfigurationConfiguration.privateIPAllocationMethod ?? 'Dynamic'
subnetResourceId: virtualNetwork::defaultSubnet.id
subnetResourceId: virtualNetwork.outputs.subnetResourceIds[0]
}
]
}
Expand Down Expand Up @@ -600,16 +590,16 @@ output workspaceProjectResourceId string = workspaceProject.outputs.resourceId
output workspaceProjectName string = workspaceProject.outputs.name

@description('The resource ID of the virtual network.')
output virtualNetworkResourceId string = createVirtualNetwork ? virtualNetwork.id : ''
output virtualNetworkResourceId string = createVirtualNetwork ? virtualNetwork.outputs.resourceId : ''

@description('The name of the virtual network.')
output virtualNetworkName string = createVirtualNetwork ? virtualNetwork.name : ''
output virtualNetworkName string = createVirtualNetwork ? virtualNetwork.outputs.name : ''

@description('The resource ID of the subnet in the virtual network.')
output virtualNetworkSubnetResourceId string = createVirtualNetwork ? virtualNetwork::defaultSubnet.id : ''
output virtualNetworkSubnetResourceId string = createVirtualNetwork ? virtualNetwork.outputs.subnetResourceIds[0] : ''

@description('The name of the subnet in the virtual network.')
output virtualNetworkSubnetName string = createVirtualNetwork ? virtualNetwork::defaultSubnet.name : ''
output virtualNetworkSubnetName string = createVirtualNetwork ? virtualNetwork.outputs.subnetNames[0] : ''

@description('The resource ID of the Azure Bastion host.')
output bastionResourceId string = createBastion ? bastion.outputs.resourceId : ''
Expand Down
Loading

0 comments on commit f08da65

Please sign in to comment.