Skip to content

Commit eb347d8

Browse files
authored
sample for firewall
1 parent 73c23e3 commit eb347d8

File tree

5 files changed

+147
-0
lines changed

5 files changed

+147
-0
lines changed

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)