From 8770c89343b04281e033a87ab5721187e28f3472 Mon Sep 17 00:00:00 2001 From: Florian Dejonckheere Date: Sun, 13 Feb 2022 23:21:18 +0100 Subject: [PATCH] Add quickstart section about resource dependencies --- CHANGELOG.md | 7 +++++-- docs/quickstart.md | 49 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e8c1c95..dfa148f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,9 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] -## [0.2.0] - 2021-12-02 +## [0.3.0] - 2022-02-13 -Initial release. +- Add dependencies between resources +- Show old and new attribute values in execution plan + +## [0.2.0] - 2021-12-02 - Add SSH Key and Server resource - Update only changed attributes diff --git a/docs/quickstart.md b/docs/quickstart.md index 0d19761..77ab4ec 100644 --- a/docs/quickstart.md +++ b/docs/quickstart.md @@ -209,6 +209,55 @@ end Try changing the name of the SSH key in the Hetzner Cloud panel as well. You'll see that Kozo tries to revert the name change. +## Dependent resources + +Resource can depend on other resources for their values. +Kozo will make sure that the dependent resources are created in the correct order. + +Append the following to your `main.kz` file: + +```ruby +resource "hcloud_server", "default" do |s| + s.name = "default" + s.location = "fsn1" + s.image = "debian-11" + s.server_type = "cx11" + s.ssh_keys = [hcloud_ssh_key.default] + s.user_data = File.read("cloud-init.yml") + + s.labels = { + primary: "true", + } +end +``` + +```sh +$ kozo plan +... + +# hcloud_server.default: ++ resource "hcloud_server", "default" do |r| + r.id = (known after apply) + + r.name = "default" + + r.image = "debian-11" + + r.server_type = "cx11" + + r.location = "fsn1" + r.datacenter = nil + + r.labels = { + primary = "true" + } + r.locked = (known after apply) + r.created = (known after apply) + + r.user_data = "#cloud-config timezone: Europe/Berlin locale: C.UTF-8 ntp: enabled: ..." + + r.ssh_keys = [ + 5562231 + ] +end + +``` + +Note that the SSH key reference was resolved to the ID of the SSH key that was previously created. + ## Destroy a resource Instruct Kozo that the resource should be deleted simply by removing the relevant lines in the `main.kz` file.