<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Tips and Pitfalls on function-hcl</title><link>https://crossplane-contrib.github.io/function-hcl/docs/tips-and-pitfalls/</link><description>Recent content in Tips and Pitfalls on function-hcl</description><generator>Hugo</generator><language>en</language><atom:link href="https://crossplane-contrib.github.io/function-hcl/docs/tips-and-pitfalls/index.xml" rel="self" type="application/rss+xml"/><item><title>Best Practices</title><link>https://crossplane-contrib.github.io/function-hcl/docs/tips-and-pitfalls/best-practices/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://crossplane-contrib.github.io/function-hcl/docs/tips-and-pitfalls/best-practices/</guid><description>&lt;h2 id="always-use-fn-hcl-tools-package"&gt;Always use fn-hcl-tools package&lt;/h2&gt;
&lt;p&gt;Run &lt;code&gt;fn-hcl-tools package&lt;/code&gt; to produce your txtar script rather than hand-crafting it. This
validates your HCL before it reaches the cluster, catching typos in variable names, bad block
structure, and syntax errors at authoring time.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;fn-hcl-tools package ./my-composition/
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h2 id="use-locals-to-name-things"&gt;Use locals to name things&lt;/h2&gt;
&lt;p&gt;Pull commonly-used expressions into top-level locals. This makes the code easier to read and
avoids long repeated expressions like &lt;code&gt;req.composite.spec.parameters&lt;/code&gt; deep inside resource bodies.&lt;/p&gt;</description></item><item><title>Gotchas</title><link>https://crossplane-contrib.github.io/function-hcl/docs/tips-and-pitfalls/gotchas/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://crossplane-contrib.github.io/function-hcl/docs/tips-and-pitfalls/gotchas/</guid><description>&lt;h2 id="dashes-in-identifiers-mean-you-cant-subtract-without-spaces"&gt;Dashes in identifiers mean you can&amp;rsquo;t subtract without spaces&lt;/h2&gt;
&lt;p&gt;HCL allows dashes in identifiers. This means &lt;code&gt;a-b&lt;/code&gt; is a single identifier, not &lt;code&gt;a&lt;/code&gt; minus &lt;code&gt;b&lt;/code&gt;.
Use spaces for arithmetic: &lt;code&gt;a - b&lt;/code&gt;.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-hcl" data-lang="hcl"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="k"&gt;locals&lt;/span&gt; {
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="n"&gt; my-var&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="m"&gt;10&lt;/span&gt;&lt;span class="c1"&gt; # this is a variable named &amp;#34;my-var&amp;#34;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="n"&gt; result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;my&lt;/span&gt;&lt;span class="err"&gt;-&lt;/span&gt;&lt;span class="k"&gt;var&lt;/span&gt;&lt;span class="c1"&gt; # refers to the variable, not &amp;#34;my&amp;#34; minus &amp;#34;var&amp;#34;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="n"&gt; diff&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;a&lt;/span&gt; &lt;span class="err"&gt;-&lt;/span&gt; &lt;span class="k"&gt;b&lt;/span&gt;&lt;span class="c1"&gt; # subtraction -- spaces required
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;}
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h2 id="body-is-an-attribute-not-a-block"&gt;body is an attribute, not a block&lt;/h2&gt;
&lt;p&gt;&lt;code&gt;body&lt;/code&gt; must use &lt;code&gt;=&lt;/code&gt; for assignment. Omitting &lt;code&gt;=&lt;/code&gt; turns it into a block, which is a different
HCL construct and will produce a schema error.&lt;/p&gt;</description></item></channel></rss>