Skip to content

Commit b1c8e79

Browse files
committed
feat: deploy terraform managed server to hcloud using deploy-rs
1 parent 75071ec commit b1c8e79

File tree

8 files changed

+109
-17
lines changed

8 files changed

+109
-17
lines changed

.gitignore

+10-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
result
2-
.direnv
31
doc/index.html
42

53
# Result of bud commands
@@ -9,5 +7,13 @@ doi
97

108
pkgs/_sources/.shake*
119

12-
# pre-commit-hooks.nix
13-
/.pre-commit-config.yaml
10+
result
11+
result*
12+
.direnv
13+
.pre-commit-config.yaml
14+
**/.terraform
15+
content*.tar.gz
16+
create_config_version.json
17+
generated_config.tf.json
18+
19+
.env

deploy/default.nix

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ in {
88
flake.deploy = {
99
nodes = {
1010
bunky = {
11-
hostname = "5.78.53.16";
11+
hostname = "5.78.50.232";
1212
profiles.system = {
1313
sshUser = "admin";
1414
path = inputs.deploy-rs.lib.x86_64-linux.activate.nixos self.nixosConfigurations.bunky;

flake-parts/terraform.nix

+5-1
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,14 @@
4747
pushd $(git rev-parse --show-toplevel)
4848
4949
# determine the path to the configuration
50-
configurationPath=$(cat ${self'.packages.terraformConfigurationMatrix}/terraform-configuration-matrix.json | ${jq} -r '.configurations[] | select(.name == "'$configurationName'" ) | .path')
50+
export configurationPath=$(cat ${self'.packages.terraformConfigurationMatrix}/terraform-configuration-matrix.json | ${jq} -r '.configurations[] | select(.name == "'$configurationName'" ) | .path')
5151
5252
# copy the generated terraform configuration to the configuration path
53+
config_file_path="$configurationPath/config.tf.json"
54+
echo $config_file_path
5355
cp "$configurationPath/config.tf.json" ./terraform/configurations/$configurationName/config.tf.json
56+
# make it writable since it is read-only in the nix store
57+
chmod +w ./terraform/configurations/$configurationName/config.tf.json
5458
5559
# execute the terraform command
5660
${terraform-cli} -chdir=./terraform/configurations/$configurationName "$@"

packer/hetzner/main.pkr.hcl

+3-6
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,21 @@ variable "hcloud-token" {
44
sensitive = true
55
}
66

7-
variable "name" {
8-
}
9-
107
locals {
118
build-id = "${uuidv4()}"
129
build-labels = {
13-
"name" = var.name
10+
"name" = local.name
1411
"packer.io.build.time" = "{{ timestamp }}"
1512
}
13+
name = "hetzner-base-nixos-{{ timestamp }}"
1614
}
1715

1816
source "hcloud" "base" {
1917
server_type = "cx21"
2018
image = "debian-11"
2119
rescue = "linux64"
2220
location = "nbg1"
23-
snapshot_name = var.name
21+
snapshot_name = "hetzner-base-nixos-{{ timestamp }}"
2422
snapshot_labels = local.build-labels
2523
ssh_username = "root"
2624
token = var.hcloud-token
@@ -40,5 +38,4 @@ build {
4038
post-processor "manifest" {
4139
custom_data = local.build-labels
4240
}
43-
4441
}

terraform/configurations/core/main.nix

-5
This file was deleted.

terraform/configurations/hetzner/.terraform.lock.hcl

+46
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
terraform {
2+
cloud {
3+
organization = "justinrubek"
4+
5+
workspaces {
6+
name = "hetzner"
7+
}
8+
}
9+
10+
required_providers {
11+
hcloud = {
12+
source = "hetznercloud/hcloud"
13+
version = "1.36.1"
14+
}
15+
random = {
16+
source = "hashicorp/random"
17+
version = "3.4.3"
18+
}
19+
}
20+
21+
required_version = ">= 1.0"
22+
}
+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{...}: {
2+
# configure hcloud
3+
variable.hcloud_token.sensitive = true;
4+
provider.hcloud.token = "\${var.hcloud_token}";
5+
6+
data.hcloud_image.nixos_base = {
7+
id = "92487340";
8+
};
9+
10+
resource.hcloud_server.bunky = {
11+
name = "bunky";
12+
13+
image = "\${data.hcloud_image.nixos_base.id}";
14+
server_type = "cpx11";
15+
location = "hil";
16+
17+
public_net = {
18+
ipv4_enabled = true;
19+
ipv6_enabled = true;
20+
};
21+
};
22+
}

0 commit comments

Comments
 (0)