-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.tf
180 lines (161 loc) · 5.36 KB
/
main.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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
terraform {
required_providers {
azurerm = {
source = "hashicorp/azurerm"
}
azapi = {
source = "azure/azapi"
}
helm = {
source = "hashicorp/helm"
}
}
}
provider "azapi" {}
provider "azurerm" {
features {}
}
provider "helm" {
kubernetes {
host = data.azurerm_kubernetes_cluster.credentials.kube_config.0.host
client_certificate = base64decode(data.azurerm_kubernetes_cluster.credentials.kube_config.0.client_certificate)
client_key = base64decode(data.azurerm_kubernetes_cluster.credentials.kube_config.0.client_key)
cluster_ca_certificate = base64decode(data.azurerm_kubernetes_cluster.credentials.kube_config.0.cluster_ca_certificate)
}
}
data "azurerm_kubernetes_cluster" "credentials" {
depends_on = [azurerm_kubernetes_cluster.spoke_1_aks]
name = azurerm_kubernetes_cluster.spoke_1_aks.name
resource_group_name = azurerm_resource_group.rg.name
}
resource "azurerm_resource_group" "rg" {
name = var.resource_group_name
location = var.location
}
resource "azapi_resource" "vwan" {
type = "Microsoft.Network/virtualWans@2023-04-01"
name = "${var.resource_group_name}-vwan"
location = var.location
parent_id = azurerm_resource_group.rg.id
body = jsonencode({
properties = {
allowVnetToVnetTraffic = true
type = "Standard"
}
})
}
resource "azapi_resource" "vhub" {
type = "Microsoft.Network/virtualHubs@2023-04-01"
name = "${var.resource_group_name}-vhub"
location = var.location
parent_id = azurerm_resource_group.rg.id
body = jsonencode({
properties = {
addressPrefix = var.vwan_hub_address_space
sku = "Standard"
virtualWan = {
id = azapi_resource.vwan.id
}
}
})
}
resource "azapi_resource" "vhub_connections" {
type = "Microsoft.Network/virtualHubs/hubVirtualNetworkConnections@2023-04-01"
name = "${var.resource_group_name}-vhub-connections"
parent_id = azapi_resource.vhub.id
body = jsonencode({
properties = {
allowHubToRemoteVnetTransit = true
allowRemoteVnetToUseHubVnetGateways = false
enableInternetSecurity = false
remoteVirtualNetwork = {
id = azurerm_virtual_network.spoke_1_vnet.id
}
}
})
}
resource "azapi_resource" "vhub-bgpconnection-1" {
type = "Microsoft.Network/virtualHubs/bgpConnections@2023-04-01"
name = "${var.resource_group_name}-vhub-bgpconnection-1"
parent_id = azapi_resource.vhub.id
body = jsonencode({
properties = {
hubVirtualNetworkConnection = {
id = azapi_resource.vhub_connections.id
}
peerAsn = var.vwan_hub_bgpconnection_asn
peerIp = var.vwan_hub_bgpconnection_1_peer_ip
}
})
depends_on = [azapi_resource.vhub_connections]
}
resource "azapi_resource" "vhub-bgpconnection-2" {
type = "Microsoft.Network/virtualHubs/bgpConnections@2023-04-01"
name = "${var.resource_group_name}-vhub-bgpconnection-2"
parent_id = azapi_resource.vhub.id
body = jsonencode({
properties = {
hubVirtualNetworkConnection = {
id = azapi_resource.vhub_connections.id
}
peerAsn = var.vwan_hub_bgpconnection_asn
peerIp = var.vwan_hub_bgpconnection_2_peer_ip
}
})
depends_on = [azapi_resource.vhub-bgpconnection-1]
}
resource "azurerm_virtual_network" "spoke_1_vnet" {
name = "${var.resource_group_name}-spoke-1-vnet"
address_space = var.spoke_1_vnet_address_space
location = var.location
resource_group_name = azurerm_resource_group.rg.name
}
resource "azurerm_subnet" "spoke_1_subnet" {
name = "${var.resource_group_name}-spoke-1-subnet"
resource_group_name = azurerm_resource_group.rg.name
virtual_network_name = azurerm_virtual_network.spoke_1_vnet.name
address_prefixes = var.spoke_1_subnet_address_prefixes
}
data "azurerm_kubernetes_service_versions" "current" {
location = var.location
version_prefix = var.kubernetes_version
}
resource "azurerm_kubernetes_cluster" "spoke_1_aks" {
name = "${var.resource_group_name}-spoke-1-aks"
location = var.location
resource_group_name = azurerm_resource_group.rg.name
kubernetes_version = data.azurerm_kubernetes_service_versions.current.latest_version
private_cluster_enabled = false
dns_prefix = "aks"
default_node_pool {
name = "default"
node_count = var.aks_nodepool_nodes_count
vm_size = var.aks_nodepool_vm_size
vnet_subnet_id = azurerm_subnet.spoke_1_subnet.id
type = "VirtualMachineScaleSets"
node_labels = {
route-reflector = true
}
}
identity {
type = "SystemAssigned"
}
network_profile {
network_plugin = "none"
service_cidr = var.aks_service_cidr
dns_service_ip = var.aks_dns_service_ip
}
}
resource "helm_release" "calico" {
name = "calico"
chart = "tigera-operator"
repository = "https://docs.projectcalico.org/charts"
version = var.calico_version
namespace = "tigera-operator"
create_namespace = true
values = [templatefile("${path.module}/helm_values/values-calico.yaml", {
pod_cidr = "${var.calico_pod_cidr}"
calico_encap = "VXLAN"
})]
depends_on = [azurerm_kubernetes_cluster.spoke_1_aks]
}