-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathazure.tf
151 lines (127 loc) · 4.35 KB
/
azure.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
resource "azurerm_resource_group" "peer_vnet" {
name = format("%s-peer", var.azure_resource_group)
location = var.azure_region
}
resource "azurerm_network_security_group" "allow_ce" {
name = "allow-ce"
resource_group_name = azurerm_resource_group.peer_vnet.name
location = azurerm_resource_group.peer_vnet.location
security_rule {
name = "allow-ingress-ce"
priority = 100
direction = "Inbound"
access = "Allow"
protocol = "*"
source_port_range = "*"
destination_port_range = "*"
source_address_prefix = lookup(var.azure_subnet_ce_cidr, "inside", "")
destination_address_prefix = "*"
}
}
module "vnet" {
source = "Azure/vnet/azurerm"
resource_group_name = azurerm_resource_group.peer_vnet.name
address_space = [var.azure_client_vnet_cidr]
subnet_prefixes = local.azure_peer_subnets
subnet_names = ["subnet1", "subnet2"]
nsg_ids = {
subnet1 = azurerm_network_security_group.allow_ce.id
subnet2 = azurerm_network_security_group.allow_ce.id
}
route_tables_ids = {
subnet1 = azurerm_route_table.peer_vnet_route_table.id
subnet2 = azurerm_route_table.peer_vnet_route_table.id
}
tags = {
"Name" = format("%s", var.mcn_name)
"usecase" = "multi-cloud-networking"
}
}
data "azurerm_network_interface" "sli" {
depends_on = [
volterra_tf_params_action.apply_az_vnet
]
name = "master-0-sli"
resource_group_name = var.azure_resource_group
}
resource "azurerm_route_table" "peer_vnet_route_table" {
name = "peer-vnet-route-table"
resource_group_name = azurerm_resource_group.peer_vnet.name
location = azurerm_resource_group.peer_vnet.location
}
resource "azurerm_route" "peer_vnet_route" {
name = "peer-vnet-route"
resource_group_name = azurerm_resource_group.peer_vnet.name
route_table_name = azurerm_route_table.peer_vnet.name
address_prefix = "0.0.0.0/0"
next_hop_type = "VirtualAppliance"
next_hop_in_ip_address = data.azurerm_network_interface.sli.private_ip_address
}
resource "azurerm_network_interface" "green" {
name = "green-nic"
location = azurerm_resource_group.peer_vnet.location
resource_group_name = azurerm_resource_group.peer_vnet.name
ip_configuration {
name = "internal"
subnet_id = element(module.vnet.vnet_subnets, 0)
private_ip_address_allocation = "Dynamic"
}
}
resource "azurerm_network_interface" "red" {
name = "red-nic"
location = azurerm_resource_group.peer_vnet.location
resource_group_name = azurerm_resource_group.peer_vnet.name
ip_configuration {
name = "internal"
subnet_id = element(module.vnet.vnet_subnets, 1)
private_ip_address_allocation = "Dynamic"
}
}
resource "azurerm_linux_virtual_machine" "green" {
name = "green-machine"
resource_group_name = azurerm_resource_group.peer_vnet.name
location = azurerm_resource_group.peer_vnet.location
size = "Standard_F2"
admin_username = "azureuser"
network_interface_ids = [
azurerm_network_interface.green.id,
]
admin_ssh_key {
username = "azureuser"
public_key = file("~/.ssh/id_rsa.pub")
}
os_disk {
caching = "ReadWrite"
storage_account_type = "Standard_LRS"
}
source_image_reference {
publisher = "Canonical"
offer = "UbuntuServer"
sku = "16.04-LTS"
version = "latest"
}
}
resource "azurerm_linux_virtual_machine" "red" {
name = "red-machine"
resource_group_name = azurerm_resource_group.peer_vnet.name
location = azurerm_resource_group.peer_vnet.location
size = "Standard_F2"
admin_username = "azureuser"
network_interface_ids = [
azurerm_network_interface.red.id,
]
admin_ssh_key {
username = "azureuser"
public_key = file("~/.ssh/id_rsa.pub")
}
os_disk {
caching = "ReadWrite"
storage_account_type = "Standard_LRS"
}
source_image_reference {
publisher = "Canonical"
offer = "UbuntuServer"
sku = "16.04-LTS"
version = "latest"
}
}