101-firewall-standard patch (#169)

* fix example

* add variable type
This commit is contained in:
Dingjia Chen 2023-02-21 00:17:48 -06:00 committed by GitHub
parent 1e7ae5e1c8
commit 4e0ad3a89c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 46 additions and 26 deletions

View File

@ -1,26 +1,10 @@
terraform {
required_version = ">=0.12"
required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = ">=2.46.0"
}
}
}
provider "azurerm" {
features {}
}
resource "azurerm_resource_group" "rg" { resource "azurerm_resource_group" "rg" {
name = "test-resources" name = "${random_pet.prefix.id}-rg"
location = var.resource_group_location location = var.resource_group_location
} }
resource "azurerm_virtual_network" "vnet" { resource "azurerm_virtual_network" "vnet" {
name = "testvnet" name = "${random_pet.prefix.id}-vnet"
address_space = ["10.0.0.0/16"] address_space = ["10.0.0.0/16"]
location = azurerm_resource_group.rg.location location = azurerm_resource_group.rg.location
resource_group_name = azurerm_resource_group.rg.name resource_group_name = azurerm_resource_group.rg.name
@ -34,17 +18,19 @@ resource "azurerm_subnet" "subnet" {
} }
resource "azurerm_public_ip" "pip" { resource "azurerm_public_ip" "pip" {
name = "testpip" name = "${random_pet.prefix.id}-pip"
location = azurerm_resource_group.rg.location location = azurerm_resource_group.rg.location
resource_group_name = azurerm_resource_group.rg.name resource_group_name = azurerm_resource_group.rg.name
allocation_method = "Static" allocation_method = "Static"
sku = "Standard" sku = "Standard"
} }
resource "azurerm_firewall" "fw" { resource "azurerm_firewall" "main" {
name = "testfirewall" name = "${random_pet.prefix.id}-fw"
location = azurerm_resource_group.rg.location location = azurerm_resource_group.rg.location
resource_group_name = azurerm_resource_group.rg.name resource_group_name = azurerm_resource_group.rg.name
sku_name = "AZFW_VNet"
sku_tier = "Standard"
ip_configuration { ip_configuration {
name = "configuration" name = "configuration"
@ -54,8 +40,8 @@ resource "azurerm_firewall" "fw" {
} }
resource "azurerm_firewall_application_rule_collection" "app-rc" { resource "azurerm_firewall_application_rule_collection" "app-rc" {
name = "apptestcollection" name = "${random_pet.prefix.id}-app-rc"
azure_firewall_name = azurerm_firewall.fw.name azure_firewall_name = azurerm_firewall.main.name
resource_group_name = azurerm_resource_group.rg.name resource_group_name = azurerm_resource_group.rg.name
priority = 100 priority = 100
action = "Allow" action = "Allow"
@ -79,8 +65,8 @@ resource "azurerm_firewall_application_rule_collection" "app-rc" {
} }
resource "azurerm_firewall_network_rule_collection" "net-rc" { resource "azurerm_firewall_network_rule_collection" "net-rc" {
name = "nettestcollection" name = "${random_pet.prefix.id}-net-rc"
azure_firewall_name = azurerm_firewall.fw.name azure_firewall_name = azurerm_firewall.main.name
resource_group_name = azurerm_resource_group.rg.name resource_group_name = azurerm_resource_group.rg.name
priority = 100 priority = 100
action = "Allow" action = "Allow"
@ -107,3 +93,8 @@ resource "azurerm_firewall_network_rule_collection" "net-rc" {
] ]
} }
} }
resource "random_pet" "prefix" {
prefix = var.prefix
length = 1
}

View File

@ -0,0 +1,3 @@
output "resource_group_name" {
value = azurerm_resource_group.rg.name
}

View File

@ -0,0 +1,18 @@
terraform {
required_version = ">= 1.0"
required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = ">= 3.0, < 4.0"
}
random = {
source = "hashicorp/random"
version = ">= 3.0"
}
}
}
provider "azurerm" {
features {}
}

View File

@ -1,3 +1,11 @@
variable "resource_group_location" { variable "resource_group_location" {
default = "eastus" type = string
default = "eastus"
description = "Location of the resource group."
}
variable "prefix" {
type = string
default = "firewall-standard"
description = "Prefix of the resource name"
} }