-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathmain.tf
104 lines (98 loc) · 4.46 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
locals {
node_config = {
cluster_name = var.cluster_name
keypair_name = module.keypair.keypair_name
ssh_key_file = var.ssh_key_file
system_user = var.system_user
use_ssh_agent = var.use_ssh_agent
network_id = module.network.nodes_net_id
subnet_id = module.network.nodes_subnet_id
secgroup_id = module.secgroup.secgroup_id
server_affinity = var.server_group_affinity
config_drive = var.nodes_config_drive
floating_ip_pool = var.public_net_name
user_data = var.user_data_file != null ? file(var.user_data_file) : null
boot_from_volume = var.boot_from_volume
boot_volume_size = var.boot_volume_size
boot_volume_type = var.boot_volume_type
availability_zones = var.availability_zones
bootstrap_server = module.server.internal_ip[0]
bastion_host = module.server.floating_ip[0]
rke2_token = random_string.rke2_token.result
registries_conf = var.registries_conf
proxy_url = var.proxy_url
no_proxy = concat(["localhost", "127.0.0.1", "169.254.169.254", "127.0.0.0/8", "169.254.0.0/16", "10.0.0.0/8", "172.16.0.0/12", "192.168.0.0/16"], var.no_proxy)
}
tmpdir = "${path.root}/.terraform/tmp/rke2"
ssh_key_arg = var.use_ssh_agent ? "" : "-i ${var.ssh_key_file}"
ssh = "ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null ${local.ssh_key_arg}"
scp = "scp -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null ${local.ssh_key_arg}"
remote_rke2_yaml = "${var.system_user}@${module.server.floating_ip[0]}:/etc/rancher/rke2/rke2-remote.yaml"
}
module "keypair" {
source = "./modules/keypair"
cluster_name = var.cluster_name
ssh_key_file = var.ssh_key_file
ssh_keypair_name = var.ssh_keypair_name
}
module "network" {
source = "./modules/network"
network_name = "${var.cluster_name}-nodes-net"
subnet_name = "${var.cluster_name}-nodes-subnet"
router_name = "${var.cluster_name}-router"
nodes_net_cidr = var.nodes_net_cidr
public_net_name = var.public_net_name
dns_servers = var.dns_servers
dns_domain = var.dns_domain
}
module "secgroup" {
source = "./modules/secgroup"
name_prefix = var.cluster_name
rules = var.secgroup_rules
}
module "server" {
source = "./modules/node"
cluster_name = var.cluster_name
name_prefix = "${var.cluster_name}-server"
nodes_count = var.nodes_count
image_name = var.image_name
image_id = var.image_id
instance_tags = var.instance_tags
flavor_name = var.flavor_name
keypair_name = module.keypair.keypair_name
ssh_key_file = var.ssh_key_file
system_user = var.system_user
use_ssh_agent = var.use_ssh_agent
network_id = module.network.nodes_net_id
subnet_id = module.network.nodes_subnet_id
secgroup_id = module.secgroup.secgroup_id
server_affinity = var.server_group_affinity
assign_floating_ip = "true"
config_drive = var.nodes_config_drive
floating_ip_pool = var.public_net_name
user_data = var.user_data_file != null ? file(var.user_data_file) : null
boot_from_volume = var.boot_from_volume
boot_volume_size = var.boot_volume_size
boot_volume_type = var.boot_volume_type
availability_zones = var.availability_zones
rke2_version = var.rke2_version
rke2_config = var.rke2_config
containerd_config_file = var.containerd_config_file
registries_conf = var.registries_conf
rke2_token = random_string.rke2_token.result
additional_san = var.additional_san
manifests_path = var.manifests_path
manifests_gzb64 = var.manifests_gzb64
additional_configs_path = var.additional_configs_path
additional_configs_gzb64 = var.additional_configs_gzb64
do_upgrade = var.do_upgrade
proxy_url = var.proxy_url
no_proxy = concat(["localhost", "127.0.0.1", "169.254.169.254", "127.0.0.0/8", "169.254.0.0/16", "10.0.0.0/8", "172.16.0.0/12", "192.168.0.0/16"], var.no_proxy)
}
resource "local_file" "tmpdirfile" {
content = ""
filename = "${local.tmpdir}/placeholder"
}
resource "random_string" "rke2_token" {
length = 64
}