diff --git a/terraform/control-plane-disk.tf b/terraform/control-plane-disk.tf index 45601d6..06fc958 100644 --- a/terraform/control-plane-disk.tf +++ b/terraform/control-plane-disk.tf @@ -1,6 +1,6 @@ resource "sakuracloud_disk" "k8s_control_plane_disk" { count = lookup(var.control_plane, terraform.workspace, 0) - name = "k8s-control-plane-${count.index + 1}-${terraform.workspace}" + name = "k8s-${terraform.workspace}-control-plane-${count.index + 1}" source_archive_id = data.sakuracloud_archive.ubuntu_archive.id size = lookup(var.control_plane_disk, terraform.workspace, 0) tags = ["k8s", terraform.workspace] diff --git a/terraform/control-plane-server.tf b/terraform/control-plane-server.tf index 3b75f51..9649833 100644 --- a/terraform/control-plane-server.tf +++ b/terraform/control-plane-server.tf @@ -1,6 +1,6 @@ resource "sakuracloud_server" "k8s_control_plane" { count = lookup(var.control_plane, terraform.workspace, 0) - name = "k8s-control-plane-${count.index + 1}-${terraform.workspace}" + name = "k8s-${terraform.workspace}-control-plane-${count.index + 1}" core = lookup(var.control_plane_cpu, terraform.workspace, 0) memory = lookup(var.control_plane_mem, terraform.workspace, 0) disks = [sakuracloud_disk.k8s_control_plane_disk[count.index].id] @@ -14,7 +14,7 @@ resource "sakuracloud_server" "k8s_control_plane" { user_ip_address = "192.168.100.1${count.index}" } disk_edit_parameter { - hostname = "k8s-control-plane-${count.index + 1}-${terraform.workspace}" + hostname = "k8s-${terraform.workspace}-control-plane-${count.index + 1}" password = var.cluster_pass disable_pw_auth = "true" ssh_key_ids = [sakuracloud_ssh_key_gen.gen_key.id] diff --git a/terraform/network-external.tf b/terraform/network-external.tf index d10e2fa..be18177 100644 --- a/terraform/network-external.tf +++ b/terraform/network-external.tf @@ -10,7 +10,8 @@ resource "sakuracloud_internet" "k8s_external_switch" { resource "sakuracloud_subnet" "bgp_subnet" { internet_id = sakuracloud_internet.k8s_external_switch.id - next_hop = sakuracloud_internet.k8s_external_switch.ip_addresses[length(sakuracloud_internet.k8s_external_switch.ip_addresses) - 11] + next_hop = sakuracloud_server.k8s_router[0].ip_address + netmask = 28 timeouts { create = "1h" delete = "1h" diff --git a/terraform/output.tf b/terraform/output.tf index 74f58c8..d03ed5a 100644 --- a/terraform/output.tf +++ b/terraform/output.tf @@ -1,9 +1,9 @@ output "vip_address" { - value = sakuracloud_internet.k8s_external_switch.ip_addresses[lookup(var.router, terraform.workspace, 0) + lookup(var.control_plane, terraform.workspace, 0)] + value = sakuracloud_internet.k8s_external_switch.ip_addresses[lookup(var.router, terraform.workspace, 0) + lookup(var.control_plane, terraform.workspace, 0) + lookup(var.worker_node, terraform.workspace, 0)] } output "external_address_range" { - value = format("%s/%s", sakuracloud_subnet.bgp_subnet.ip_addresses[0], lookup(var.external_subnet, terraform.workspace, 0)) + value = format("%s/%s", sakuracloud_subnet.bgp_subnet.ip_addresses[0], 28) } output "k8s_router_ip_address" { diff --git a/terraform/router-disk.tf b/terraform/router-disk.tf index 4c78c6b..8bf5f57 100644 --- a/terraform/router-disk.tf +++ b/terraform/router-disk.tf @@ -1,6 +1,6 @@ resource "sakuracloud_disk" "k8s_router_disk" { count = lookup(var.router, terraform.workspace, 0) - name = "k8s-router-${count.index + 1}-${terraform.workspace}" + name = "k8s-${terraform.workspace}-router-${count.index + 1}" source_archive_id = data.sakuracloud_archive.ubuntu_archive.id size = lookup(var.router_disk, terraform.workspace, 0) tags = ["k8s", terraform.workspace] diff --git a/terraform/router-server.tf b/terraform/router-server.tf index 6d0b99f..c9577e0 100644 --- a/terraform/router-server.tf +++ b/terraform/router-server.tf @@ -1,6 +1,6 @@ resource "sakuracloud_server" "k8s_router" { count = lookup(var.router, terraform.workspace, 0) - name = "k8s-router-${count.index + 1}-${terraform.workspace}" + name = "k8s-${terraform.workspace}-router-${count.index + 1}" core = lookup(var.router_cpu, terraform.workspace, 0) memory = lookup(var.router_mem, terraform.workspace, 0) disks = [sakuracloud_disk.k8s_router_disk[count.index].id] @@ -14,7 +14,7 @@ resource "sakuracloud_server" "k8s_router" { user_ip_address = "192.168.100.${count.index}" } disk_edit_parameter { - hostname = "k8s-router-${count.index + 1}-${terraform.workspace}" + hostname = "k8s-${terraform.workspace}-router-${count.index + 1}" password = var.cluster_pass disable_pw_auth = "true" ssh_key_ids = [sakuracloud_ssh_key_gen.gen_key.id] diff --git a/terraform/vars.tf b/terraform/vars.tf index d3fdf65..6c94f99 100644 --- a/terraform/vars.tf +++ b/terraform/vars.tf @@ -6,16 +6,14 @@ variable "cluster_pass" { variable "external_subnet" { type = map(any) default = { - wsp = 28 - dev = 28 - prd = 28 + dev = 27 + prd = 27 } } variable "control_plane" { type = map(any) default = { - wsp = 3 dev = 3 prd = 3 } @@ -23,101 +21,86 @@ variable "control_plane" { variable "control_plane_cpu" { type = map(any) default = { - wsp = 4 - dev = 4 - prd = 4 + dev = 2 + prd = 2 } } variable "control_plane_mem" { type = map(any) default = { - wsp = 8 - dev = 8 - prd = 8 + dev = 2 + prd = 2 } } variable "control_plane_disk" { type = map(any) default = { - wsp = 40 - dev = 40 - prd = 40 + dev = 20 + prd = 20 } } variable "worker_node" { type = map(any) default = { - wsp = 3 - dev = 3 - prd = 3 + dev = 8 + prd = 8 } } variable "worker_node_cpu" { type = map(any) default = { - wsp = 4 - dev = 4 - prd = 4 + dev = 2 + prd = 2 } } variable "worker_node_mem" { type = map(any) default = { - wsp = 16 - dev = 8 - prd = 16 + dev = 2 + prd = 2 } } variable "worker_node_disk" { type = map(any) default = { - wsp = 40 - dev = 40 - prd = 40 + dev = 20 + prd = 20 } } - variable "worker_node_rook_disk" { type = map(any) default = { - wsp = 100 - dev = 40 - prd = 100 + dev = 20 + prd = 20 } } variable "router" { type = map(any) default = { - wsp = "1" - dev = "1" - prd = "1" - bgp = "1" + dev = 1 + prd = 1 } } - variable "router_cpu" { type = map(any) default = { - wsp = "2" - dev = "2" - prd = "2" + dev = 2 + prd = 2 } } variable "router_mem" { type = map(any) default = { - wsp = "2" - dev = "2" - prd = "2" + dev = 2 + prd = 2 } } variable "router_disk" { type = map(any) default = { - wsp = "20" - dev = "20" - prd = "20" + dev = 20 + prd = 20 } } diff --git a/terraform/worker-node-disk.tf b/terraform/worker-node-disk.tf index b7f48fe..c7f1857 100644 --- a/terraform/worker-node-disk.tf +++ b/terraform/worker-node-disk.tf @@ -1,6 +1,6 @@ resource "sakuracloud_disk" "k8s_worker_node_disk" { count = lookup(var.worker_node, terraform.workspace, 0) - name = "k8s-worker-node-${count.index + 1}-${terraform.workspace}" + name = "k8s-${terraform.workspace}-worker-node-${count.index + 1}" source_archive_id = data.sakuracloud_archive.ubuntu_archive.id size = lookup(var.worker_node_disk, terraform.workspace, 0) tags = ["k8s", terraform.workspace] @@ -12,7 +12,7 @@ resource "sakuracloud_disk" "k8s_worker_node_disk" { resource "sakuracloud_disk" "k8s_rook_disk" { count = lookup(var.worker_node, terraform.workspace, 0) - name = "k8s-rook-${count.index + 1}-${terraform.workspace}" + name = "k8s-${terraform.workspace}-rook-${count.index + 1}" size = lookup(var.worker_node_rook_disk, terraform.workspace, 0) tags = ["k8s", terraform.workspace] timeouts { diff --git a/terraform/worker-node-server.tf b/terraform/worker-node-server.tf index 1538105..b7fc334 100644 --- a/terraform/worker-node-server.tf +++ b/terraform/worker-node-server.tf @@ -1,6 +1,6 @@ resource "sakuracloud_server" "k8s_worker_node" { count = lookup(var.worker_node, terraform.workspace, 0) - name = "k8s-worker-node-${count.index + 1}-${terraform.workspace}" + name = "k8s-${terraform.workspace}-worker-node-${count.index + 1}" core = lookup(var.worker_node_cpu, terraform.workspace, 0) memory = lookup(var.worker_node_mem, terraform.workspace, 0) disks = [sakuracloud_disk.k8s_worker_node_disk[count.index].id, sakuracloud_disk.k8s_rook_disk[count.index].id] @@ -13,12 +13,12 @@ resource "sakuracloud_server" "k8s_worker_node" { user_ip_address = "192.168.100.2${count.index}" } disk_edit_parameter { - hostname = "k8s-worker-node-${count.index + 1}-${terraform.workspace}" + hostname = "k8s-${terraform.workspace}-worker-node-${count.index + 1}" password = var.cluster_pass disable_pw_auth = "true" ssh_key_ids = [sakuracloud_ssh_key_gen.gen_key.id] # note_ids = ["", ""] - ip_address = sakuracloud_internet.k8s_external_switch.ip_addresses[count.index + length(sakuracloud_internet.k8s_external_switch.ip_addresses) - 4] + ip_address = sakuracloud_internet.k8s_external_switch.ip_addresses[count.index + lookup(var.router, terraform.workspace, 0) + lookup(var.control_plane, terraform.workspace, 0)] gateway = sakuracloud_internet.k8s_external_switch.gateway netmask = lookup(var.external_subnet, terraform.workspace, 0) }