Skip to content

Commit 8e9f365

Browse files
authored
Merge eb347d8 into 1d24188
2 parents 1d24188 + eb347d8 commit 8e9f365

File tree

6 files changed

+209
-0
lines changed

6 files changed

+209
-0
lines changed

3_networking/firewall/README.md

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# Terraform Template - Azure Firewall
2+
3+
Costa Rica
4+
5+
[![GitHub](https://img.shields.io/badge/--181717?logo=github&logoColor=ffffff)](https://github.com/)
6+
[brown9804](https://github.com/brown9804)
7+
8+
Last updated: 2025-06-12
9+
10+
----------
11+
12+
> This template contains Terraform configurations to create and manage an Azure Firewall, including a public IP and required subnet configuration.
13+
14+
> [!NOTE]
15+
> The subnet used for Azure Firewall **must** be named `AzureFirewallSubnet` and sized at least /26.
16+
17+
<p align="center">
18+
<img width="800" alt="image" src="https://github.com/user-attachments/assets/7614ce31-c57d-41ce-a9f2-307c29cb0f3d">
19+
</p>
20+
21+
22+
23+
## File Descriptions
24+
25+
- **main.tf**: Contains the main configuration for creating the Azure Firewall and its supporting resources.
26+
- **variables.tf**: Defines the input variables used in the Terraform configuration.
27+
- **terraform.tfvars**: Provides default values for the variables defined in `variables.tf`.
28+
- **outputs.tf**: Defines the outputs such as Firewall ID and public IP address.
29+
30+
## Variables
31+
32+
| Variable Name | Description | Type | Example Value |
33+
|---------------------- |--------------------------------------------------|--------|-----------------------------|
34+
| `resource_group_name` | The name of the resource group | string | `"my-firewall-rg"` |
35+
| `location` | The Azure region to deploy resources | string | `"eastus"` |
36+
| `firewall_name` | The name of the Azure Firewall | string | `"my-azfw"` |
37+
| `public_ip_name` | The name of the public IP address for the firewall | string | `"my-azfw-pip"` |
38+
| `subnet_id` | The ID of the subnet for the Azure Firewall | string | `".../subnets/AzureFirewallSubnet"` |
39+
40+
## Usage
41+
42+
1. Clone the repository and navigate to the firewall directory.
43+
2. Update the `terraform.tfvars` file with your values.
44+
3. Initialize and apply the Terraform configuration:
45+
46+
```bash
47+
terraform init
48+
terraform plan
49+
terraform apply
50+
```
51+
52+
## Outputs
53+
54+
| Output Name | Description |
55+
|---------------------|---------------------------------------------|
56+
| `firewall_id` | The ID of the Azure Firewall |
57+
| `firewall_public_ip`| The public IP address of the Azure Firewall |
58+
59+
<div align="center">
60+
<h3 style="color: #4CAF50;">Total Visitors</h3>
61+
<img src="https://profile-counter.glitch.me/brown9804/count.svg" alt="Visitor Count" style="border: 2px solid #4CAF50; border-radius: 5px; padding: 5px;"/>
62+
</div>

3_networking/firewall/main.tf

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# main.tf
2+
# This file contains the main configuration for creating an Azure Firewall and its supporting resources.
3+
4+
# Resource Group
5+
resource "azurerm_resource_group" "fw" {
6+
name = var.resource_group_name
7+
location = var.location
8+
}
9+
10+
# Public IP for Firewall
11+
resource "azurerm_public_ip" "fw" {
12+
name = var.public_ip_name
13+
location = azurerm_resource_group.fw.location
14+
resource_group_name = azurerm_resource_group.fw.name
15+
allocation_method = "Static"
16+
sku = "Standard"
17+
}
18+
19+
# Virtual Network for Firewall
20+
resource "azurerm_virtual_network" "fw" {
21+
name = var.vnet_name
22+
address_space = var.vnet_address_space
23+
location = azurerm_resource_group.fw.location
24+
resource_group_name = azurerm_resource_group.fw.name
25+
}
26+
27+
# AzureFirewallSubnet (required name and at least /26)
28+
resource "azurerm_subnet" "fw" {
29+
name = var.subnet_name
30+
resource_group_name = azurerm_resource_group.fw.name
31+
virtual_network_name = azurerm_virtual_network.fw.name
32+
address_prefixes = var.subnet_address_prefixes
33+
}
34+
35+
# Azure Firewall
36+
resource "azurerm_firewall" "fw" {
37+
name = var.firewall_name
38+
location = azurerm_resource_group.fw.location
39+
resource_group_name = azurerm_resource_group.fw.name
40+
41+
sku_tier = "Standard"
42+
sku_name = "AZFW_VNet"
43+
44+
ip_configuration {
45+
name = "configuration"
46+
subnet_id = azurerm_subnet.fw.id # Direct reference to the subnet resource
47+
public_ip_address_id = azurerm_public_ip.fw.id
48+
}
49+
}

3_networking/firewall/outputs.tf

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# outputs.tf
2+
# This file defines the outputs for the Azure Firewall configuration.
3+
4+
output "firewall_id" {
5+
description = "The ID of the Azure Firewall"
6+
value = azurerm_firewall.fw.id
7+
}
8+
9+
output "firewall_public_ip" {
10+
description = "The public IP address of the Azure Firewall"
11+
value = azurerm_public_ip.fw.ip_address
12+
}

3_networking/firewall/provider.tf

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# provider.tf
2+
# This file configures the Azure provider to interact with Azure resources.
3+
# It specifies the required provider and its version, along with provider-specific configurations.
4+
5+
terraform {
6+
required_version = ">= 1.8, < 2.0"
7+
# Specify the required provider and its version
8+
required_providers {
9+
azurerm = {
10+
source = "hashicorp/azurerm" # Source of the AzureRM provider
11+
version = "~> 4.16.0" # Version of the AzureRM provider
12+
}
13+
}
14+
}
15+
16+
provider "azurerm" {
17+
features {} # Enable all features for the AzureRM provider
18+
subscription_id = var.subscription_id # Use the subscription ID variable
19+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# terraform.tfvars
2+
# This file provides default values for the variables defined in variables.tf.
3+
# These values can be overridden by specifying different values during Terraform execution.
4+
5+
# Azure Subscription
6+
subscription_id = "" # "your-subscription-id"
7+
8+
# Resource Group
9+
resource_group_name = "RG-firewall-test"
10+
location = "eastus"
11+
12+
# Azure Firewall Configuration
13+
firewall_name = "my-azfw"
14+
public_ip_name = "my-azfw-pip"
15+
vnet_name = "my-azfw-vnet"
16+
vnet_address_space = ["10.0.0.0/16"]
17+
18+
# Subnet Configuration
19+
subnet_name = "AzureFirewallSubnet"
20+
subnet_address_prefixes = ["10.0.1.0/26"]

3_networking/firewall/variables.tf

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# variables.tf
2+
# This file defines the input variables used in the Terraform configuration.
3+
4+
variable "subscription_id" {
5+
description = "The Azure subscription ID"
6+
type = string
7+
}
8+
9+
variable "resource_group_name" {
10+
description = "The name of the resource group"
11+
type = string
12+
}
13+
14+
variable "location" {
15+
description = "The Azure region to deploy resources"
16+
type = string
17+
}
18+
19+
variable "firewall_name" {
20+
description = "The name of the Azure Firewall"
21+
type = string
22+
}
23+
24+
variable "public_ip_name" {
25+
description = "The name of the public IP address for the firewall"
26+
type = string
27+
}
28+
29+
variable "vnet_name" {
30+
description = "The name of the virtual network"
31+
type = string
32+
}
33+
34+
variable "vnet_address_space" {
35+
description = "The address space of the virtual network"
36+
type = list(string)
37+
}
38+
39+
variable "subnet_name" {
40+
description = "The name of the subnet for the Azure Firewall"
41+
type = string
42+
}
43+
44+
variable "subnet_address_prefixes" {
45+
description = "The address prefixes for the subnet"
46+
type = list(string)
47+
}

0 commit comments

Comments
 (0)