-
Notifications
You must be signed in to change notification settings - Fork 0
/
spoke2.tf
112 lines (95 loc) · 3.74 KB
/
spoke2.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
locals {
spoke2-location = var.azurelocation
prefix-spoke2 = "${var.global_prefix}-spoke2"
}
resource "azurerm_resource_group" "spoke2-vnet-rg" {
name = "${local.prefix-spoke2}-rg"
location = local.spoke2-location
}
resource "azurerm_virtual_network" "spoke2-vnet" {
name = "${local.prefix-spoke2}-vnet"
location = azurerm_resource_group.spoke2-vnet-rg.location
resource_group_name = azurerm_resource_group.spoke2-vnet-rg.name
address_space = ["10.2.0.0/16"]
tags = {
environment = local.prefix-spoke2
}
}
resource "azurerm_subnet" "spoke2-mgmt" {
name = "mgmt"
resource_group_name = azurerm_resource_group.spoke2-vnet-rg.name
virtual_network_name = azurerm_virtual_network.spoke2-vnet.name
address_prefix = "10.2.0.64/27"
}
resource "azurerm_subnet" "spoke2-workload" {
name = "workload"
resource_group_name = azurerm_resource_group.spoke2-vnet-rg.name
virtual_network_name = azurerm_virtual_network.spoke2-vnet.name
address_prefix = "10.2.1.0/24"
}
resource "azurerm_virtual_network_peering" "spoke2-hub-peer" {
name = "${local.prefix-spoke2}-hub-peer"
resource_group_name = azurerm_resource_group.spoke2-vnet-rg.name
virtual_network_name = azurerm_virtual_network.spoke2-vnet.name
remote_virtual_network_id = azurerm_virtual_network.hub-vnet.id
allow_virtual_network_access = true
allow_forwarded_traffic = true
allow_gateway_transit = false
use_remote_gateways = true
depends_on = [azurerm_virtual_network.spoke2-vnet, azurerm_virtual_network.hub-vnet, azurerm_virtual_network_gateway.hub-vnet-gateway]
}
resource "azurerm_network_interface" "spoke2-nic" {
name = "${local.prefix-spoke2}-nic"
location = azurerm_resource_group.spoke2-vnet-rg.location
resource_group_name = azurerm_resource_group.spoke2-vnet-rg.name
enable_ip_forwarding = true
ip_configuration {
name = local.prefix-spoke2
subnet_id = azurerm_subnet.spoke2-mgmt.id
private_ip_address_allocation = "Dynamic"
}
tags = {
environment = local.prefix-spoke2
}
}
resource "azurerm_virtual_machine" "spoke2-vm" {
name = "${local.prefix-spoke2}-vm"
location = azurerm_resource_group.spoke2-vnet-rg.location
resource_group_name = azurerm_resource_group.spoke2-vnet-rg.name
network_interface_ids = [azurerm_network_interface.spoke2-nic.id]
vm_size = var.vmsize
storage_image_reference {
publisher = "Canonical"
offer = "UbuntuServer"
sku = "16.04-LTS"
version = "latest"
}
storage_os_disk {
name = "myosdisk1"
caching = "ReadWrite"
create_option = "FromImage"
managed_disk_type = "Standard_LRS"
}
os_profile {
computer_name = "${local.prefix-spoke2}-vm"
admin_username = var.username
admin_password = var.password
}
os_profile_linux_config {
disable_password_authentication = false
}
tags = {
environment = local.prefix-spoke2
}
}
resource "azurerm_virtual_network_peering" "hub-spoke2-peer" {
name = "hub-spoke2-peer"
resource_group_name = azurerm_resource_group.hub-vnet-rg.name
virtual_network_name = azurerm_virtual_network.hub-vnet.name
remote_virtual_network_id = azurerm_virtual_network.spoke2-vnet.id
allow_virtual_network_access = true
allow_forwarded_traffic = true
allow_gateway_transit = true
use_remote_gateways = false
depends_on = [azurerm_virtual_network.spoke2-vnet, azurerm_virtual_network.hub-vnet, azurerm_virtual_network_gateway.hub-vnet-gateway]
}