2024-01-17 02:03:34 +00:00
# tofu
2022-01-10 11:04:08 +00:00
2024-01-17 02:03:34 +00:00
Contains [OpenTofu ](https://opentofu.org/ ) code used to manage our infrastructure, Nix'ified for [Terranix ](https://terranix.org/ ).
2022-01-10 11:04:08 +00:00
2022-01-10 12:53:20 +00:00
## Prerequisites
2022-01-10 11:04:08 +00:00
2024-01-13 15:31:46 +00:00
- [Nix ](https://nix.dev/ ) with [Flakes ](https://nixos.wiki/wiki/Flakes ) enabled
2024-01-17 01:37:31 +00:00
- Credentials (see [configuring ](#configuring )), if not using the [shared secrets ](#secrets ):
- `tf_cloud_token` : [Terraform Cloud ](https://app.terraform.io/ ) token to use shared state
- `hcloud_api_token` : [Hetzner Cloud API token ](https://docs.hetzner.com/cloud/api/getting-started/generating-api-token )
2024-01-13 15:31:46 +00:00
2024-01-17 01:37:31 +00:00
## Usage
2024-01-13 15:31:46 +00:00
2024-01-23 20:15:50 +00:00
### Development shell
2024-01-17 01:37:31 +00:00
2024-01-23 20:15:50 +00:00
Before issuing any other commands, enter the development environment (if not using [`direnv` ](https://zero-to-flakes.com/direnv )):
2024-01-17 01:37:31 +00:00
2024-01-23 20:15:50 +00:00
```sh
nix develop -c $SHELL
```
2024-01-20 19:45:19 +00:00
2024-01-23 23:14:39 +00:00
### Commands
2024-01-17 01:37:31 +00:00
2024-01-23 20:15:50 +00:00
```sh
2024-01-23 23:14:39 +00:00
just -l
2024-01-23 20:15:50 +00:00
```
2024-01-17 01:37:31 +00:00
2024-01-23 23:14:39 +00:00
### Handling [credentials](#secrets)
2024-01-23 20:15:50 +00:00
## Secrets
2024-01-16 17:02:43 +00:00
- if you want to reset secrets:
2024-01-23 23:14:39 +00:00
- generate keypair: `just keygen`
2024-01-16 17:02:43 +00:00
- list it in [`sops` ](https://getsops.io/ ) config file `.sops.yaml`
2024-01-23 23:14:39 +00:00
- key setup: set environment variable `SOPS_AGE_KEY_FILE` or `SOPS_AGE_KEY` so `sops` can locate the secret key to an `age` key pair that has its public key listed in `.sops.yaml` , e.g. (listed in `.envrc` ):
2024-01-17 01:37:31 +00:00
```sh
2024-01-20 19:45:19 +00:00
export SOPS_AGE_KEY_FILE=./keys.txt
2024-01-17 01:37:31 +00:00
```
2024-01-20 19:45:19 +00:00
- setting Terraform Cloud credentials, either by:
- decode (as per above) to reuse the shared session
2024-01-23 23:14:39 +00:00
- log in to the Terraform Cloud backend: `just login`
2024-01-16 17:02:43 +00:00
2024-01-16 19:15:11 +00:00
### Configuring
2022-08-20 17:39:35 +00:00
2024-01-20 19:45:19 +00:00
In `.auto.tfvars.json` override any OpenTofu variables, e.g.:
2024-01-13 15:31:46 +00:00
```tfvars
2024-01-16 19:15:11 +00:00
hcloud_location = "nbg1"
2022-08-20 17:39:35 +00:00
```
2024-01-13 15:31:46 +00:00
## [HCL to Nix](https://gist.github.com/KiaraGrouwstra/249ede6a7dfc00ea44d85bc6bdbcd875)