-
Notifications
You must be signed in to change notification settings - Fork 830
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #400 from Azure/101-azure-expressroute
101-azure-expressroute
- Loading branch information
Showing
5 changed files
with
151 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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." | ||
} |