Skip to content

Commit d59dcc3

Browse files
authored
Merge pull request #23 from sshine/docs/why-terranix
docs: Website Renewal
2 parents db52453 + 650706a commit d59dcc3

25 files changed

+420
-160
lines changed

book.toml

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,29 @@ git-repository-icon = "fa-github"
1717
enable = false
1818

1919
[output.linkcheck]
20-
# Should we check links on the internet? Enabling this option adds a
21-
# non-negligible performance impact
20+
# Don't follow external links when linkchecking by default.
21+
# Use `nix run .#deepcheck` to also follow web links.
22+
# Several HashiCorp resources give 429 Too Many Requests.
2223
follow-web-links = false
24+
25+
[output.html.redirect]
26+
"documentation/flakes.html" = "../flakes.html"
27+
"documentation/functions.html" = "../functions.html"
28+
"documentation/getting-started.html" = "../getting-started.html"
29+
"documentation/getting-startet-with-nix-flakes.html" = "../getting-startet-with-nix-flakes.html"
30+
"documentation/modules.html" = "../modules.html"
31+
"documentation/terranix-vs-hcl.html" = "../terranix-vs-hcl.html"
32+
"documentation/what-is-terranix.html" = "../what-is-terranix.html"
33+
"news/2021-10-02_release-2.4.0.html" = "../news-2021-10-02_release-2.4.0.html"
34+
"news/2021-10-20_new_page_layout.html" = "../news-2021-10-20_new_page_layout.html"
35+
"news/2021-11-07_release-2.5.0.html" = "../news-2021-11-07_release-2.5.0.html"
36+
"news/2021-11-13_release-2.5.1.html" = "../news-2021-11-13_release-2.5.1.html"
37+
"news/2021-11-17_release-2.5.2.html" = "../news-2021-11-17_release-2.5.2.html"
38+
"news/2022-01-07_release-2.5.3.html" = "../news-2022-01-07_release-2.5.3.html"
39+
"news/2022-07-11_release-2.5.4.html" = "../news-2022-07-11_release-2.5.4.html"
40+
"news/2022-09-06_release-2.5.5.html" = "../news-2022-09-06_release-2.5.5.html"
41+
"news/2023-02-08_matrix.html" = "../news-2023-02-08_matrix.html"
42+
"news/2023-05-24_release-2.6.0.html" = "../news-2023-05-24_release-2.6.0.html"
43+
"news/2023-09-22_release-2.7.0.html" = "../news-2023-09-22_release-2.7.0.html"
44+
"news/2024-10-15_release-2.8.0.html" = "../news-2024-10-15_release-2.8.0.html"
45+
"news/2025-11-09_website_renewal.html" = "../news-2025-11-09_website_renewal.html"

src/SUMMARY.md

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
11
# Summary
22

3-
- [Terranix](index.md)
4-
53
# Documentation
64

7-
- [about terranix and terraform](documentation/what-is-terranix.md)
8-
- [Getting Started](documentation/getting-started.md)
9-
- [Getting Started with nix flake](documentation/getting-startet-with-nix-flakes.md)
10-
- [Differences between terranix and HCL](documentation/terranix-vs-hcl.md)
11-
- [Functions](documentation/functions.md)
12-
- [Modules](documentation/modules.md)
13-
- [terranix via nix flakes](documentation/flakes.md)
5+
- [Introduction](index.md)
6+
- [Getting Started](getting-started.md)
7+
- [What is Terraform / OpenTofu?](what-is-terranix.md)
8+
- [Getting Started with nix flake](getting-startet-with-nix-flakes.md)
9+
- [Differences between terranix and HCL](terranix-vs-hcl.md)
10+
- [Functions](functions.md)
11+
- [Modules](modules.md)
12+
- [terranix via nix flakes](flakes.md)
1413

1514
# News
1615

17-
- [Release 2.8.0 ](news/2024-10-15_release-2.8.0.md)
18-
- [Release 2.7.0 ](news/2023-09-22_release-2.7.0.md)
19-
- [Release 2.6.0 ](news/2023-05-24_release-2.6.0.md)
20-
- [Matrix Server is Online](news/2023-02-08_matrix.md)
21-
- [Release 2.5.5 ](news/2022-09-06_release-2.5.5.md)
22-
- [Release 2.5.4 ](news/2022-07-11_release-2.5.4.md)
23-
- [Release 2.5.3 ](news/2022-01-07_release-2.5.3.md)
24-
- [Release 2.5.2 ](news/2021-11-17_release-2.5.2.md)
25-
- [Release 2.5.1 ](news/2021-11-13_release-2.5.1.md)
26-
- [Release 2.5.0 ](news/2021-11-07_release-2.5.0.md)
27-
- [New Page Layout](news/2021-10-20_new_page_layout.md)
28-
- [Release 2.4.0](news/2021-10-02_release-2.4.0.md)
16+
- [2025-09-11: Website Renewal](news-2025-11-09_website_renewal.md)
17+
- [2024-10-15: Release 2.8.0](news-2024-10-15_release-2.8.0.md)
18+
- [2023-09-22: Release 2.7.0](news-2023-09-22_release-2.7.0.md)
19+
- [2023-05-24: Release 2.6.0](news-2023-05-24_release-2.6.0.md)
20+
- [2023-02-08: Matrix Server is Online](news-2023-02-08_matrix.md)
21+
- [2022-09-06: Release 2.5.5](news-2022-09-06_release-2.5.5.md)
22+
- [2022-07-11: Release 2.5.4](news-2022-07-11_release-2.5.4.md)
23+
- [2022-01-07: Release 2.5.3](news-2022-01-07_release-2.5.3.md)
24+
- [2021-11-17: Release 2.5.2](news-2021-11-17_release-2.5.2.md)
25+
- [2021-11-13: Release 2.5.1](news-2021-11-13_release-2.5.1.md)
26+
- [2021-11-07: Release 2.5.0](news-2021-11-07_release-2.5.0.md)
27+
- [2021-10-20: New Page Layout](news-2021-10-20_new_page_layout.md)
28+
- [2021-10-02: Release 2.4.0](news-2021-10-02_release-2.4.0.md)

src/documentation/getting-started.md

Lines changed: 0 additions & 71 deletions
This file was deleted.

src/documentation/what-is-terranix.md

Lines changed: 0 additions & 52 deletions
This file was deleted.
File renamed without changes.
File renamed without changes.

src/getting-started.md

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
# Getting Started
2+
3+
Let's have a quick overview on how you could use terranix.
4+
5+
If you look for working examples, check out [examples at GitHub](https://github.com/terranix/terranix-examples).
6+
7+
If you don’t know what [Terraform][tf] is, have a look at
8+
<a href="what-is-terranix.html">What is Terraform / OpenTofu?</a>
9+
10+
This guide assumes you have Nix installed. If you don't have, check [Determinate Nix installer][det-nix].
11+
12+
[tf]: https://terraform.io
13+
[det-nix]: https://github.com/DeterminateSystems/nix-installer#determinate-nix-installer
14+
15+
## shell.nix
16+
17+
One way to get started is to create a `shell.nix`
18+
that holds your terranix and terraform setup.
19+
20+
```nix
21+
{ pkgs ? import <nixpkgs> { } }:
22+
let
23+
hcloud_token = "...";
24+
tf = pkgs.writers.writeBashBin "tf" ''
25+
export TF_VAR_hcloud_token="${hcloud_token}"
26+
${pkgs.opentofu}/bin/tofu "$@"
27+
'';
28+
in pkgs.mkShell {
29+
buildInputs = [ pkgs.terranix tf ];
30+
}
31+
```
32+
33+
This installs both terranix and opentofu.
34+
35+
It also creates a `tf` CLI wrapper that embeds an API key.
36+
37+
You want to avoid putting the API token(s) directly into shell.nix.
38+
39+
But that can be done in a number of ways.
40+
41+
## config.nix
42+
43+
Create a `config.nix` that holds your resource definitions.
44+
45+
This example is adapted from the pure HCL example in [What is Terraform / OpenTofu?](./what-is-terranix.md):
46+
47+
```nix
48+
{ lib, ... }:
49+
{
50+
# Control the API token with a variable to hide it from version control
51+
variable.hcloud_token = {
52+
sensitive = true;
53+
};
54+
55+
# Configure the Hetzner Cloud Provider
56+
provider.hcloud = {
57+
token = "\${var.hcloud_token}";
58+
};
59+
60+
resource.hcloud_server.my_server = {
61+
image = "debian-12";
62+
name = "myserver.example.org";
63+
server_type = "cx22";
64+
datacenter = "nbg1-dc3";
65+
ssh_keys = [ "\${hcloud_ssh_key.my_key.id}" ];
66+
public_net = {
67+
ipv4_enabled = true;
68+
ipv6_enabled = true;
69+
};
70+
};
71+
72+
resource.hcloud_ssh_key.my_key = {
73+
name = "my-ssh-key";
74+
public_key = ''''${file("~/.ssh/id_ed25519.pub")}'';
75+
};
76+
}
77+
```
78+
79+
<div class="warning">
80+
<b>Escaping string interpolation:</b> Since both Terraform and Nix use the same string
81+
interpolation syntax, <code>${}</code>, it is necessary to escape Terraform literal
82+
<code>${}</code> references so that they don't get picked up by Nix. This happens in two
83+
different ways in the example above:
84+
85+
- `"\${var.hcloud_token}"`: Escaping here is necessary; `${var.hcloud_token}` is a Terraform string that gets interpreted when running `plan` or `apply`. If it were not escaped, it would result in a "variable not found" error in Nix, since `var` is not a Nix variable.
86+
87+
It could also have been written as `lib.tf.ref "var.hcloud_token"`
88+
89+
- `''''${file("~/.ssh/id_ed25519.pub")}''`: Because the Terraform expression contains double quotes, a Nix multi-line string is used to avoid also escaping the double quotes. Escaping a Nix `${...}` expression inside a multi-line string looks like `''${...}`, i.e. instead of a backslash, two single quotes escape the string interpolation.
90+
91+
It could also have been written as `"\${file(\"~/.ssh/id_ed25519.pub\")}"`.
92+
93+
The resulting Terraform JSON contains strings that contain these string interpolations.
94+
95+
</div>
96+
97+
## Create a Server
98+
99+
Convert `config.nix` into Terraform JSON, `init` the Terraform provider, and `apply` the configuration:
100+
101+
```shell
102+
terranix config.nix > config.tf.json
103+
tf init
104+
tf apply
105+
```
106+
107+
Note that the `tf` binary assumes the wrapper from shell.nix.
108+
109+
Use `terraform` or `tofu` if you installed either of them plainly.
110+
111+
## Destroy a Server
112+
113+
cleaning everything up is the job of terraform.
114+
115+
```shell
116+
tf destroy
117+
```
File renamed without changes.

src/index.md

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
1-
Terranix is a [Nix][nix]-based infrastructure-as-code tool that combines the
2-
providers of Terraform and the lazy, functional configuration of [NixOS][nixos]
3-
Terranix works as a replacement for HCL by generating [Terraform JSON][tf-json].
1+
# What is terranix?
2+
3+
terranix is a [Nix][nix]-based infrastructure-as-code tool that combines the
4+
providers of Terraform and the lazy, functional configuration of [NixOS][nixos].
5+
terranix works as an alternative to HCL by generating [Terraform JSON][tf-json]
6+
that can then be applied using the same providers.
47

58
[nix]: https://serokell.io/blog/what-is-nix
69
[nixos]: https://nixos.org/
710
[tf-json]: https://www.terraform.io/docs/configuration/syntax-json.html
811

912
## Features
1013

11-
- Terranix is similar to Terraform: you can use the
14+
- terranix is similar to Terraform: you can use the
1215
[Terraform reference material](https://www.terraform.io/docs/providers/index.html)
1316
- The full power of the Nix language
1417
- The full power of the NixOS module system
@@ -17,5 +20,5 @@ Terranix works as a replacement for HCL by generating [Terraform JSON][tf-json].
1720

1821
## Community
1922

20-
- Write issues on [github](https://github.com/terranix/terranix/issues)
21-
- Create pull requests on [github](https://github.com/terranix/terranix/pulls)
23+
- Write issues on [GitHub](https://github.com/terranix/terranix/issues)
24+
- Create pull requests on [GitHub](https://github.com/terranix/terranix/pulls)
File renamed without changes.

0 commit comments

Comments
 (0)