From 4f23df279ffe6214f99a6bd0d1deb11761b11a22 Mon Sep 17 00:00:00 2001 From: Martin Goik <goik@hdm-stuttgart.de> Date: Tue, 16 Apr 2024 10:34:39 +0200 Subject: [PATCH] Re-considering terraform output --- .../Terra/040HelloSshSecretApiToken/main.tf | 5 - .../040HelloSshSecretApiToken/outputs.tf | 9 ++ Doc/Sdi/CloudProvider/gettingStarted.xml | 118 +++++++++++------- 3 files changed, 83 insertions(+), 49 deletions(-) create mode 100644 Doc/Sdi/CloudProvider/Terra/040HelloSshSecretApiToken/outputs.tf diff --git a/Doc/Sdi/CloudProvider/Terra/040HelloSshSecretApiToken/main.tf b/Doc/Sdi/CloudProvider/Terra/040HelloSshSecretApiToken/main.tf index 91b7263f9..f12c8699a 100644 --- a/Doc/Sdi/CloudProvider/Terra/040HelloSshSecretApiToken/main.tf +++ b/Doc/Sdi/CloudProvider/Terra/040HelloSshSecretApiToken/main.tf @@ -37,8 +37,3 @@ resource "hcloud_server" "helloServer" { ssh_keys = [hcloud_ssh_key.goik.id] firewall_ids = [hcloud_firewall.sshFw.id] } - -output "hello_ip_addr" { - value = hcloud_server.helloServer.ipv4_address - description = "The server's IPv4 address" -} diff --git a/Doc/Sdi/CloudProvider/Terra/040HelloSshSecretApiToken/outputs.tf b/Doc/Sdi/CloudProvider/Terra/040HelloSshSecretApiToken/outputs.tf new file mode 100644 index 000000000..fb93fbb76 --- /dev/null +++ b/Doc/Sdi/CloudProvider/Terra/040HelloSshSecretApiToken/outputs.tf @@ -0,0 +1,9 @@ +output "hello_ip_addr" { + value = hcloud_server.helloServer.ipv4_address + description = "The server's IPv4 address" +} + +output "hello_datacenter" { + value = hcloud_server.helloServer.datacenter + description = "The server's datacenter" +} \ No newline at end of file diff --git a/Doc/Sdi/CloudProvider/gettingStarted.xml b/Doc/Sdi/CloudProvider/gettingStarted.xml index 974e6ae6e..a95dc5ee8 100644 --- a/Doc/Sdi/CloudProvider/gettingStarted.xml +++ b/Doc/Sdi/CloudProvider/gettingStarted.xml @@ -522,63 +522,92 @@ resource "hcloud_server" "helloServer" { ... Plan: 3 to add, 0 to change, 0 to destroy. ... -Apply complete! Resources: 3 added, 0 changed, 0 destroyed. -</screen> +Apply complete! Resources: 3 added, 0 changed, 0 destroyed.</screen> </figure> <figure xml:id="sdi_cloudProvider_terra_hello_sshApplyOutputValuesDetails1"> - <title>Output data details 1</title> - - <glosslist> - <glossentry> - <glossterm><command>terraform</command> <option - xlink:href="https://developer.hashicorp.com/terraform/language/values/outputs">output</option></glossterm> - - <glossdef> - <programlisting language="properties">hello_id = "45839978" -hello_ip_addr = "128.140.108.60"</programlisting> - </glossdef> - </glossentry> - - <glossentry> - <glossterm><command>terraform</command> <option - xlink:href="https://developer.hashicorp.com/terraform/language/values/outputs">output</option> - <option>hello_ip_addr</option></glossterm> - - <glossdef> - <screen>"128.140.108.60"</screen> - </glossdef> - </glossentry> - </glosslist> + <title>Output data details #1/2</title> + + <para>See <link + xlink:href="https://developer.hashicorp.com/terraform/language/values/outputs"> + terraform output documentation</link>:</para> + + <informaltable border="1"> + <tr> + <th>File <filename>outputs.tf</filename></th> + + <th>Result</th> + </tr> + + <tr> + <td rowspan="2" valign="top"><programlisting language="terraform">output "hello_ip_addr" { + value = hcloud_server.helloServer.ipv4_address + description = "The server's IPv4 address" +} + +output "hello_datacenter" { + value = hcloud_server.helloServer.datacenter + description = "The server's datacenter" +}</programlisting></td> + + <td valign="top"><screen language="properties">$ <command>terraform</command> output +hello_datacenter = "nbg1-dc3" +hello_ip_addr = "159.69.152.37"</screen></td> + </tr> + + <tr> + <td valign="top"><screen language="properties">$ <command>terraform</command> output hello_ip_addr +"159.69.152.37"</screen></td> + </tr> + </informaltable> </figure> <figure xml:id="sdi_cloudProvider_terra_hello_sshApplyOutputValuesDetails"> - <title>Output data details 2</title> - - <glosslist> - <glossentry> - <glossterm><command>terraform</command> <option - xlink:href="https://developer.hashicorp.com/terraform/language/values/outputs">output</option> - <option>-json</option></glossterm> - - <glossdef> - <programlisting language="json">{ - "hello_id": {"sensitive": false, "type": "string", "value": "45839978"}, - "hello_ip_addr": {"sensitive": false, "type": "string", "value": "128.140.108.60"} -}</programlisting> - </glossdef> - </glossentry> - </glosslist> + <title>Output data details #2/2</title> + + <informaltable border="1"> + <tr> + <th>File <filename>outputs.tf</filename></th> + + <th><command>terraform</command> output <option>-json</option></th> + </tr> + + <tr> + <td valign="top"><programlisting language="terraform">output "hello_ip_addr" { + value = hcloud_server.helloServer.ipv4_address + description = "The server's IPv4 address" +} + +output "hello_datacenter" { + value = hcloud_server.helloServer.datacenter + description = "The server's datacenter" +}</programlisting></td> + + <td valign="top"><programlisting language="json">{ + "hello_datacenter": { + "sensitive": false, + "type": "string", + "value": "nbg1-dc3" + }, + "hello_ip_addr": { + "sensitive": false, + "type": "string", + "value": "159.69.152.37" + } +}</programlisting></td> + </tr> + </informaltable> </figure> <figure xml:id="sdi_cloudProvider_terra_hello_sshProblemApiToken"> <title><productname>Problem 2</productname>: <xref linkend="glo_VCS"/> and visible provider API token 😱</title> - <para>Versioned file <filename>main.tf</filename>:</para> + <para><emphasis role="red">Versioned</emphasis> file + <filename>main.tf</filename>:</para> <programlisting language="terraform">... -provider "hcloud" { token = "xdaGfz9LmwO8SWkg ... "} +provider "hcloud" { token = "<emphasis role="red">xdaGfz9LmwO8SWkg ... </emphasis>"} ...</programlisting> <para>Solution:</para> @@ -598,7 +627,8 @@ provider "hcloud" { token = "xdaGfz9LmwO8SWkg ... "} <listitem> <para>Optional: Provide a versioned - <filename>secrets.auto.tfvars.template</filename> file</para> + <filename>secrets.auto.tfvars.template</filename> documenting + file</para> </listitem> </itemizedlist> </figure> -- GitLab