Compare commits

...

5 Commits

Author SHA1 Message Date
zjhe
c08405c06a fix broken script url 2024-10-05 12:37:06 +08:00
zjhe
ff0b2795ab add random suffix to resource group name 2024-10-05 10:43:31 +08:00
zjhe
dcca3ba6ef fix example 2024-10-05 10:39:55 +08:00
zjhe
86b15f1a9f fix example 2024-10-05 08:54:51 +08:00
zjhe
ddfedda590 fix 301-hub-spoke 2024-10-05 08:50:32 +08:00
7 changed files with 400 additions and 379 deletions

View File

@ -4,8 +4,14 @@ locals {
hub-nva-resource-group = "hub-nva-rg"
}
resource "random_string" "suffix" {
length = 5
special = false
upper = false
}
resource "azurerm_resource_group" "hub-nva-rg" {
name = "${local.prefix-hub-nva}-rg"
name = "${local.prefix-hub-nva}-rg-${random_string.suffix.result}"
location = local.hub-nva-location
tags = {
@ -55,7 +61,7 @@ resource "azurerm_virtual_machine" "hub-nva-vm" {
os_profile {
computer_name = "${local.prefix-hub-nva}-vm"
admin_username = var.username
admin_password = var.password
admin_password = local.password
}
os_profile_linux_config {
@ -78,7 +84,7 @@ resource "azurerm_virtual_machine_extension" "enable-routes" {
settings = <<SETTINGS
{
"fileUris": [
"https://raw.githubusercontent.com/mspnp/reference-architectures/master/scripts/linux/enable-ip-forwarding.sh"
"https://raw.githubusercontent.com/lonegunmanb/reference-architectures/refs/heads/master/scripts/linux/enable-ip-forwarding.sh"
],
"commandToExecute": "bash enable-ip-forwarding.sh"
}
@ -142,7 +148,7 @@ resource "azurerm_route_table" "spoke1-rt" {
route {
name = "default"
address_prefix = "0.0.0.0/0"
next_hop_type = "vnetlocal"
next_hop_type = "VnetLocal"
}
tags = {
@ -178,7 +184,7 @@ resource "azurerm_route_table" "spoke2-rt" {
route {
name = "default"
address_prefix = "0.0.0.0/0"
next_hop_type = "vnetlocal"
next_hop_type = "VnetLocal"
}
tags = {

View File

@ -1,7 +1,7 @@
locals {
prefix-hub = "hub"
hub-location = "eastus"
hub-resource-group = "hub-vnet-rg"
hub-resource-group = "hub-vnet-rg-${random_string.suffix.result}"
shared-key = "4-v3ry-53cr37-1p53c-5h4r3d-k3y"
}
@ -84,7 +84,7 @@ resource "azurerm_virtual_machine" "hub-vm" {
os_profile {
computer_name = "${local.prefix-hub}-vm"
admin_username = var.username
admin_password = var.password
admin_password = local.password
}
os_profile_linux_config {

View File

@ -5,11 +5,24 @@ terraform {
required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = "~>2.0"
version = "~> 3.0"
}
}
}
provider "azurerm" {
features {}
features {
resource_group {
prevent_deletion_if_contains_resources = false
}
}
}
resource "random_password" "password" {
count = var.password == null ? 1 : 0
length = 20
}
locals {
password = try(random_password.password[0].result, var.password)
}

View File

@ -1,6 +1,6 @@
locals {
onprem-location = "eastus"
onprem-resource-group = "onprem-vnet-rg"
onprem-resource-group = "onprem-vnet-rg-${random_string.suffix.result}"
prefix-onprem = "onprem"
}
@ -111,7 +111,7 @@ resource "azurerm_virtual_machine" "onprem-vm" {
os_profile {
computer_name = "${local.prefix-onprem}-vm"
admin_username = var.username
admin_password = var.password
admin_password = local.password
}
os_profile_linux_config {

View File

@ -1,6 +1,6 @@
locals {
spoke1-location = "eastus"
spoke1-resource-group = "spoke1-vnet-rg"
spoke1-resource-group = "spoke1-vnet-rg-${random_string.suffix.result}"
prefix-spoke1 = "spoke1"
}
@ -44,7 +44,7 @@ resource "azurerm_virtual_network_peering" "spoke1-hub-peer" {
allow_forwarded_traffic = true
allow_gateway_transit = false
use_remote_gateways = true
depends_on = [azurerm_virtual_network.spoke1-vnet, azurerm_virtual_network.hub-vnet , azurerm_virtual_network_gateway.hub-vnet-gateway]
depends_on = [azurerm_virtual_network.spoke1-vnet, azurerm_virtual_network.hub-vnet, azurerm_virtual_network_gateway.hub-vnet-gateway]
}
resource "azurerm_network_interface" "spoke1-nic" {
@ -84,7 +84,7 @@ resource "azurerm_virtual_machine" "spoke1-vm" {
os_profile {
computer_name = "${local.prefix-spoke1}-vm"
admin_username = var.username
admin_password = var.password
admin_password = local.password
}
os_profile_linux_config {

View File

@ -1,6 +1,6 @@
locals {
spoke2-location = "eastus"
spoke2-resource-group = "spoke2-vnet-rg"
spoke2-resource-group = "spoke2-vnet-rg-${random_string.suffix.result}"
prefix-spoke2 = "spoke2"
}
@ -88,7 +88,7 @@ resource "azurerm_virtual_machine" "spoke2-vm" {
os_profile {
computer_name = "${local.prefix-spoke2}-vm"
admin_username = var.username
admin_password = var.password
admin_password = local.password
}
os_profile_linux_config {

View File

@ -10,6 +10,8 @@ variable "username" {
variable "password" {
description = "Password for Virtual Machines"
sensitive = true
default = null
}
variable "vmsize" {