103 lines
No EOL
3 KiB
HCL
103 lines
No EOL
3 KiB
HCL
resource "oci_containerengine_cluster" "containerengine_cluster" {
|
|
compartment_id = var.oke_compartment
|
|
|
|
cluster_pod_network_options {
|
|
cni_type = "OCI_VCN_IP_NATIVE"
|
|
}
|
|
|
|
endpoint_config {
|
|
is_public_ip_enabled = "${var.oke_api_endpoint_public}"
|
|
# Se usa existente, pega o ID; se não, pega o ID da subnet criada pelo módulo
|
|
subnet_id = oci_core_subnet.api_endpoint_subnet.id
|
|
}
|
|
kubernetes_version = local.latest_k8s_version
|
|
name = "${var.oke_cluster_name}"
|
|
options {
|
|
admission_controller_options {
|
|
is_pod_security_policy_enabled = "false"
|
|
}
|
|
persistent_volume_config {
|
|
freeform_tags = {
|
|
"OKEclusterName" = "cluster-${var.oke_cluster_name}"
|
|
}
|
|
}
|
|
service_lb_config {
|
|
freeform_tags = {
|
|
"OKEclusterName" = "cluster-${var.oke_cluster_name}"
|
|
}
|
|
}
|
|
service_lb_subnet_ids = [oci_core_subnet.lb_subnet.id]
|
|
}
|
|
type = "ENHANCED_CLUSTER"
|
|
vcn_id = var.vcn_id
|
|
|
|
freeform_tags = {
|
|
"ManagedBy" = "Terraform"
|
|
}
|
|
}
|
|
|
|
resource "oci_containerengine_node_pool" "cluster_app_node_pool" {
|
|
cluster_id = oci_containerengine_cluster.containerengine_cluster.id
|
|
compartment_id = var.oke_compartment
|
|
kubernetes_version = local.latest_k8s_version
|
|
name = "${var.oke_cluster_name}"
|
|
node_shape = var.oke_node_shape
|
|
|
|
depends_on = [
|
|
oci_identity_policy.oke_all_policy
|
|
]
|
|
|
|
node_source_details {
|
|
# Pega o ID da imagem que ficou no topo da lista (a mais recente)
|
|
image_id = local.selected_image_id
|
|
source_type = "IMAGE"
|
|
}
|
|
|
|
lifecycle {
|
|
ignore_changes = [
|
|
node_config_details[0].size
|
|
]
|
|
}
|
|
|
|
node_config_details {
|
|
|
|
# Tamanho TOTAL do pool (o OKE distribui os nós entre as ADs acima)
|
|
size = var.oke_nodepool_size
|
|
|
|
# 2. O bloco dinâmico cria uma 'placement_config' para cada AD encontrada
|
|
dynamic "placement_configs" {
|
|
for_each = data.oci_identity_availability_domains.ads.availability_domains
|
|
content {
|
|
availability_domain = placement_configs.value.name
|
|
# Subnet onde ficam as instâncias (Workers)
|
|
subnet_id = oci_core_subnet.node_subnet.id
|
|
}
|
|
}
|
|
# Configuração da Subnet de Pods (VCN-Native)
|
|
node_pool_pod_network_option_details {
|
|
cni_type = "OCI_VCN_IP_NATIVE"
|
|
|
|
# Lista das subnets de pods (geralmente uma regional)
|
|
pod_subnet_ids = [oci_core_subnet.pods_subnet.id]
|
|
|
|
# Opcional: NSGs específicos para os PODS
|
|
# pod_nsg_ids = [oci_core_network_security_group.pod_nsg.id]
|
|
|
|
# Opcional: Para regiões de 1 AD, você pode querer forçar a
|
|
# distribuição entre Fault Domains específicos
|
|
# fault_domains = ["FAULT-DOMAIN-1", "FAULT-DOMAIN-2", "FAULT-DOMAIN-3"]
|
|
}
|
|
}
|
|
|
|
node_shape_config {
|
|
memory_in_gbs = var.oke_node_shape_memory_gb
|
|
ocpus = var.oke_node_shape_ocpus
|
|
}
|
|
|
|
freeform_tags = {
|
|
"ManagedBy" = "Terraform"
|
|
}
|
|
}
|
|
|
|
|
|
# terraform destroy -auto-approve && terraform apply -auto-approve |