-
Notifications
You must be signed in to change notification settings - Fork 19
/
instances-web.tf
157 lines (133 loc) · 5.24 KB
/
instances-web.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
resource "oci_core_instance_pool" "web" {
for_each = { for idx, ad in local.zones : ad => idx + 1 }
compartment_id = var.compartment_ocid
instance_configuration_id = oci_core_instance_configuration.web[each.key].id
size = lookup(var.instances[each.key], "web_count", 0)
state = "RUNNING"
display_name = "${var.project}-web-${each.value}"
defined_tags = merge(var.tags, { "Kubernetes.Role" = "web" })
placement_configurations {
availability_domain = local.network_public[each.key].availability_domain
fault_domains = data.oci_identity_fault_domains.domains[each.key].fault_domains.*.name
primary_subnet_id = local.network_public[each.key].id
}
load_balancers {
backend_set_name = oci_load_balancer_backend_set.web.name
load_balancer_id = oci_load_balancer_load_balancer.web.id
port = 80
vnic_selection = "primaryvnic"
}
load_balancers {
backend_set_name = oci_load_balancer_backend_set.webs.name
load_balancer_id = oci_load_balancer_load_balancer.web.id
port = 443
vnic_selection = "primaryvnic"
}
lifecycle {
ignore_changes = [
state,
defined_tags,
load_balancers
]
}
}
locals {
web_labels = "project.io/node-pool=web"
}
resource "oci_core_instance_configuration" "web" {
for_each = { for idx, ad in local.zones : ad => idx + 1 }
compartment_id = var.compartment_ocid
display_name = "${var.project}-web-${each.value}"
defined_tags = merge(var.tags, { "Kubernetes.Role" = "web" })
instance_details {
instance_type = "compute"
launch_details {
compartment_id = var.compartment_ocid
display_name = "${var.project}-web"
is_pv_encryption_in_transit_enabled = true
preferred_maintenance_action = "LIVE_MIGRATE"
launch_mode = "NATIVE"
shape = lookup(var.instances[each.key], "web_instance_shape", "VM.Standard.E2.1.Micro")
shape_config {
ocpus = lookup(var.instances[each.key], "web_instance_ocpus", 1)
memory_in_gbs = lookup(var.instances[each.key], "web_instance_memgb", 1)
}
metadata = {
user_data = base64encode(templatefile("${path.module}/templates/web.yaml.tpl",
merge(var.kubernetes, {
lbv4 = local.lbv4_local
clusterDns = cidrhost(split(",", var.kubernetes["serviceSubnets"])[0], 10)
nodeSubnets = local.network_public[each.key].cidr_block
labels = local.web_labels
})
))
}
source_details {
source_type = "image"
image_id = data.oci_core_images.talos_x64.images[0].id
boot_volume_size_in_gbs = "50"
}
create_vnic_details {
display_name = "${var.project}-web"
assign_private_dns_record = false
assign_public_ip = true
nsg_ids = [local.nsg_talos, local.nsg_cilium, local.nsg_web]
subnet_id = local.network_public[each.key].id
skip_source_dest_check = true
}
agent_config {
are_all_plugins_disabled = true
is_management_disabled = true
is_monitoring_disabled = true
}
launch_options {
network_type = "PARAVIRTUALIZED"
}
instance_options {
are_legacy_imds_endpoints_disabled = true
}
availability_config {
recovery_action = "RESTORE_INSTANCE"
}
}
}
lifecycle {
create_before_destroy = "true"
ignore_changes = [
defined_tags
]
}
}
# data "oci_core_instance_pool_instances" "web" {
# compartment_id = var.compartment_ocid
# instance_pool_id = oci_core_instance_pool.web.id
# }
# locals {
# lbv4_web_instances = local.lbv4_web_enable && length(data.oci_core_instance_pool_instances.web.instances) > 0
# }
# resource "oci_core_ipv6" "web" {
# for_each = data.oci_core_instance_pool_instances.web.instances
# vnic_id = data.oci_core_vnic_attachments.contolplane[count.index].vnic_attachments[0]["vnic_id"]
# }
# resource "oci_network_load_balancer_backend" "web_http" {
# for_each = local.lbv4_web_enable ? { for instances in data.oci_core_instance_pool_instances.web.instances.* : instances.display_name => instances.id } : {}
# backend_set_name = oci_network_load_balancer_backend_set.web_http[0].name
# network_load_balancer_id = oci_network_load_balancer_network_load_balancer.web[0].id
# port = 80
# name = "web-http-lb"
# target_id = each.value
# depends_on = [
# oci_core_instance_pool.web
# ]
# }
# resource "oci_network_load_balancer_backend" "web_https" {
# for_each = local.lbv4_web_enable ? { for instances in data.oci_core_instance_pool_instances.web.instances.* : instances.display_name => instances.id } : {}
# backend_set_name = oci_network_load_balancer_backend_set.web_https[0].name
# network_load_balancer_id = oci_network_load_balancer_network_load_balancer.web[0].id
# port = 443
# name = "web-https-lb"
# target_id = each.value
# depends_on = [
# oci_core_instance_pool.web
# ]
# }