From 5243bd6b78e9bb72c3353bb57e74caa2caddeeeb Mon Sep 17 00:00:00 2001 From: "marcoemi.poleggi" <marco-emilio.poleggi@hesge.ch> Date: Mon, 4 Nov 2024 10:52:37 +0100 Subject: [PATCH] Update README.md with task 7-bonus --- SwitchEngines/README.md | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/SwitchEngines/README.md b/SwitchEngines/README.md index 1a76372..00d195c 100644 --- a/SwitchEngines/README.md +++ b/SwitchEngines/README.md @@ -599,6 +599,30 @@ lcl$ ssh -i keys/tf-cloud-init -o IdentitiesOnly=yes $(terraform output -raw ssh ... ``` + +### Task #7-bonus: a cluster of 2 ### + +**Goal:** use advanced HCL features to handle resource arrays. + +Now you can provision an instance and have SSH access to it. Let's write a plan variant to provision a cluster of 2 instances. + +You shall: + +1. Declare a variable or [_local_](https://developer.hashicorp.com/terraform/language/values/locals) `insance_count`. +1. Extend your "app_server" resource with + - a [`count` argument](https://developer.hashicorp.com/terraform/language/meta-arguments/count) using `insance_count`, + - a `name` argument showing the instance count index. +1. Extend the networking-related resources with the count argument plus the index where necessary. +1. Modify your `outputs` to show arrays instead of scalar values. + +Once done and your cluster provisioned, the following command should yield a single element of an output array: +```shell +$ terraform output --json instance_public_ip | jq -r '.[0]' +``` + +The same login should work for both the instances! + + ### Task #8: further practice with Cloud-init ### **Goal:** get more acquainted with Cloud-init: change the instance's default -- GitLab