Skip to content

Commit a745f51

Browse files
authored
Merge pull request #29 from MicrosoftCloudEssentials-LearningHub/vpn-gateway
vpn-gatway sample
2 parents 4db90b2 + 4df1ec7 commit a745f51

File tree

7 files changed

+208
-2
lines changed

7 files changed

+208
-2
lines changed

3_networking/vpn-gateway/README.md

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# Terraform Template - Azure VPN Gateway
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-13
9+
10+
----------
11+
12+
> This template contains Terraform configurations to create and manage an Azure VPN Gateway, including a virtual network, GatewaySubnet, and public IP.
13+
14+
> [!NOTE]
15+
> The subnet used for Azure VPN Gateway **must** be named `GatewaySubnet` and sized at least /27.
16+
17+
<p align="center">
18+
<img width="700" alt="image" src="https://github.com/user-attachments/assets/c87943f7-5550-4e59-8059-3c236ec00f53">
19+
</p>
20+
21+
## File Descriptions
22+
23+
- **main.tf**: Contains the main configuration for creating the Azure VPN Gateway and its supporting resources.
24+
- **variables.tf**: Defines the input variables used in the Terraform configuration.
25+
- **terraform.tfvars**: Provides default values for the variables defined in `variables.tf`.
26+
- **outputs.tf**: Defines the outputs such as VPN Gateway ID and public IP address.
27+
28+
## Variables
29+
30+
| Variable Name | Description | Type | Example Value |
31+
|---------------------- |--------------------------------------------------|--------|-----------------------------|
32+
| `subscription_id` | The Azure subscription ID | string | `"00000000-0000-0000-0000-000000000000"` |
33+
| `resource_group_name` | The name of the resource group | string | `"my-vpngw-rg"` |
34+
| `location` | The Azure region to deploy resources | string | `"eastus"` |
35+
| `public_ip_name` | The name of the public IP address for the VPN Gateway | string | `"my-vpngw-pip"` |
36+
| `vpn_gateway_name` | The name of the VPN Gateway | string | `"my-vpngw"` |
37+
| `vpn_gateway_sku` | The SKU for the VPN Gateway | string | `"VpnGw1"` |
38+
39+
## Usage
40+
41+
1. Clone the repository and navigate to the vpn-gateway directory.
42+
2. Update the `terraform.tfvars` file with your values.
43+
3. Initialize and apply the Terraform configuration:
44+
45+
```bash
46+
terraform init
47+
terraform plan
48+
terraform apply
49+
```
50+
51+
## Outputs
52+
53+
| Output Name | Description |
54+
|-----------------------|---------------------------------------------|
55+
| `vpn_gateway_id` | The ID of the VPN Gateway |
56+
| `vpn_gateway_public_ip` | The public IP address of the VPN Gateway |
57+
58+
<div align="center">
59+
<h3 style="color: #4CAF50;">Total Visitors</h3>
60+
<img src="https://profile-counter.glitch.me/brown9804/count.svg" alt="Visitor Count" style="border: 2px solid #4CAF50; border-radius: 5px; padding: 5px;"/>
61+
</div>

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+
}

README.md

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
# Azure Terraform Sample Templates: Version 0.0.0
1+
# Azure Terraform Deployment <br/> Sample Templates: Version 0.0.0
22

33
Costa Rica
44

55
[![GitHub](https://img.shields.io/badge/--181717?logo=github&logoColor=ffffff)](https://github.com/)
66
[brown9804](https://github.com/brown9804)
77

8-
Last updated: 2025-06-01
8+
Last updated: 2025-06-13
99

1010
----------
1111

@@ -64,6 +64,20 @@ Last updated: 2025-06-01
6464

6565
</details>
6666

67+
<details>
68+
<summary><b> Networking </b> (Click to expand) </summary>
69+
70+
- [Networking](./3_networking)
71+
- [Azure Application Gateway](./3_networking/application-gateway)
72+
- [Azure ExpressRoute](./3_networking/expressroute)
73+
- [Azure Firewall](./3_networking/firewall)
74+
- [Azure Front Door](./3_networking/front-door)
75+
- [Azure Load Balancer](./3_networking/load-balancer)
76+
- [Azure Traffic Manager](./3_networking/traffic-manager)
77+
- [Azure VPN Gateway](./3_networking/vpn-gateway)
78+
79+
</details>
80+
6781

6882
## Prerequisites
6983

0 commit comments

Comments
 (0)