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

Add Firewall Policy module #19

Merged
merged 3 commits into from
Jan 4, 2024
Merged
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
1 change: 1 addition & 0 deletions modules/firewall-policy/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Changelog
30 changes: 30 additions & 0 deletions modules/firewall-policy/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Firewall Policy

This module creates a [Firewall Policy](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/firewall_policy).

## Usage

```hcl
module "firewall_policy" {
source = "https://github.com/gofrontier-com/azurerm-terraform-modules/releases/download/firewall-policy/[VERSION]/module.tar.gz//src"

environment = "dev"
identifier = "customerbanking"
location = "uksouth"
resource_group_name = module.resource_group.name
zone = "pla"

tags = {
WorkloadType = "PlatformLZ/firewall-policy"
}
}

```

## Known issues

_None._

## Contributing

See <https://github.com/gofrontier-com/azurerm-terraform-modules/blob/main/README.rst#contributing>.
1 change: 1 addition & 0 deletions modules/firewall-policy/VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1.0
14 changes: 14 additions & 0 deletions modules/firewall-policy/src/locals.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
locals {
identifier = replace(lower(var.identifier), "/[^a-z1-9]/", "")

short_locations = {
"uksouth" = "uks"
"ukwest" = "ukw"
}

tags = {
Environment = var.environment
Location = var.location
Zone = var.zone
}
}
20 changes: 20 additions & 0 deletions modules/firewall-policy/src/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
resource "azurerm_firewall_policy" "main" {
name = "fwpol-${var.zone}-${var.environment}-${lookup(local.short_locations, var.location)}-${local.identifier}"
resource_group_name = var.resource_group_name
location = var.location

base_policy_id = var.base_policy_id

sku = var.sku

dynamic "dns" {
for_each = length(var.dns_servers) > 0 ? [{}] : []

content {
proxy_enabled = true
servers = var.dns_servers
}
}

tags = merge(var.tags, local.tags)
}
7 changes: 7 additions & 0 deletions modules/firewall-policy/src/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
output "id" {
value = azurerm_firewall_policy.main.id
}

output "name" {
value = azurerm_firewall_policy.main.name
}
39 changes: 39 additions & 0 deletions modules/firewall-policy/src/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
variable "base_policy_id" {
type = string
default = null
}

variable "dns_servers" {
type = list(string)
default = []
}

variable "environment" {
type = string
}

variable "identifier" {
type = string
}

variable "location" {
type = string
}

variable "resource_group_name" {
type = string
}

variable "sku" {
type = string
default = "Standard"
}

variable "tags" {
type = map(string)
default = {}
}

variable "zone" {
type = string
}
17 changes: 17 additions & 0 deletions modules/firewall-policy/test/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
provider "azurerm" {
features {}
}

module "firewall_policy" {
source = "../src"

environment = "foo"
identifier = "bar"
location = "uksouth"
resource_group_name = "baz"
zone = "qux"

tags = {
Foo = "Bar"
}
}
10 changes: 10 additions & 0 deletions modules/firewall-policy/test/terraform.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
terraform {
required_version = "~> 1.5"

required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = "~> 3.85"
}
}
}
Loading