-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.tf
178 lines (154 loc) · 4.13 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
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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
module "media" {
source = "./modules/cloud_init"
name = "media"
ip = "192.168.4.201"
cores = 4
sockets = 2
disk_size = 16
memory = 8192
balloon = 2048
cloud_init_template_name = "debian-11-cloudinit-template"
# TODO I really don't like passing this in to every VM... is there a better way to get cloud-init configs into PVE?
pve_host = var.pve_host
pve_user = var.pve_user
pve_password = var.pve_password
}
module "wireguard" {
source = "./modules/cloud_init"
name = "wireguard"
ip = "192.168.4.203"
cores = 2
sockets = 2
memory = 1024
balloon = 512
vm_state = "stopped"
# TODO I really don't like passing this in to every VM... is there a better way to get cloud-init configs into PVE?
pve_host = var.pve_host
pve_user = var.pve_user
pve_password = var.pve_password
}
module "ddclient" {
source = "./modules/cloud_init"
name = "ddclient"
cores = 1
sockets = 1
memory = 512
# TODO I really don't like passing this in to every VM... is there a better way to get cloud-init configs into PVE?
pve_host = var.pve_host
pve_user = var.pve_user
pve_password = var.pve_password
}
locals {
k3s_server_count = 3
}
resource "random_password" "password" {
length = 16
special = false
}
module "k3s-server" {
count = local.k3s_server_count
source = "./modules/cloud_init"
name = "k3s-server-${count.index}"
cores = 2
sockets = 2
memory = 2048
disk_size = 20
additional_cloud_init_config = <<-EOT
ansible:
install_method: distro
package_name: ansible-core
pull:
url: https://github.com/ryanrishi/homelab.git
checkout: main
playbook_name: k3s-server.yml
extra_vars:
cluster_init: ${count.index == 0}
num_servers: ${local.k3s_server_count}
token: ${random_password.password.result}
# Unfortunately `cloud_final_modules` can't be merged, only overwritten
# This is the list from /etc/cloud/cloud.cfg with `ansible` added
cloud_final_modules:
- package-update-upgrade-install
- fan
- landscape
- lxd
- write-files-deferred
- puppet
- chef
- ansible # added by ryanrishi
- mcollective
- salt-minion
- reset_rmc
- refresh_rmc_and_interface
- rightscale_userdata
- scripts-vendor
- scripts-per-once
- scripts-per-boot
- scripts-per-instance
- scripts-user
- ssh-authkey-fingerprints
- keys-to-console
- install-hotplug
- phone-home
- final-message
- power-state-change
EOT
# TODO I really don't like passing this in to every VM... is there a better way to get cloud-init configs into PVE?
pve_host = var.pve_host
pve_user = var.pve_user
pve_password = var.pve_password
}
module "k3s-agent" {
count = 4
source = "./modules/cloud_init"
name = "k3s-replica-${count.index}"
cores = 2
sockets = 2
memory = 2048
disk_size = 20
additional_cloud_init_config = <<-EOT
ansible:
install_method: distro
package_name: ansible-core
pull:
url: https://github.com/ryanrishi/homelab.git
checkout: main
playbook_name: k3s-agent.yml
extra_vars:
token: ${random_password.password.result}
# Unfortunately `cloud_final_modules` can't be merged, only overwritten
# This is the list from /etc/cloud/cloud.cfg with `ansible` added
cloud_final_modules:
- package-update-upgrade-install
- fan
- landscape
- lxd
- write-files-deferred
- puppet
- chef
- ansible # added by ryanrishi
- mcollective
- salt-minion
- reset_rmc
- refresh_rmc_and_interface
- rightscale_userdata
- scripts-vendor
- scripts-per-once
- scripts-per-boot
- scripts-per-instance
- scripts-user
- ssh-authkey-fingerprints
- keys-to-console
- install-hotplug
- phone-home
- final-message
- power-state-change
EOT
# TODO I really don't like passing this in to every VM... is there a better way to get cloud-init configs into PVE?
pve_host = var.pve_host
pve_user = var.pve_user
pve_password = var.pve_password
depends_on = [
module.k3s-server
]
}