feat: subnets attached to compute, added tf destroy

This commit is contained in:
2025-12-29 14:50:21 -05:00
parent 64cd0eb4ff
commit 2427411452
5 changed files with 78 additions and 34 deletions

View File

@@ -3,9 +3,10 @@ version: 3
tasks: tasks:
vault: ansible-vault edit vault.yml {{.CLI_ARGS}} vault: ansible-vault edit vault.yml {{.CLI_ARGS}}
tf:apply: ansible-playbook playbooks/provision.yml {{.CLI_ARGS}} tf:apply: ansible-playbook playbooks/provision.yml {{.CLI_ARGS}}
tf:destroy: ansible-playbook playbooks/destroy.yml {{.CLI_ARGS}}
enter: enter:
cmd: ssh -i {{.KEY}} -p 22 root@{{.IP}} cmd: ssh -i {{.KEY}} -p 22 root@{{.IP}}
vars: vars:
KEY: { sh: ansible-vault view vault.yml | yq -r .secret.private_key_file } KEY: { sh: ansible-vault view vault.yml | yq -r .secret.private_key_file }
IP: { sh: cat secrets/terraform_outputs.yml | jq -r .box_ip.value.jumphost } IP: { sh: "cat secrets/terraform_outputs.yml | jq -r '.box_ip.value[\"kthw-jumphost\"]'" }

15
playbooks/destroy.yml Normal file
View File

@@ -0,0 +1,15 @@
- name: Deploy terraform infrastructure.
hosts: localhost
gather_facts: false
vars_files:
- ../vault.yml
tasks:
- name: Destroy
community.general.terraform:
project_path: '../terraform'
state: "absent"
init_reconfigure: true
force_init: true
backend_config: "{{ terraform.backend }}"
variables: "{{ terraform.variables }}"
complex_vars: true

View File

@@ -3,14 +3,34 @@ resource "hcloud_ssh_key" "key" {
public_key = file(var.public_key_file) public_key = file(var.public_key_file)
} }
resource "hcloud_network" "net" {
name = "kthw-net"
ip_range = "10.0.0.0/8"
}
resource "hcloud_network_subnet" "subnet" {
type = "cloud"
network_id = hcloud_network.net.id
network_zone = "eu-central"
ip_range = "10.0.0.0/16"
}
resource "hcloud_server" "boxes" { resource "hcloud_server" "boxes" {
for_each = var.boxes for_each = var.boxes
name = each.value name = "kthw-${each.key}"
image = "debian-12" image = "debian-12"
ssh_keys = [hcloud_ssh_key.key.id] ssh_keys = [hcloud_ssh_key.key.id]
server_type = "cx23" server_type = "cx23"
network {
network_id = hcloud_network.net.id
ip = each.value.private_ip
}
public_net { public_net {
ipv4_enabled = true ipv4_enabled = true
ipv6_enabled = false ipv6_enabled = false
} }
depends_on = [ hcloud_network_subnet.subnet ]
} }

View File

@@ -9,5 +9,7 @@ variable "public_key_file" {
} }
variable "boxes" { variable "boxes" {
type = set(string) type = map(object({
private_ip = string
}))
} }

View File

@@ -1,32 +1,38 @@
$ANSIBLE_VAULT;1.1;AES256 $ANSIBLE_VAULT;1.1;AES256
62363766383731633261633434393031643136643966663963643362656435666633303631396432 65306438313236636631396636376236396334373838363464653530326465343964613034303663
3265303163636462616566633462663261366461636663630a363835353161616136633635346233 3966616439613237323235626565356261306235393439350a373334343831613635646132366462
62663264366161393961363966636633663461353931316361316665323065336133353262663062 30656532363661663431653266663061313131663166363231316362383732393862333834643738
3262323562383532340a353930653533623832623239633737343835643562343834633862666561 6131343064626562650a616138376363323562306531626638353565316236376135613039643939
34323466323435336437353263393661313061623465326432323666313138646262663337303039 38326131653037666130646465336464633765346539626362356138353533656264373966363065
39616366363134383936383163616164383537623334323332353736646132373033326162333536 33353631663533626235396336383135643962363161393163613734313131613338643464376434
35336261373934653232636663393834396665313137613965663464303832613537316562363963 33656364626630636332313134623261653038306337363339316664383032356234663130313463
34663263396234326361303063326363633165343062366164353934396239333963626130303939 38313030376434393162636234646337623735663536313535316165376539353565636463313165
62626261336133616633303236333630656336356262383963376532656537373864643161653364 63633937383465643863326163623438326431646237323633363336396561343231653864633065
32663134376531663235376561663733336430623739616438396531616630626464343833653730 35343639663538343664653230333637663366333763616537613365326539363563356337653066
63376137396333353037656532303236336661643339643333353331313735623463316364666266 63363733666432303131613533383664623964356239393061383635623035313765393938653736
34623135363362343165643164303733626565393766366466353962343165373466323638306531 33656531333232653038633966623731313661643830383433373739636436623935366235643130
65623834323039313635623436306632343332313030303764396335663032326438326637376538 61393964663132616632363962313335343533643962373437316432663464613062663738666337
61393633386436386635666135323138623138383261633935383439633865313966376331366632 64313062643761323038643630666234383734633338383932353264643761626333396162303935
34303036353039343336346437383239303963306535343131643834316635643765653736306436 63383430303564303631333864313934646339366561656430306565376465343839303061386238
61356433633135663366393238353931353336316437663662373235313165306462623330633135 37306634636330323431636233333464643935643139663463613937353738363264663636646231
31363663386562376133663461646133366231663738663239303733616430326136636234343134 37323764653832613633653831363962643235383337623431333135306236363961643338626163
66656435323534393233373061363438633233386461653131336134373162386563353730663763 37333136636638636562363432313566383264386335316137343562633666303138663565313663
31353866623731323133373762653261346465373738303932356462363235383638386366663639 64376237396235306235343366356138653338333137653065396637323363646565656139326533
39363430666636386138396363326538343839613965383465366434613764373736396265306438 62373266636663323634326338656461666133633861613164636365616433316164326561323563
66363536643931313630363563343530616664653038393839363636363536313130326431326566 32613066346430663564333738633534313432353134663938376330373234636135663661383335
64343832646435356437376564393239353736646437636432636366303634356139366332653935 37646163333564623465393362663331356337333662303833616261313861316231343033666433
30353538656266633632376666396232663464313231333438376534346430386464366263383833 33663863646537363239373639343238396661643134316339663761333238373061616239366635
35313361313633306434336137383533363431316163353634393638633935306163343266663631 36353761633362616638633863306462346265666565636138303935323263386230333637633034
64633765333932316363373161323062656536363035333062383430363836393634613066313034 65333431653130373336383331366334323130306639383966366436626663323364303761633331
35636333666130343461356136613238333063393362346264346232353866376162653836373966 30383062643365356436376132396536306438303532636166356266326363356231633063636537
63316561396135383861333530656331393761393931666261626433356530663863303437366437 39376136336263386636326430383432313164356332663164383631376365376261366432323064
32343337653634336331303362393462346435373639396435303830303734303265666663663134 34363432363135653261373864666236353935306532333361343063623034356332393636343863
31353934653937636561353066386439366466333732326464386537373530326364373731313161 35353966376230343432323437356235333161656332333738613866303966393863383333643834
62393530636436613332363565363036326430313336303032343564666533623133663530303263 33616634393330393062643831633838366233663039613136623835643363383336633934336137
633139386533353862636266643630633263 62393135363332373963623266313334633864363938393561353934386430323965663138633136
34303238653536333139663137346161663732613037656137663836393936336331663239366530
62646537313239383464646432396264656262396566663666666536633335666563313733306632
31663133303662383637383166646162393931646534656532346135376465656336343136353062
31643561623462626337316232656534663838366234653531373130346237623737613839666563
62323431643965386137313464303333636534376262393237663561313063373439643966383163
6236