From 0a7bb46519b7d47b37bcba28829f25e43150dbc3 Mon Sep 17 00:00:00 2001 From: Tom Archer Date: Thu, 12 Dec 2024 07:19:53 -0800 Subject: [PATCH] Initial put --- quickstart/101-azure-expressroute/README.md | 22 +++++ quickstart/101-azure-expressroute/main.tf | 86 +++++++++++++++++++ quickstart/101-azure-expressroute/outputs.tf | 16 ++++ .../101-azure-expressroute/providers.tf | 16 ++++ .../101-azure-expressroute/variables.tf | 11 +++ 5 files changed, 151 insertions(+) create mode 100644 quickstart/101-azure-expressroute/README.md create mode 100644 quickstart/101-azure-expressroute/main.tf create mode 100644 quickstart/101-azure-expressroute/outputs.tf create mode 100644 quickstart/101-azure-expressroute/providers.tf create mode 100644 quickstart/101-azure-expressroute/variables.tf diff --git a/quickstart/101-azure-expressroute/README.md b/quickstart/101-azure-expressroute/README.md new file mode 100644 index 000000000..304873171 --- /dev/null +++ b/quickstart/101-azure-expressroute/README.md @@ -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 | diff --git a/quickstart/101-azure-expressroute/main.tf b/quickstart/101-azure-expressroute/main.tf new file mode 100644 index 000000000..118ee064e --- /dev/null +++ b/quickstart/101-azure-expressroute/main.tf @@ -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 +} \ No newline at end of file diff --git a/quickstart/101-azure-expressroute/outputs.tf b/quickstart/101-azure-expressroute/outputs.tf new file mode 100644 index 000000000..1dbf781be --- /dev/null +++ b/quickstart/101-azure-expressroute/outputs.tf @@ -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 +} \ No newline at end of file diff --git a/quickstart/101-azure-expressroute/providers.tf b/quickstart/101-azure-expressroute/providers.tf new file mode 100644 index 000000000..7261b1fb4 --- /dev/null +++ b/quickstart/101-azure-expressroute/providers.tf @@ -0,0 +1,16 @@ +terraform { + required_providers { + azurerm = { + source = "hashicorp/azurerm" + version = "~>3.0" + } + random = { + source = "hashicorp/random" + version = "~>3.0" + } + } +} + +provider "azurerm" { + features {} +} \ No newline at end of file diff --git a/quickstart/101-azure-expressroute/variables.tf b/quickstart/101-azure-expressroute/variables.tf new file mode 100644 index 000000000..1a8c6abba --- /dev/null +++ b/quickstart/101-azure-expressroute/variables.tf @@ -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." +} \ No newline at end of file