-
Notifications
You must be signed in to change notification settings - Fork 0
/
on-prem.tf
153 lines (127 loc) · 4.73 KB
/
on-prem.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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
locals {
onprem-location = var.onpremlocation
prefix-onprem = "${var.global_prefix}-onprem"
}
resource "azurerm_resource_group" "onprem-vnet-rg" {
name = "${local.prefix-onprem}-rg"
location = local.onprem-location
}
resource "azurerm_virtual_network" "onprem-vnet" {
name = "onprem-vnet"
location = azurerm_resource_group.onprem-vnet-rg.location
resource_group_name = azurerm_resource_group.onprem-vnet-rg.name
address_space = ["192.168.0.0/16"]
tags = {
environment = local.prefix-onprem
}
}
resource "azurerm_subnet" "onprem-gateway-subnet" {
name = "GatewaySubnet"
resource_group_name = azurerm_resource_group.onprem-vnet-rg.name
virtual_network_name = azurerm_virtual_network.onprem-vnet.name
address_prefix = "192.168.255.224/27"
}
resource "azurerm_subnet" "onprem-mgmt" {
name = "mgmt"
resource_group_name = azurerm_resource_group.onprem-vnet-rg.name
virtual_network_name = azurerm_virtual_network.onprem-vnet.name
address_prefix = "192.168.1.128/25"
}
resource "azurerm_public_ip" "onprem-pip" {
name = "${local.prefix-onprem}-pip"
location = azurerm_resource_group.onprem-vnet-rg.location
resource_group_name = azurerm_resource_group.onprem-vnet-rg.name
allocation_method = "Dynamic"
tags = {
environment = local.prefix-onprem
}
}
resource "azurerm_network_interface" "onprem-nic" {
name = "${local.prefix-onprem}-nic"
location = azurerm_resource_group.onprem-vnet-rg.location
resource_group_name = azurerm_resource_group.onprem-vnet-rg.name
enable_ip_forwarding = true
ip_configuration {
name = local.prefix-onprem
subnet_id = azurerm_subnet.onprem-mgmt.id
private_ip_address_allocation = "Dynamic"
public_ip_address_id = azurerm_public_ip.onprem-pip.id
}
}
# Create Network Security Group and rule
resource "azurerm_network_security_group" "onprem-nsg" {
name = "${local.prefix-onprem}-nsg"
location = azurerm_resource_group.onprem-vnet-rg.location
resource_group_name = azurerm_resource_group.onprem-vnet-rg.name
security_rule {
name = "SSH"
priority = 1001
direction = "Inbound"
access = "Allow"
protocol = "Tcp"
source_port_range = "*"
destination_port_range = "22"
source_address_prefix = "*"
destination_address_prefix = "*"
}
tags = {
environment = "onprem"
}
}
resource "azurerm_subnet_network_security_group_association" "mgmt-nsg-association" {
subnet_id = azurerm_subnet.onprem-mgmt.id
network_security_group_id = azurerm_network_security_group.onprem-nsg.id
}
resource "azurerm_virtual_machine" "onprem-vm" {
name = "${local.prefix-onprem}-vm"
location = azurerm_resource_group.onprem-vnet-rg.location
resource_group_name = azurerm_resource_group.onprem-vnet-rg.name
network_interface_ids = [azurerm_network_interface.onprem-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-onprem}-vm"
admin_username = var.username
admin_password = var.password
}
os_profile_linux_config {
disable_password_authentication = false
}
tags = {
environment = local.prefix-onprem
}
}
resource "azurerm_public_ip" "onprem-vpn-gateway1-pip" {
name = "${local.prefix-onprem}-vpn-gateway1-pip"
location = azurerm_resource_group.onprem-vnet-rg.location
resource_group_name = azurerm_resource_group.onprem-vnet-rg.name
allocation_method = "Dynamic"
}
resource "azurerm_virtual_network_gateway" "onprem-vpn-gateway" {
name = "onprem-vpn-gateway1"
location = azurerm_resource_group.onprem-vnet-rg.location
resource_group_name = azurerm_resource_group.onprem-vnet-rg.name
type = "Vpn"
vpn_type = "RouteBased"
active_active = false
enable_bgp = false
sku = "VpnGw1"
ip_configuration {
name = "vnetGatewayConfig"
public_ip_address_id = azurerm_public_ip.onprem-vpn-gateway1-pip.id
private_ip_address_allocation = "Dynamic"
subnet_id = azurerm_subnet.onprem-gateway-subnet.id
}
depends_on = [azurerm_public_ip.onprem-vpn-gateway1-pip]
}