Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

101-azure-expressroute #400

Merged
merged 1 commit into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions quickstart/101-azure-expressroute/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Azure ExpressRoute

This template deploys an Azure ExpressRoute.

## Terraform resource types

- [random_pet](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/pet)
- [azurerm_resource_group](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/resource_group)
- [random_string](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/string)
- [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_public_ip](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/public_ip)
- [azurerm_virtual_network_gateway](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/virtual_network_gateway)
- [azurerm_express_route_circuit](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/express_route_circuit)
- [azurerm_express_route_circuit_peering](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/express_route_circuit_peering)

## Variables

| Name | Description | Default value |
|-|-|-|
| `resource_group_name_prefix` | Prefix of the resource group name that's combined with a random ID so name is unique in your Azure subscription. | rg |
| `resource_group_location` | Location of the resource group. | eastus |
86 changes: 86 additions & 0 deletions quickstart/101-azure-expressroute/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
# Create Resource Group
resource "random_pet" "rg_name" {
prefix = var.resource_group_name_prefix
}

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

# Random String for unique naming
resource "random_string" "name" {
length = 8
special = false
upper = false
lower = true
numeric = false
}

# Create Virtual Network
resource "azurerm_virtual_network" "vnet" {
name = "vnet-${random_string.name.result}"
address_space = ["10.0.0.0/16"]
location = azurerm_resource_group.rg.location
resource_group_name = azurerm_resource_group.rg.name
}

# Create Subnet for Gateway
resource "azurerm_subnet" "gateway_subnet" {
name = "GatewaySubnet"
resource_group_name = azurerm_resource_group.rg.name
virtual_network_name = azurerm_virtual_network.vnet.name
address_prefixes = ["10.0.0.0/24"]
}

# Create Public IP for Gateway
resource "azurerm_public_ip" "gateway_ip" {
name = "pip-${random_string.name.result}"
location = azurerm_resource_group.rg.location
resource_group_name = azurerm_resource_group.rg.name
allocation_method = "Static"
sku = "Standard"
}

# Create ExpressRoute Gateway
resource "azurerm_virtual_network_gateway" "gateway" {
name = "gateway-${random_string.name.result}"
location = azurerm_resource_group.rg.location
resource_group_name = azurerm_resource_group.rg.name
type = "ExpressRoute"
vpn_type = "RouteBased"
active_active = false
enable_bgp = false
sku = "HighPerformance"

ip_configuration {
name = "vnetGatewayConfig"
public_ip_address_id = azurerm_public_ip.gateway_ip.id
subnet_id = azurerm_subnet.gateway_subnet.id
}
}

# Create ExpressRoute Circuit
resource "azurerm_express_route_circuit" "circuit" {
name = "erc-${random_string.name.result}"
resource_group_name = azurerm_resource_group.rg.name
location = azurerm_resource_group.rg.location
service_provider_name = "Equinix"
peering_location = "Washington DC"
bandwidth_in_mbps = 50
sku {
tier = "Standard"
family = "MeteredData"
}
}

# Create ExpressRoute Circuit Peering
resource "azurerm_express_route_circuit_peering" "private" {
peering_type = "AzurePrivatePeering"
express_route_circuit_name = azurerm_express_route_circuit.circuit.name
resource_group_name = azurerm_resource_group.rg.name
primary_peer_address_prefix = "192.168.10.16/30"
secondary_peer_address_prefix = "192.168.10.20/30"
vlan_id = 200
peer_asn = 65001 # Provide a valid private ASN here
}
16 changes: 16 additions & 0 deletions quickstart/101-azure-expressroute/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
output "resource_group_name" {
value = azurerm_resource_group.rg.name
}

output "express_route_circuit_id" {
value = azurerm_express_route_circuit.circuit.id
}

output "gateway_ip" {
value = azurerm_public_ip.gateway_ip.ip_address
}

output "service_key" {
value = azurerm_express_route_circuit.circuit.service_key
sensitive = true
}
16 changes: 16 additions & 0 deletions quickstart/101-azure-expressroute/providers.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 {}
}
11 changes: 11 additions & 0 deletions quickstart/101-azure-expressroute/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
variable "resource_group_location" {
type = string
default = "eastus"
description = "Location of the resource group."
}

variable "resource_group_name_prefix" {
type = string
default = "rg"
description = "Prefix of the resource group name that's combined with a random ID so name is unique in your Azure subscription."
}
Loading