Skip to content

Commit

Permalink
azfw quickstarts (#245)
Browse files Browse the repository at this point in the history
* adding azfw quickstarts
  • Loading branch information
cshea-msft committed Sep 4, 2023
1 parent 382bc86 commit 8aa0c51
Show file tree
Hide file tree
Showing 10 changed files with 553 additions and 0 deletions.
120 changes: 120 additions & 0 deletions quickstart/101-azfw-with-fwpolicy/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
resource "random_pet" "rg-name" {
prefix = var.resource_group_name_prefix
}

resource "azurerm_resource_group" "rg" {
name = random_pet.rg-name.id
location = var.resource_group_location
}

resource "azurerm_virtual_network" "azfw_vnet" {
name = "azfw-vnet"
location = azurerm_resource_group.rg.location
resource_group_name = azurerm_resource_group.rg.name
address_space = ["10.10.0.0/24"]
}

resource "azurerm_ip_group" "workload_ip_group" {
name = "workload-ip-group"
resource_group_name = azurerm_resource_group.rg.name
location = azurerm_resource_group.rg.location
cidrs = ["10.20.0.0/24", "10.30.0.0/24"]
}
resource "azurerm_ip_group" "infra_ip_group" {
name = "infra-ip-group"
resource_group_name = azurerm_resource_group.rg.name
location = azurerm_resource_group.rg.location
cidrs = ["10.40.0.0/24", "10.50.0.0/24"]
}

resource "azurerm_subnet" "azfw_subnet" {
name = "AzureFirewallSubnet"
resource_group_name = azurerm_resource_group.rg.name
virtual_network_name = azurerm_virtual_network.azfw_vnet.name
address_prefixes = ["10.10.0.0/26"]
}

resource "azurerm_public_ip" "pip_azfw" {
name = "pip-azfw"
location = azurerm_resource_group.rg.location
resource_group_name = azurerm_resource_group.rg.name
allocation_method = "Static"
sku = "Standard"
}

resource "azurerm_firewall_policy" "azfw_policy" {
name = "azfw-policy"
resource_group_name = azurerm_resource_group.rg.name
location = azurerm_resource_group.rg.location
sku = var.firewall_sku_tier
threat_intelligence_mode = "Alert"
}

resource "azurerm_firewall_policy_rule_collection_group" "net_policy_rule_collection_group" {
name = "DefaultNetworkRuleCollectionGroup"
firewall_policy_id = azurerm_firewall_policy.azfw_policy.id
priority = 200
network_rule_collection {
name = "DefaultNetworkRuleCollection"
action = "Allow"
priority = 200
rule {
name = "time-windows"
protocols = ["UDP"]
source_ip_groups = [azurerm_ip_group.workload_ip_group.id, azurerm_ip_group.infra_ip_group.id]
destination_ports = ["123"]
destination_addresses = ["132.86.101.172"]
}
}
}

resource "azurerm_firewall_policy_rule_collection_group" "app_policy_rule_collection_group" {
name = "DefaulApplicationtRuleCollectionGroup"
firewall_policy_id = azurerm_firewall_policy.azfw_policy.id
priority = 300
application_rule_collection {
name = "DefaultApplicationRuleCollection"
action = "Allow"
priority = 500
rule {
name = "AllowWindowsUpdate"

description = "Allow Windows Update"
protocols {
type = "Http"
port = 80
}
protocols {
type = "Https"
port = 443
}
source_ip_groups = [azurerm_ip_group.workload_ip_group.id, azurerm_ip_group.infra_ip_group.id]
destination_fqdn_tags = ["WindowsUpdate"]
}
rule {
name = "Global Rule"
description = "Allow access to Microsoft.com"
protocols {
type = "Https"
port = 443
}
destination_fqdns = ["*.microsoft.com"]
terminate_tls = false
source_ip_groups = [azurerm_ip_group.workload_ip_group.id, azurerm_ip_group.infra_ip_group.id]
}
}
}

resource "azurerm_firewall" "fw" {
name = "azfw"
location = azurerm_resource_group.rg.location
resource_group_name = azurerm_resource_group.rg.name
sku_name = "AZFW_VNet"
sku_tier = var.firewall_sku_tier
ip_configuration {
name = "azfw-ipconfig"
subnet_id = azurerm_subnet.azfw_subnet.id
public_ip_address_id = azurerm_public_ip.pip_azfw.id
}
firewall_policy_id = azurerm_firewall_policy.azfw_policy.id
}
7 changes: 7 additions & 0 deletions quickstart/101-azfw-with-fwpolicy/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
output "resource_group_name" {
value = azurerm_resource_group.rg.name
}

output "firewall_name" {
value = azurerm_firewall.fw.name
}
16 changes: 16 additions & 0 deletions quickstart/101-azfw-with-fwpolicy/provider.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
terraform {
required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = "~>3.0"
}
random = {
source = "hashicorp/random"
version = "~>3.0"
}
}
}

provider "azurerm" {
features {}
}
23 changes: 23 additions & 0 deletions quickstart/101-azfw-with-fwpolicy/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Azure Firewall and Azure Firewall Policy

This template deploys an [Azure Firewall](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/firewall) with an [Azure Firewall Policy](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/firewall_policy)

## Terraform resource types

- [azurerm_resource_group](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/resource_group)
- [azurerm_virtual_network](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/virtual_network)
- [azurerm_subnet](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/subnet)
- [azurerm_ip_group](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/ip_group)
- [azurerm_public_ip](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/public_ip)
- [azurerm_firewall_policy](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/firewall_policy)
- [azurerm_firewall_policy_rule_collection_group](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/firewall_policy_rule_collection_group)
- [azurerm_firewall](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/firewall)

## Variables

| Name | Description | Default value |
|-|-|-|
| `resource_group_location` | location for your resources | eastus |
| `firewall_sku_tier` | Sku size for your Firewall and Firewall Policy | Premium |

## Example
22 changes: 22 additions & 0 deletions quickstart/101-azfw-with-fwpolicy/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
variable "resource_group_location" {
type = string
description = "Location for all resources."
default = "eastus"
}

variable "resource_group_name_prefix" {
type = string
description = "Prefix for the Resource Group Name that's combined with a random id so name is unique in your Azure subcription."
default = "rg"
}

variable "firewall_sku_tier" {
type = string
description = "Firewall SKU."
default = "Premium" # Valid values are Standard and Premium
validation {
condition = contains(["Standard", "Premium"], var.firewall_sku_tier)
error_message = "The sku must be one of the following: Standard, Premium"
}
}

Loading

0 comments on commit 8aa0c51

Please sign in to comment.