Skip to content

Commit cff98d6

Browse files
authored
sample template for vpn gateway
1 parent 6ffe1b2 commit cff98d6

File tree

5 files changed

+131
-0
lines changed

5 files changed

+131
-0
lines changed

3_networking/vpn-gateway/main.tf

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# main.tf
2+
# This file contains the main configuration for creating an Azure VPN Gateway and its supporting resources.
3+
4+
# Resource Group
5+
resource "azurerm_resource_group" "vpngw" {
6+
name = var.resource_group_name
7+
location = var.location
8+
}
9+
10+
# Virtual Network for VPN Gateway
11+
resource "azurerm_virtual_network" "vpngw" {
12+
name = "vpngw-vnet"
13+
address_space = ["10.10.0.0/16"]
14+
location = azurerm_resource_group.vpngw.location
15+
resource_group_name = azurerm_resource_group.vpngw.name
16+
}
17+
18+
# GatewaySubnet (required name and at least /27)
19+
resource "azurerm_subnet" "gateway" {
20+
name = "GatewaySubnet"
21+
resource_group_name = azurerm_resource_group.vpngw.name
22+
virtual_network_name = azurerm_virtual_network.vpngw.name
23+
address_prefixes = ["10.10.1.0/27"]
24+
}
25+
26+
# Public IP for VPN Gateway
27+
resource "azurerm_public_ip" "vpngw" {
28+
name = var.public_ip_name
29+
location = azurerm_resource_group.vpngw.location
30+
resource_group_name = azurerm_resource_group.vpngw.name
31+
allocation_method = "Static" # <-- Must be Static for Standard SKU
32+
sku = "Standard"
33+
}
34+
35+
# VPN Gateway
36+
resource "azurerm_virtual_network_gateway" "vpngw" {
37+
name = var.vpn_gateway_name
38+
location = azurerm_resource_group.vpngw.location
39+
resource_group_name = azurerm_resource_group.vpngw.name
40+
type = "Vpn"
41+
vpn_type = "RouteBased"
42+
active_active = false
43+
enable_bgp = false
44+
sku = var.vpn_gateway_sku
45+
46+
ip_configuration {
47+
name = "vnetGatewayConfig"
48+
public_ip_address_id = azurerm_public_ip.vpngw.id
49+
subnet_id = azurerm_subnet.gateway.id
50+
private_ip_address_allocation = "Dynamic"
51+
}
52+
}
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 VPN Gateway configuration.
3+
4+
output "vpn_gateway_id" {
5+
description = "The ID of the VPN Gateway"
6+
value = azurerm_virtual_network_gateway.vpngw.id
7+
}
8+
9+
output "vpn_gateway_public_ip" {
10+
description = "The public IP address of the VPN Gateway"
11+
value = azurerm_public_ip.vpngw.ip_address
12+
}
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: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
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-vpn-gateway-test"
10+
location = "eastus"
11+
12+
# VPN Gateway Configuration
13+
public_ip_name = "my-vpngw-pip"
14+
vpn_gateway_name = "my-vpngw"
15+
vpn_gateway_sku = "VpnGw1"
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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 "public_ip_name" {
20+
description = "The name of the public IP address for the VPN Gateway"
21+
type = string
22+
}
23+
24+
variable "vpn_gateway_name" {
25+
description = "The name of the VPN Gateway"
26+
type = string
27+
}
28+
29+
variable "vpn_gateway_sku" {
30+
description = "The SKU for the VPN Gateway (e.g., VpnGw1, VpnGw2)"
31+
type = string
32+
default = "VpnGw1"
33+
}

0 commit comments

Comments
 (0)