Skip to content
Draft
Show file tree
Hide file tree
Changes from all 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
48 changes: 48 additions & 0 deletions modules/azure-nsg-nsr/.terraform-docs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
formatter: "markdown"

version: ""

Comment on lines +3 to +4
Copy link

Copilot AI Feb 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An empty version field is ambiguous. Prefer removing it entirely or pinning a specific terraform-docs version to make doc generation reproducible across environments/CI.

Suggested change
version: ""

Copilot uses AI. Check for mistakes.
header-from: docs/header.md
footer-from: docs/footer.md

recursive:
enabled: false
path: modules
include-main: true

sections:
hide: []
show: []

content: ""

output:
file: "README.MD"
mode: inject
template: |-
<!-- BEGIN_TF_DOCS -->
{{ .Content }}
<!-- END_TF_DOCS -->

output-values:
enabled: false
from: ""

sort:
enabled: true
by: name

settings:
anchor: true
color: true
default: true
description: false
escape: true
hide-empty: false
html: true
indent: 2
lockfile: true
read-comments: true
required: true
sensitive: true
type: true
163 changes: 163 additions & 0 deletions modules/azure-nsg-nsr/README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -137,3 +137,166 @@ values:
source_address_prefix: "0.0.0.0/0"
destination_address_prefix: "*"
```

<!-- BEGIN_TF_DOCS -->
# Azure Network Security Group & Rules Terraform Module

## Overview

This Terraform module allows you to create and manage an Azure Network Security Group (NSG) and its rules, with support for:
- Custom NSG and security rule definitions.
- Tag inheritance from the resource group.
- Flexible configuration for ports, protocols, and address prefixes.

## Main features
- Create an NSG with custom tags and location.
- Define multiple security rules with granular control.
- Support for both single and multiple port/address fields.
- Realistic configuration example.

## Complete usage example

### HCL
```hcl
tags_from_rg = false
tags = {
env = "Production"
}
nsg = {
name = "example-nsg"
location = "East US"
resource_group_name = "example-rg"
}
rules = {
rule1 = {
name = "AllowSSH"
priority = 100
direction = "Inbound"
access = "Allow"
protocol = "Tcp"
source_port_range = "*"
destination_port_range = "22"
source_address_prefix = "10.0.0.0/24"
destination_address_prefix = "*"
}
rule2 = {
name = "AllowHTTP"
priority = 200
direction = "Inbound"
access = "Allow"
protocol = "Tcp"
source_port_range = "*"
destination_port_range = "80"
source_address_prefix = "0.0.0.0/0"
destination_address_prefix = "*"
}
}
```

### YAML
```yaml
values:
tags_from_rg: false
tags:
env: "Production"
nsg:
name: "example-nsg"
location: "East US"
resource_group_name: "example-rg"
rules:
rule1:
name: "AllowSSH"
priority: 100
direction: "Inbound"
access: "Allow"
protocol: "Tcp"
source_port_range: "*"
destination_port_range: "22"
source_address_prefix: "10.0.0.0/24"
destination_address_prefix: "*"
rule2:
name: "AllowHTTP"
priority: 200
direction: "Inbound"
access: "Allow"
protocol: "Tcp"
source_port_range: "*"
destination_port_range: "80"
source_address_prefix: "0.0.0.0/0"
destination_address_prefix: "*"
```

## Notes
- You must provide at least one of each: `*_range` or `*_ranges` and `*_prefix` or `*_prefixes`, but not both at the same time.
- You can use `tags_from_rg` to inherit tags exclusively from the resource group.

## File structure

```
.
├── main.tf
├── variables.tf
├── outputs.tf
├── README.MD
├── CHANGELOG.md
└── docs/
├── header.md
└── footer.md
```

## Requirements

| Name | Version |
|------|---------|
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.7.0 |
| <a name="requirement_azurerm"></a> [azurerm](#requirement\_azurerm) | >= 4.16.0 |

## Providers

| Name | Version |
|------|---------|
| <a name="provider_azurerm"></a> [azurerm](#provider\_azurerm) | >= 4.16.0 |

## Modules

No modules.

## Resources

| Name | Type |
|------|------|
| [azurerm_network_security_group.this](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/network_security_group) | resource |
| [azurerm_network_security_rule.this](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/network_security_rule) | resource |
| [azurerm_resource_group.this](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/data-sources/resource_group) | data source |

## Inputs

| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| <a name="input_nsg"></a> [nsg](#input\_nsg) | Network Security Group configuration | <pre>object({<br/> name = string<br/> location = string<br/> resource_group_name = string<br/> })</pre> | n/a | yes |
| <a name="input_rules"></a> [rules](#input\_rules) | Network Security Rule configuration | <pre>map(object({<br/> name = string<br/> priority = number<br/> direction = string<br/> access = string<br/> protocol = string<br/> source_port_range = optional(string)<br/> source_port_ranges = optional(list(string))<br/> destination_port_range = optional(string)<br/> destination_port_ranges = optional(list(string))<br/> source_address_prefix = optional(string)<br/> source_address_prefixes = optional(list(string))<br/> destination_address_prefix = optional(string)<br/> destination_address_prefixes = optional(list(string))<br/> }))</pre> | n/a | yes |
| <a name="input_tags"></a> [tags](#input\_tags) | Tags to apply to resources | `map(string)` | `{}` | no |
| <a name="input_tags_from_rg"></a> [tags\_from\_rg](#input\_tags\_from\_rg) | Use resource group tags as base for module tags | `bool` | `false` | no |

## Outputs

| Name | Description |
|------|-------------|
| <a name="output_id"></a> [id](#output\_id) | OUTPUTS SECTION |
Copy link

Copilot AI Feb 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The generated Outputs table exposes a placeholder description (OUTPUTS SECTION), which is unhelpful for users. Update the corresponding output description in outputs.tf so terraform-docs produces a meaningful description (e.g., 'Network Security Group ID').

Suggested change
| <a name="output_id"></a> [id](#output\_id) | OUTPUTS SECTION |
| <a name="output_id"></a> [id](#output\_id) | Network Security Group ID |

Copilot uses AI. Check for mistakes.

## Examples

For detailed examples, refer to the [module examples](https://github.com/prefapp/tfm/tree/main/modules/azure-nsg-nsr/_examples):

- [basic](https://github.com/prefapp/tfm/tree/main/modules/azure-nsg-nsr/_examples/basic) - Network Security Group with a set of common inbound and outbound rules.

## Resources and support

- [Official Azure Network Security Group documentation](https://learn.microsoft.com/en-us/azure/virtual-network/network-security-groups-overview)
- [Terraform reference for azurerm\_network\_security\_group](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/network_security_group)
- [Terraform reference for azurerm\_network\_security\_rule](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/network_security_rule)

## Support

For issues, questions, or contributions related to this module, please visit the [repository's issue tracker](https://github.com/prefapp/tfm/issues).
<!-- END_TF_DOCS -->
39 changes: 39 additions & 0 deletions modules/azure-nsg-nsr/_examples/basic/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
module "azure_nsg_nsr" {
source = "../../"

tags_from_rg = false
tags = {
env = "Production"
}

nsg = {
name = "example-nsg"
location = "westeurope"
resource_group_name = "example-rg"
}

rules = {
rule1 = {
name = "AllowSSH"
priority = 100
direction = "Inbound"
access = "Allow"
protocol = "Tcp"
source_port_range = "*"
destination_port_range = "22"
source_address_prefix = "10.0.0.0/24"
destination_address_prefix = "*"
}
rule2 = {
name = "AllowHTTP"
priority = 200
direction = "Inbound"
access = "Allow"
protocol = "Tcp"
source_port_range = "*"
destination_port_range = "80"
source_address_prefix = "0.0.0.0/0"
destination_address_prefix = "*"
}
}
}
30 changes: 30 additions & 0 deletions modules/azure-nsg-nsr/_examples/basic/values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
tags_from_rg: false
tags:
env: Production

nsg:
name: example-nsg
location: westeurope
resource_group_name: example-rg

rules:
rule1:
name: AllowSSH
priority: 100
direction: Inbound
access: Allow
protocol: Tcp
source_port_range: "*"
destination_port_range: "22"
source_address_prefix: 10.0.0.0/24
destination_address_prefix: "*"
rule2:
name: AllowHTTP
priority: 200
direction: Inbound
access: Allow
protocol: Tcp
source_port_range: "*"
destination_port_range: "80"
source_address_prefix: 0.0.0.0/0
destination_address_prefix: "*"
Comment on lines +1 to +30
Copy link

Copilot AI Feb 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This example values.yaml format conflicts with the YAML shown in the docs/README (which uses a top-level values: key). Align the on-disk example format with the documentation to avoid copy/paste failures.

Suggested change
tags_from_rg: false
tags:
env: Production
nsg:
name: example-nsg
location: westeurope
resource_group_name: example-rg
rules:
rule1:
name: AllowSSH
priority: 100
direction: Inbound
access: Allow
protocol: Tcp
source_port_range: "*"
destination_port_range: "22"
source_address_prefix: 10.0.0.0/24
destination_address_prefix: "*"
rule2:
name: AllowHTTP
priority: 200
direction: Inbound
access: Allow
protocol: Tcp
source_port_range: "*"
destination_port_range: "80"
source_address_prefix: 0.0.0.0/0
destination_address_prefix: "*"
values:
tags_from_rg: false
tags:
env: Production
nsg:
name: example-nsg
location: westeurope
resource_group_name: example-rg
rules:
rule1:
name: AllowSSH
priority: 100
direction: Inbound
access: Allow
protocol: Tcp
source_port_range: "*"
destination_port_range: "22"
source_address_prefix: 10.0.0.0/24
destination_address_prefix: "*"
rule2:
name: AllowHTTP
priority: 200
direction: Inbound
access: Allow
protocol: Tcp
source_port_range: "*"
destination_port_range: "80"
source_address_prefix: 0.0.0.0/0
destination_address_prefix: "*"

Copilot uses AI. Check for mistakes.
15 changes: 15 additions & 0 deletions modules/azure-nsg-nsr/docs/footer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
## Examples

For detailed examples, refer to the [module examples](https://github.com/prefapp/tfm/tree/main/modules/azure-nsg-nsr/_examples):

- [basic](https://github.com/prefapp/tfm/tree/main/modules/azure-nsg-nsr/_examples/basic) - Network Security Group with a set of common inbound and outbound rules.

## Resources and support

- [Official Azure Network Security Group documentation](https://learn.microsoft.com/en-us/azure/virtual-network/network-security-groups-overview)
- [Terraform reference for azurerm_network_security_group](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/network_security_group)
- [Terraform reference for azurerm_network_security_rule](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/network_security_rule)

## Support

For issues, questions, or contributions related to this module, please visit the [repository's issue tracker](https://github.com/prefapp/tfm/issues).
Comment on lines +7 to +15
Copy link

Copilot AI Feb 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The footer has both 'Resources and support' and a separate 'Support' section immediately after, which is redundant. Consider merging into a single section (e.g., 'Resources' and include the issue tracker link there) to keep the footer concise.

Suggested change
## Resources and support
- [Official Azure Network Security Group documentation](https://learn.microsoft.com/en-us/azure/virtual-network/network-security-groups-overview)
- [Terraform reference for azurerm_network_security_group](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/network_security_group)
- [Terraform reference for azurerm_network_security_rule](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/network_security_rule)
## Support
For issues, questions, or contributions related to this module, please visit the [repository's issue tracker](https://github.com/prefapp/tfm/issues).
## Resources
- [Official Azure Network Security Group documentation](https://learn.microsoft.com/en-us/azure/virtual-network/network-security-groups-overview)
- [Terraform reference for azurerm_network_security_group](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/network_security_group)
- [Terraform reference for azurerm_network_security_rule](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/network_security_rule)
- For issues, questions, or contributions related to this module, please visit the [repository's issue tracker](https://github.com/prefapp/tfm/issues).

Copilot uses AI. Check for mistakes.
Comment on lines +7 to +15
Copy link

Copilot AI Feb 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The footer has both 'Resources and support' and a separate 'Support' section immediately after, which is redundant. Consider merging into a single section (e.g., 'Resources' and include the issue tracker link there) to keep the footer concise.

Suggested change
## Resources and support
- [Official Azure Network Security Group documentation](https://learn.microsoft.com/en-us/azure/virtual-network/network-security-groups-overview)
- [Terraform reference for azurerm_network_security_group](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/network_security_group)
- [Terraform reference for azurerm_network_security_rule](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/network_security_rule)
## Support
For issues, questions, or contributions related to this module, please visit the [repository's issue tracker](https://github.com/prefapp/tfm/issues).
## Resources
- [Official Azure Network Security Group documentation](https://learn.microsoft.com/en-us/azure/virtual-network/network-security-groups-overview)
- [Terraform reference for azurerm_network_security_group](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/network_security_group)
- [Terraform reference for azurerm_network_security_rule](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/network_security_rule)
- For issues, questions, or contributions related to this module, please visit the [repository's issue tracker](https://github.com/prefapp/tfm/issues).

Copilot uses AI. Check for mistakes.
Loading