Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: module avm/res/network/nat-gateway #3341

Merged
merged 7 commits into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 63 additions & 6 deletions avm/res/network/nat-gateway/README.md
eriqua marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,10 @@ The following section provides usage examples for the module, which were used to
>**Note**: To reference the module, please use the following syntax `br/public:avm/res/network/nat-gateway:<version>`.

- [Using only defaults](#example-1-using-only-defaults)
- [Using large parameter set](#example-2-using-large-parameter-set)
- [Combine a generated and provided Public IP Prefix](#example-3-combine-a-generated-and-provided-public-ip-prefix)
- [WAF-aligned](#example-4-waf-aligned)
- [Using an existing Public IP](#example-2-using-an-existing-public-ip)
- [Using large parameter set](#example-3-using-large-parameter-set)
- [Combine a generated and provided Public IP Prefix](#example-4-combine-a-generated-and-provided-public-ip-prefix)
- [WAF-aligned](#example-5-waf-aligned)

### Example 1: _Using only defaults_

Expand Down Expand Up @@ -87,7 +88,63 @@ module natGateway 'br/public:avm/res/network/nat-gateway:<version>' = {
</details>
<p>

### Example 2: _Using large parameter set_
### Example 2: _Using an existing Public IP_

This instance deploys the module with most of its features enabled.


<details>

<summary>via Bicep module</summary>

```bicep
module natGateway 'br/public:avm/res/network/nat-gateway:<version>' = {
name: 'natGatewayDeployment'
params: {
// Required parameters
name: 'nngepip001'
zone: 1
// Non-required parameters
location: '<location>'
publicIpResourceIds: '<publicIpResourceIds>'
}
}
```

</details>
<p>

<details>

<summary>via JSON Parameter file</summary>

```json
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#",
"contentVersion": "1.0.0.0",
"parameters": {
// Required parameters
"name": {
"value": "nngepip001"
},
"zone": {
"value": 1
},
// Non-required parameters
"location": {
"value": "<location>"
},
"publicIpResourceIds": {
"value": "<publicIpResourceIds>"
}
}
}
```

</details>
<p>

### Example 3: _Using large parameter set_

This instance deploys the module with most of its features enabled.

Expand Down Expand Up @@ -287,7 +344,7 @@ module natGateway 'br/public:avm/res/network/nat-gateway:<version>' = {
</details>
<p>

### Example 3: _Combine a generated and provided Public IP Prefix_
### Example 4: _Combine a generated and provided Public IP Prefix_

This example shows how you can provide a Public IP Prefix to the module, while also generating one in the module.

Expand Down Expand Up @@ -359,7 +416,7 @@ module natGateway 'br/public:avm/res/network/nat-gateway:<version>' = {
</details>
<p>

### Example 4: _WAF-aligned_
### Example 5: _WAF-aligned_

This instance deploys the module in alignment with the best-practices of the Azure Well-Architected Framework.

Expand Down
4 changes: 2 additions & 2 deletions avm/res/network/nat-gateway/main.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ module publicIPAddresses 'br/public:avm/res/network/public-ip-address:0.5.1' = [
for (publicIPAddressObject, index) in (publicIPAddressObjects ?? []): {
name: '${uniqueString(deployment().name, location)}-NatGw-PIP-${index}'
params: {
name: contains(publicIPAddressObject, 'name') ? publicIPAddressObject.name : '${name}-pip'
name: publicIPAddressObject.?name ?? '${name}-pip'
location: location
lock: publicIPAddressObject.?lock ?? lock
diagnosticSettings: publicIPAddressObject.?diagnosticSettings
Expand Down Expand Up @@ -133,7 +133,7 @@ module publicIPPrefixes 'br/public:avm/res/network/public-ip-prefix:0.4.1' = [
for (publicIPPrefixObject, index) in (publicIPPrefixObjects ?? []): {
name: '${uniqueString(deployment().name, location)}-NatGw-Prefix-PIP-${index}'
params: {
name: contains(publicIPPrefixObject, 'name') ? publicIPPrefixObject.name : '${name}-pip'
name: publicIPPrefixObject.?name ?? '${name}-pip'
location: location
lock: publicIPPrefixObject.?lock ?? lock
prefixLength: publicIPPrefixObject.prefixLength
Expand Down
20 changes: 12 additions & 8 deletions avm/res/network/nat-gateway/main.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"metadata": {
"_generator": {
"name": "bicep",
"version": "0.29.47.4906",
"templateHash": "3430947452943320440"
"version": "0.30.3.12046",
"templateHash": "16462612640291787003"
},
"name": "NAT Gateways",
"description": "This module deploys a NAT Gateway.",
Expand Down Expand Up @@ -308,7 +308,9 @@
},
"mode": "Incremental",
"parameters": {
"name": "[if(contains(coalesce(parameters('publicIPAddressObjects'), createArray())[copyIndex()], 'name'), createObject('value', coalesce(parameters('publicIPAddressObjects'), createArray())[copyIndex()].name), createObject('value', format('{0}-pip', parameters('name'))))]",
"name": {
"value": "[coalesce(tryGet(coalesce(parameters('publicIPAddressObjects'), createArray())[copyIndex()], 'name'), format('{0}-pip', parameters('name')))]"
},
"location": {
"value": "[parameters('location')]"
},
Expand Down Expand Up @@ -1004,8 +1006,8 @@
"metadata": {
"_generator": {
"name": "bicep",
"version": "0.29.47.4906",
"templateHash": "15040145942768763519"
"version": "0.30.3.12046",
"templateHash": "9121047532434826411"
}
},
"parameters": {
Expand Down Expand Up @@ -1050,7 +1052,9 @@
},
"mode": "Incremental",
"parameters": {
"name": "[if(contains(coalesce(parameters('publicIPPrefixObjects'), createArray())[copyIndex()], 'name'), createObject('value', coalesce(parameters('publicIPPrefixObjects'), createArray())[copyIndex()].name), createObject('value', format('{0}-pip', parameters('name'))))]",
"name": {
"value": "[coalesce(tryGet(coalesce(parameters('publicIPPrefixObjects'), createArray())[copyIndex()], 'name'), format('{0}-pip', parameters('name')))]"
},
"location": {
"value": "[parameters('location')]"
},
Expand Down Expand Up @@ -1416,8 +1420,8 @@
"metadata": {
"_generator": {
"name": "bicep",
"version": "0.29.47.4906",
"templateHash": "15040145942768763519"
"version": "0.30.3.12046",
"templateHash": "9121047532434826411"
}
},
"parameters": {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
@description('Optional. The location to deploy to.')
param location string = resourceGroup().location

@description('Required. The name of the Public IP to create.')
param existingPipName string

resource existingPip 'Microsoft.Network/publicIPAddresses@2023-04-01' = {
name: existingPipName
location: location
sku: {
name: 'Standard'
tier: 'Regional'
}
properties: {
publicIPAllocationMethod: 'Static'
}
zones: [
'1'
'2'
'3'
]
}

@description('The resource ID of the existing Public IP.')
output existingPipResourceId string = existingPip.id
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
targetScope = 'subscription'

metadata name = 'Using an existing Public IP'
metadata description = 'This instance deploys the module with most of its features enabled.'
eriqua marked this conversation as resolved.
Show resolved Hide resolved

// ========== //
// Parameters //
// ========== //

@description('Optional. The name of the resource group to deploy for testing purposes.')
@maxLength(90)
param resourceGroupName string = 'dep-${namePrefix}-network.natgateway-${serviceShort}-rg'

@description('Optional. The location to deploy resources to.')
param resourceLocation string = deployment().location

@description('Optional. A short identifier for the kind of deployment. Should be kept short to not run into resource-name length-constraints.')
param serviceShort string = 'nngepip'

@description('Optional. A token to inject into the name of each resource.')
param namePrefix string = '#_namePrefix_#'

// ============ //
// Dependencies //
// ============ //

// General resources
// =================
resource resourceGroup 'Microsoft.Resources/resourceGroups@2021-04-01' = {
name: resourceGroupName
location: resourceLocation
}

module nestedDependencies 'dependencies.bicep' = {
scope: resourceGroup
name: '${uniqueString(deployment().name, resourceLocation)}-nestedDependencies'
params: {
location: resourceLocation
existingPipName: '${namePrefix}${serviceShort}001-existingpip1'

}
}


// ============== //
// Test Execution //
// ============== //

@batchSize(1)
module testDeployment '../../../main.bicep' = [
for iteration in ['init', 'idem']: {
scope: resourceGroup
name: '${uniqueString(deployment().name, resourceLocation)}-test-${serviceShort}-${iteration}'
params: {
location: resourceLocation
name: '${namePrefix}${serviceShort}001'
zone: 1
publicIpResourceIds: [nestedDependencies.outputs.existingPipResourceId]
}
}
]