Skip to content

Commit

Permalink
Added some Terraform
Browse files Browse the repository at this point in the history
  • Loading branch information
jinglemansweep committed Feb 5, 2024
1 parent 923e17b commit 97c1ea1
Show file tree
Hide file tree
Showing 14 changed files with 395 additions and 4 deletions.
21 changes: 17 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,30 @@ on:
permissions:
contents: write
jobs:
build-and-deploy:
Build:
concurrency: ci-${{ github.ref }}
runs-on: ubuntu-latest
steps:

- name: Setup Terraform
uses: hashicorp/setup-terraform@v3

- name: Checkout
uses: actions/checkout@v4

- name: Build
- name: Create Butane YAML with Terraform
run: |
mkdir -p .build
echo "HELLO" > .build/index.html
pushd ./terraform
echo "Initialising Terraform..."
terraform init
echo "Applying Terraform..."
terraform apply -auto-approve
echo "Getting Terraform JSON outputs..."
for i in "plex" "swarm_manager" "swarm_worker"; do
echo " ... ${i}"
terraform output -raw ${i} > ./build/${i}.json
done
popd
- name: Deploy
uses: JamesIves/github-pages-deploy-action@v4
Expand Down
15 changes: 15 additions & 0 deletions terraform/.terraform.lock.hcl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file not shown.
15 changes: 15 additions & 0 deletions terraform/files/sections/base.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
variant: flatcar
version: 1.0.0

storage:
disks:
- device: /dev/vdb
wipe_table: true

files:
- path: /etc/systemd/system.conf.d/10-env-base.conf
mode: 0644
contents:
inline: |
[Manager]
DefaultEnvironment=FC_TEST_VAR=hello-world
30 changes: 30 additions & 0 deletions terraform/files/sections/docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
variant: flatcar
version: 1.0.0

storage:
disks:
- device: /dev/vdb
partitions:
- number: 1
label: mnt_data
resize: true
size_mib: 0

filesystems:
- path: /mnt/data
device: /dev/disk/by-partlabel/mnt_data
format: ext4
wipe_filesystem: true
label: mnt_data
with_mount_unit: true

links:
- path: /etc/systemd/system/multi-user.target.wants/docker.service
target: /usr/lib/systemd/system/docker.service
hard: false
overwrite: true

systemd:
units:
- name: docker.service
enabled: true
30 changes: 30 additions & 0 deletions terraform/files/sections/iscsi.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
variant: flatcar
version: 1.0.0

systemd:
units:
- name: iscsi.service
enabled: true

- name: iscsi-volume.service
enabled: true
contents: |
[Unit]
Description=Mount iSCSI Volume
Wants=network-online.target
After=network-online.target iscsid.service
Requires=iscsid.service
ConditionEnvironment=FC_ISCSI_PORTAL
ConditionEnvironment=FC_ISCSI_TARGET
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStartPre=/bin/mkdir -p /mnt/iscsi
ExecStartPre=/sbin/iscsiadm -m discovery -t st -p ${FC_ISCSI_PORTAL}
ExecStartPre=-/sbin/iscsiadm -m node --targetname ${FC_ISCSI_TARGET} --portal ${FC_ISCSI_PORTAL} --logout
ExecStart=/sbin/iscsiadm -m node --targetname ${FC_ISCSI_TARGET} --portal ${FC_ISCSI_PORTAL} --login
ExecStart=/bin/sh -c "sleep 5 && /bin/mount /dev/disk/by-id/scsi-*-part1 /mnt/iscsi"
ExecStop=/bin/umount /mnt/iscsi
ExecStop=/sbin/iscsiadm -m node --targetname ${FC_ISCSI_TARGET} --portal ${FC_ISCSI_PORTAL} --logout
[Install]
WantedBy=multi-user.target
37 changes: 37 additions & 0 deletions terraform/files/sections/nfs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
variant: flatcar
version: 1.0.0

storage:
files:
- path: /etc/systemd/system.conf.d/11-env-nfs.conf
mode: 0644
contents:
inline: |
[Manager]
DefaultEnvironment=FC_NFS_HOST=10.0.2.11
systemd:
units:
- name: mnt-nfs-work.mount
enabled: true
contents: |
[Unit]
Before=remote-fs.target
[Mount]
What=${FC_NFS_HOST}:/volume1/cluster/work
Where=/mnt/nfs/work
Type=nfs
[Install]
WantedBy=remote-fs.target
- name: mnt-nfs-volumes.mount
enabled: true
contents: |
[Unit]
Before=remote-fs.target
[Mount]
What=${FC_NFS_HOST}:/volume1/cluster/docker/volumes
Where=/mnt/nfs/volumes
Type=nfs
[Install]
WantedBy=remote-fs.target
10 changes: 10 additions & 0 deletions terraform/files/sections/users.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
variant: flatcar
version: 1.0.0

passwd:
users:
- name: louis
ssh_authorized_keys:
- ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDAPME1Cu6epBXHCAI6pRjhuWC5HprHsqLlrokNRqdpcd/yKvP4KauPGKzZpshG9P/EUJ/ZYCh1diD4CUZgkzY54n2GuDmfxqsnhjkdI9g8Ceu1VsXTLwvW62BVDQgXaVBhds9rd+f+DTIEMqQvCnwkWSnMCPTY/+mi4PqireJgdQ18UXkSGjWtbDb+BgJB9BLI61Wx+eoKe8JMjJjoRhV1xxinS1XlghATh9onddaM6k1uVuLi8hQRYRqbrBwUQ21P+pLQbe6XJLdw65jnThSH/9BJ59ePqpWS+H43fzl9iAyyZFoBV9IVT+P4roEIAIIs1O4Kp02R09azbml8JkON louis@home
password_hash: "$6$4DcadFC0.wM$.3jy/J4hsDnP55ehJM2zTEWyCrrc.O7m3N2/j2Zohel8n1qQJM73mwmHFFOyuTbp8eZH4XReUyzE1EbyqXx/b."
groups: [sudo, docker]
38 changes: 38 additions & 0 deletions terraform/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
data "ct_config" "swarm_manager" {
content = file("files/sections/base.yml")
strict = true
pretty_print = false

snippets = [
# Sections
file("files/sections/users.yml"),
file("files/sections/docker.yml"),
file("files/sections/nfs.yml")
]
}

data "ct_config" "swarm_worker" {
content = file("files/sections/base.yml")
strict = true
pretty_print = false

snippets = [
# Sections
file("files/sections/users.yml"),
file("files/sections/docker.yml"),
file("files/sections/nfs.yml")
]
}

data "ct_config" "plex" {
content = file("files/sections/base.yml")
strict = true
pretty_print = false

snippets = [
# Sections
file("files/sections/users.yml"),
file("files/sections/docker.yml"),
file("files/sections/nfs.yml")
]
}
11 changes: 11 additions & 0 deletions terraform/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
output "swarm_manager" {
value = data.ct_config.swarm_manager.rendered
}

output "swarm_worker" {
value = data.ct_config.swarm_worker.rendered
}

output "plex" {
value = data.ct_config.plex.rendered
}
10 changes: 10 additions & 0 deletions terraform/providers.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
terraform {
required_providers {
ct = {
source = "poseidon/ct"
version = "0.13.0"
}
}
}

provider "ct" {}
Loading

0 comments on commit 97c1ea1

Please sign in to comment.