Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Terraformのファイルを分割する #13

Merged
merged 5 commits into from
Aug 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions terraform/control-plane-disk.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
resource "sakuracloud_disk" "k8s-master-disk" {
count = lookup(var.master, terraform.workspace)
name = "k8s-master-${count.index + 1}-${terraform.workspace}"
source_archive_id = data.sakuracloud_archive.ubuntu-archive.id
size = lookup(var.master_disk, terraform.workspace)
tags = ["k8s", "${terraform.workspace}"]
timeouts {
create = "1h"
delete = "1h"
}
}
29 changes: 29 additions & 0 deletions terraform/control-plane-server.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
resource "sakuracloud_server" "k8s-master-server" {
count = lookup(var.master, terraform.workspace)
name = "k8s-master-${count.index + 1}-server-${terraform.workspace}"
core = lookup(var.master_cpu, terraform.workspace)
memory = lookup(var.master_mem, terraform.workspace)
disks = ["${sakuracloud_disk.k8s-master-disk[count.index].id}"]
tags = ["k8s", "${terraform.workspace}", "@nic-double-queue"]

network_interface {
upstream = sakuracloud_internet.k8s-external-switch.switch_id
}
network_interface {
upstream = sakuracloud_switch.k8s-internal-switch.id
user_ip_address = "192.168.100.1${count.index}"
}
disk_edit_parameter {
hostname = "k8s-master-${count.index + 1}-server-${terraform.workspace}"
password = var.cluster_pass
disable_pw_auth = "true"
ssh_key_ids = ["${sakuracloud_ssh_key_gen.gen_key.id}"]
ip_address = sakuracloud_internet.k8s-external-switch.ip_addresses[count.index + lookup(var.router, terraform.workspace)]
gateway = sakuracloud_internet.k8s-external-switch.gateway
netmask = lookup(var.external_subnet, terraform.workspace)
}
timeouts {
create = "1h"
delete = "1h"
}
}
11 changes: 11 additions & 0 deletions terraform/lb-disk.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
resource "sakuracloud_disk" "k8s-lb-disk" {
count = lookup(var.lb, terraform.workspace)
name = "k8s-lb-${count.index + 1}-${terraform.workspace}"
source_archive_id = data.sakuracloud_archive.ubuntu-archive.id
size = lookup(var.lb_disk, terraform.workspace)
tags = ["k8s", "${terraform.workspace}"]
timeouts {
create = "1h"
delete = "1h"
}
}
29 changes: 29 additions & 0 deletions terraform/lb-server.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
resource "sakuracloud_server" "k8s-lb-server" {
count = lookup(var.lb, terraform.workspace)
name = "k8s-lb-${count.index + 1}-server-${terraform.workspace}"
core = lookup(var.lb_cpu, terraform.workspace)
memory = lookup(var.lb_mem, terraform.workspace)
disks = ["${sakuracloud_disk.k8s-lb-disk[count.index].id}"]
tags = ["k8s", "${terraform.workspace}", "@nic-double-queue"]
network_interface {
upstream = sakuracloud_internet.k8s-external-switch.switch_id
}
network_interface {
upstream = sakuracloud_switch.k8s-internal-switch.id
user_ip_address = "192.168.100.3${count.index}"
}
disk_edit_parameter {
hostname = "k8s-lb-${count.index + 1}-server-${terraform.workspace}"
password = var.cluster_pass
disable_pw_auth = "true"
ssh_key_ids = ["${sakuracloud_ssh_key_gen.gen_key.id}"]
# note_ids = ["<ID>", "<ID>"]
ip_address = sakuracloud_internet.k8s-external-switch.ip_addresses[count.index + lookup(var.router, terraform.workspace) + lookup(var.master, terraform.workspace)]
gateway = sakuracloud_internet.k8s-external-switch.gateway
netmask = lookup(var.external_subnet, terraform.workspace)
}
timeouts {
create = "1h"
delete = "1h"
}
}
226 changes: 0 additions & 226 deletions terraform/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -38,229 +38,3 @@ resource "sakuracloud_ssh_key_gen" "gen_key" {
command = "rm -f ../id_rsa"
}
}

resource "sakuracloud_internet" "k8s-external-switch" {
name = "k8s-external-switch"
netmask = lookup(var.external_subnet, terraform.workspace)
band_width = 100
timeouts {
create = "1h"
delete = "1h"
}
}

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]
timeouts {
create = "1h"
delete = "1h"
}
}

resource "sakuracloud_switch" "k8s-internal-switch" {
name = "k8s-internal-switch"
timeouts {
create = "1h"
delete = "1h"
}
}

# disks
resource "sakuracloud_disk" "k8s-router-disk" {
count = lookup(var.router, terraform.workspace)
name = "k8s-router-${count.index + 1}-${terraform.workspace}"
source_archive_id = lookup(var.router_archive_id, terraform.workspace)
size = lookup(var.router_disk, terraform.workspace)
tags = ["k8s", "${terraform.workspace}"]
}

resource "sakuracloud_disk" "k8s-master-disk" {
count = lookup(var.master, terraform.workspace)
name = "k8s-master-${count.index + 1}-${terraform.workspace}"
source_archive_id = data.sakuracloud_archive.ubuntu-archive.id
size = lookup(var.master_disk, terraform.workspace)
tags = ["k8s", "${terraform.workspace}"]
timeouts {
create = "1h"
delete = "1h"
}
}

resource "sakuracloud_disk" "k8s-node-disk" {
count = lookup(var.node, terraform.workspace)
name = "k8s-node-${count.index + 1}-${terraform.workspace}"
source_archive_id = data.sakuracloud_archive.ubuntu-archive.id
size = lookup(var.node_disk, terraform.workspace)
tags = ["k8s", "${terraform.workspace}"]
timeouts {
create = "1h"
delete = "1h"
}
}

resource "sakuracloud_disk" "k8s-rook-disk" {
count = lookup(var.node, terraform.workspace)
name = "k8s-rook-${count.index + 1}-${terraform.workspace}"
size = lookup(var.node_rook_disk, terraform.workspace)
tags = ["k8s", "${terraform.workspace}"]
timeouts {
create = "1h"
delete = "1h"
}
}

resource "sakuracloud_disk" "k8s-lb-disk" {
count = lookup(var.lb, terraform.workspace)
name = "k8s-lb-${count.index + 1}-${terraform.workspace}"
source_archive_id = data.sakuracloud_archive.ubuntu-archive.id
size = lookup(var.lb_disk, terraform.workspace)
tags = ["k8s", "${terraform.workspace}"]
timeouts {
create = "1h"
delete = "1h"
}
}

# servers
resource "sakuracloud_server" "k8s-router" {
count = lookup(var.router, terraform.workspace)
name = "k8s-router-${count.index + 1}-${terraform.workspace}"
core = lookup(var.router_cpu, terraform.workspace)
memory = lookup(var.router_mem, terraform.workspace)
disks = ["${sakuracloud_disk.k8s-router-disk[count.index].id}"]
tags = ["k8s", "${terraform.workspace}", "@nic-double-queue"]

network_interface {
upstream = sakuracloud_internet.k8s-external-switch.switch_id
}

disk_edit_parameter {
hostname = "k8s-router-${count.index + 1}-${terraform.workspace}"
password = var.cluster_pass
disable_pw_auth = "false"
ip_address = sakuracloud_internet.k8s-external-switch.ip_addresses[count.index]
gateway = sakuracloud_internet.k8s-external-switch.gateway
netmask = lookup(var.external_subnet, terraform.workspace)
}
timeouts {
create = "1h"
delete = "1h"
}
}

resource "sakuracloud_server" "k8s-master-server" {
count = lookup(var.master, terraform.workspace)
name = "k8s-master-${count.index + 1}-server-${terraform.workspace}"
core = lookup(var.master_cpu, terraform.workspace)
memory = lookup(var.master_mem, terraform.workspace)
disks = ["${sakuracloud_disk.k8s-master-disk[count.index].id}"]
tags = ["k8s", "${terraform.workspace}", "@nic-double-queue"]

network_interface {
upstream = sakuracloud_internet.k8s-external-switch.switch_id
}
network_interface {
upstream = sakuracloud_switch.k8s-internal-switch.id
user_ip_address = "192.168.100.1${count.index}"
}
disk_edit_parameter {
hostname = "k8s-master-${count.index + 1}-server-${terraform.workspace}"
password = var.cluster_pass
disable_pw_auth = "true"
ssh_key_ids = ["${sakuracloud_ssh_key_gen.gen_key.id}"]
ip_address = sakuracloud_internet.k8s-external-switch.ip_addresses[count.index + lookup(var.router, terraform.workspace)]
gateway = sakuracloud_internet.k8s-external-switch.gateway
netmask = lookup(var.external_subnet, terraform.workspace)
}
timeouts {
create = "1h"
delete = "1h"
}
}

resource "sakuracloud_server" "k8s-node-server" {
count = lookup(var.node, terraform.workspace)
name = "k8s-node-${count.index + 1}-server-${terraform.workspace}"
core = lookup(var.node_cpu, terraform.workspace)
memory = lookup(var.node_mem, terraform.workspace)
disks = ["${sakuracloud_disk.k8s-node-disk[count.index].id}", "${sakuracloud_disk.k8s-rook-disk[count.index].id}"]
tags = ["k8s", "${terraform.workspace}", "@nic-double-queue"]
network_interface {
upstream = sakuracloud_internet.k8s-external-switch.switch_id
}
network_interface {
upstream = sakuracloud_switch.k8s-internal-switch.id
user_ip_address = "192.168.100.2${count.index}"
}
disk_edit_parameter {
hostname = "k8s-node-${count.index + 1}-server-${terraform.workspace}"
password = var.cluster_pass
disable_pw_auth = "true"
ssh_key_ids = ["${sakuracloud_ssh_key_gen.gen_key.id}"]
# note_ids = ["<ID>", "<ID>"]
ip_address = sakuracloud_internet.k8s-external-switch.ip_addresses[count.index + length(sakuracloud_internet.k8s-external-switch.ip_addresses) - 4]
gateway = sakuracloud_internet.k8s-external-switch.gateway
netmask = lookup(var.external_subnet, terraform.workspace)
}
timeouts {
create = "1h"
delete = "1h"
}
}

resource "sakuracloud_server" "k8s-lb-server" {
count = lookup(var.lb, terraform.workspace)
name = "k8s-lb-${count.index + 1}-server-${terraform.workspace}"
core = lookup(var.lb_cpu, terraform.workspace)
memory = lookup(var.lb_mem, terraform.workspace)
disks = ["${sakuracloud_disk.k8s-lb-disk[count.index].id}"]
tags = ["k8s", "${terraform.workspace}", "@nic-double-queue"]
network_interface {
upstream = sakuracloud_internet.k8s-external-switch.switch_id
}
network_interface {
upstream = sakuracloud_switch.k8s-internal-switch.id
user_ip_address = "192.168.100.3${count.index}"
}
disk_edit_parameter {
hostname = "k8s-lb-${count.index + 1}-server-${terraform.workspace}"
password = var.cluster_pass
disable_pw_auth = "true"
ssh_key_ids = ["${sakuracloud_ssh_key_gen.gen_key.id}"]
# note_ids = ["<ID>", "<ID>"]
ip_address = sakuracloud_internet.k8s-external-switch.ip_addresses[count.index + lookup(var.router, terraform.workspace) + lookup(var.master, terraform.workspace)]
gateway = sakuracloud_internet.k8s-external-switch.gateway
netmask = lookup(var.external_subnet, terraform.workspace)
}
timeouts {
create = "1h"
delete = "1h"
}
}

# output

output "vip_address" {
value = sakuracloud_internet.k8s-external-switch.ip_addresses[lookup(var.router, terraform.workspace) + lookup(var.master, terraform.workspace) + lookup(var.lb, terraform.workspace)]
}

output "external_address_range" {
value = "${sakuracloud_subnet.bgp-subnet.ip_addresses[0]}/${lookup(var.external_subnet, terraform.workspace)}"
}

output "k8s_router_ip_address" {
value = sakuracloud_server.k8s-router.*.ip_address
}

output "k8s_master_server_ip_address" {
value = sakuracloud_server.k8s-master-server.*.ip_address
}

output "k8s_node_server_ip_address" {
value = sakuracloud_server.k8s-node-server.*.ip_address
}

output "k8s_lb_server_ip_address" {
value = sakuracloud_server.k8s-lb-server.*.ip_address
}
18 changes: 18 additions & 0 deletions terraform/network-external.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
resource "sakuracloud_internet" "k8s-external-switch" {
name = "k8s-external-switch"
netmask = lookup(var.external_subnet, terraform.workspace)
band_width = 100
timeouts {
create = "1h"
delete = "1h"
}
}

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]
timeouts {
create = "1h"
delete = "1h"
}
}
7 changes: 7 additions & 0 deletions terraform/network-internal.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
resource "sakuracloud_switch" "k8s-internal-switch" {
name = "k8s-internal-switch"
timeouts {
create = "1h"
delete = "1h"
}
}
23 changes: 23 additions & 0 deletions terraform/output.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
output "vip_address" {
value = sakuracloud_internet.k8s-external-switch.ip_addresses[lookup(var.router, terraform.workspace) + lookup(var.master, terraform.workspace) + lookup(var.lb, terraform.workspace)]
}

output "external_address_range" {
value = "${sakuracloud_subnet.bgp-subnet.ip_addresses[0]}/${lookup(var.external_subnet, terraform.workspace)}"
}

output "k8s_router_ip_address" {
value = sakuracloud_server.k8s-router.*.ip_address
}

output "k8s_master_server_ip_address" {
value = sakuracloud_server.k8s-master-server.*.ip_address
}

output "k8s_node_server_ip_address" {
value = sakuracloud_server.k8s-node-server.*.ip_address
}

output "k8s_lb_server_ip_address" {
value = sakuracloud_server.k8s-lb-server.*.ip_address
}
7 changes: 7 additions & 0 deletions terraform/router-disk.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
resource "sakuracloud_disk" "k8s-router-disk" {
count = lookup(var.router, terraform.workspace)
name = "k8s-router-${count.index + 1}-${terraform.workspace}"
source_archive_id = lookup(var.router_archive_id, terraform.workspace)
size = lookup(var.router_disk, terraform.workspace)
tags = ["k8s", "${terraform.workspace}"]
}
25 changes: 25 additions & 0 deletions terraform/router-server.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
resource "sakuracloud_server" "k8s-router" {
count = lookup(var.router, terraform.workspace)
name = "k8s-router-${count.index + 1}-${terraform.workspace}"
core = lookup(var.router_cpu, terraform.workspace)
memory = lookup(var.router_mem, terraform.workspace)
disks = ["${sakuracloud_disk.k8s-router-disk[count.index].id}"]
tags = ["k8s", "${terraform.workspace}", "@nic-double-queue"]

network_interface {
upstream = sakuracloud_internet.k8s-external-switch.switch_id
}

disk_edit_parameter {
hostname = "k8s-router-${count.index + 1}-${terraform.workspace}"
password = var.cluster_pass
disable_pw_auth = "false"
ip_address = sakuracloud_internet.k8s-external-switch.ip_addresses[count.index]
gateway = sakuracloud_internet.k8s-external-switch.gateway
netmask = lookup(var.external_subnet, terraform.workspace)
}
timeouts {
create = "1h"
delete = "1h"
}
}
Loading
Loading