<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-us"><generator uri="https://gohugo.io/" version="0.156.0">Hugo</generator><title type="html">Terraform-Cloud on Marcin Jasion - Pragmatic DevOps</title><link href="https://2a300508.mjasion.pages.dev/tags/terraform-cloud/" rel="alternate" type="text/html" title="html"/><link href="https://2a300508.mjasion.pages.dev/tags/terraform-cloud/index.xml" rel="alternate" type="application/rss+xml" title="rss"/><updated>2022-06-14T00:00:00+02:00</updated><id>https://2a300508.mjasion.pages.dev/tags/terraform-cloud/</id><entry><title type="html">How to configure parallelism in Terraform Cloud</title><link href="https://2a300508.mjasion.pages.dev/posts/cloud/how-to-set-parallelism-in-terraform-cloud/?utm_source=atom_feed" rel="alternate" type="text/html"/><link href="https://2a300508.mjasion.pages.dev/posts/cloud/how-to-enable-debug-in-terraform-cloud/?utm_source=atom_feed" rel="related" type="text/html" title="How to enable debug and trace logs in Terraform Cloud and Enterprise"/><id>https://2a300508.mjasion.pages.dev/posts/cloud/how-to-set-parallelism-in-terraform-cloud/</id><author><name>Marcin Jasion</name></author><published>2022-06-14T00:00:00+02:00</published><updated>2022-06-14T00:00:00+02:00</updated><content type="html"><![CDATA[<blockquote>Remote terraform execution runs on default parallelism value. There is a simple way to improve execution speed 4 times</blockquote><p>In my previous <a href="../how-to-enable-debug-in-terraform-cloud/">post</a> I showed how to enable debug logs. Today I want to present how to improve <code>terraform plan</code> and <code>terraform apply</code> speed by configuring <strong>parallelism</strong>.</p>
<p><a href="https://www.terraform.io/" target="_blank" rel="noopener">Terraform</a> by default runs <code>10</code> concurrent operations. To reduce execution time on plan or apply operation we can increase this parameter.</p>
<blockquote>
<p>By increasing <strong>parallelism</strong> you can hit the rate limit of your provider. Some cloud providers (like <a href="https://developers.cloudflare.com/terraform/advanced-topics/provider-customization/#increase-the-frequency-of-api-requests" target="_blank" rel="noopener">Cloudflare</a>) inform about the number of API requests allowed in a period of time. Hitting the limit can impact your deployments.</p>
</blockquote>
<h2 id="tfe_parallelism-variable"><code>TFE_PARALLELISM</code> variable</h2>
<p>The easiest way to increase parallelism in Terraform Cloud for Remote Execution is the <code>TFE_PARALLELISM</code> variable. It just requires a number. To set this you need to perform those steps:</p>
<ul>
<li>Select your workspace,</li>
<li>Go to <strong>Variables</strong> tab,</li>
<li>Add variable in <strong>Workspace variables</strong> panel and create <code>TFE_PARALLELISM</code> variable:
<img src="/posts/cloud/how-to-set-parallelism-in-terraform-cloud/workspace_tfe_parallelism.png" alt="Workspace TFE_PARALLELISM variable">
<blockquote>
<p>Ensure you have selected <strong>Environment variable</strong> button</p>
</blockquote>
</li>
</ul>
<p>The change should be available on next execution.</p>
<h2 id="manage-parallelism-for-each-stage-of-execution">Manage parallelism for each stage of execution</h2>
<p>Terraform CLI allows configuring parallelism differently per command (<code>terraform plan</code>, <code>terraform apply</code> or <code>terraform destroy</code>). In Terraform Cloud we can also do this. In these cases, use <code>TF_CLI_ARGS_plan=&quot;-parallelism=&lt;N&gt;&quot;</code> or <code>TF_CLI_ARGS_apply=&quot;-parallelism=&lt;N&gt;&quot;</code> environment variables instead of <code>TFE_PARALLELISM</code>.</p>
<p>I prefer this way because it allows being more granular. I want to run plan fast because it makes a request about every resource.</p>
<p>To set <code>TF_CLI_ARGS_plan=&quot;-parallelism=&lt;N&gt;&quot;</code> or <code>TF_CLI_ARGS_apply=&quot;-parallelism=&lt;N&gt;&quot;</code> parameters perform same steps as in instruction written above for <code>TFE_PARALLELISM</code>.</p>
<h2 id="manage-the-variables-in-a-single-place">Manage the variables in a single place</h2>
<p>I showed how to configure a variable per workspace. Terraform Cloud allows configuring a <strong>Variable set</strong> which can be attached to each workspace, so we don&rsquo;t need to repeat ourselves for each workspace.</p>
<p>To configure <strong>Variable set</strong> do:</p>
<ul>
<li>Go to your organization <strong>Settings</strong></li>
<li>Select <strong>Variable set</strong> tab and click button <strong>Create variable set</strong></li>
<li>In <strong>Variables</strong> panel you need to define your variables</li>
</ul>
<p>What is left is to attach the variable set to your workspace, or you can enable this set for all workspaces in the organization.</p>
<p><strong>Variables set</strong> has lower precedence than workspace variables. Definition of the same variable in workspace will be used in execution. <a href="https://www.terraform.io/cloud-docs/workspaces/variables#precedence" target="_blank" rel="noopener">Here</a> you can read more.</p>
]]></content><category scheme="https://2a300508.mjasion.pages.dev/tags/terraform" term="terraform" label="terraform"/><category scheme="https://2a300508.mjasion.pages.dev/tags/terraform-cloud" term="terraform-cloud" label="terraform-cloud"/><category scheme="https://2a300508.mjasion.pages.dev/tags/performance" term="performance" label="performance"/></entry><entry><title type="html">How to enable debug and trace logs in Terraform Cloud and Enterprise</title><link href="https://2a300508.mjasion.pages.dev/posts/cloud/how-to-enable-debug-in-terraform-cloud/?utm_source=atom_feed" rel="alternate" type="text/html"/><link href="https://2a300508.mjasion.pages.dev/posts/kubernetes/how-to-debug-istio-upstream-reset/?utm_source=atom_feed" rel="related" type="text/html" title="How to debug Istio Upstream Reset 502 UPE (old 503 UC)"/><id>https://2a300508.mjasion.pages.dev/posts/cloud/how-to-enable-debug-in-terraform-cloud/</id><author><name>Marcin Jasion</name></author><published>2022-06-10T00:00:00+02:00</published><updated>2022-06-10T00:00:00+02:00</updated><content type="html"><![CDATA[<blockquote>Remote terraform execution does not forward CLI parameters. This post covers how to do this.</blockquote><p><a href="https://cloud.hashicorp.com/products/terraform" target="_blank" rel="noopener">Terraform Cloud</a> is an application that helps teams use Terraform together. I am using it for side projects like my cloud infrastructure. Last time I had to see trace logs to find an issue with one of the managed resources.</p>
<p><a href="https://www.terraform.io/" target="_blank" rel="noopener">Terraform</a> has detailed logs which can be enabled by setting the <code>TF_LOG</code> environment variable to any value. This will cause detailed logs to appear on execution.</p>
<h2 id="enabling-verbose-logging-in-cli">Enabling verbose logging in CLI</h2>
<p>You can set <code>TF_LOG</code> to one of the log levels <code>TRACE</code>, <code>DEBUG</code>, <code>INFO</code>, <code>WARN</code> or <code>ERROR</code> to change the verbosity of the logs. You can set this variable in two ways. First option is to set variable for shell session:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>$ export TF_LOG<span style="color:#f92672">=</span>TRACE
</span></span><span style="display:flex;"><span>$ terraform plan
</span></span></code></pre></div><p>Second option is to change variable before command execution</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>$ TF_LOG<span style="color:#f92672">=</span>TRACE terraform plan
</span></span></code></pre></div><h2 id="enabling-logging-in-terraform-cloud">Enabling logging in Terraform Cloud</h2>
<p>If this run is in Terraform Cloud or Terraform Enterprise with Remote Execution, perform these steps:</p>
<ul>
<li>Select your workspace,</li>
<li>Go to <strong>Variables</strong> tab,</li>
<li>Add variable in <strong>Workspace variables</strong> panel and create <code>TF_LOG</code> variable:
<img src="/posts/cloud/how-to-enable-debug-in-terraform-cloud/workspace_variables.png" alt="Workspace Variables">
<blockquote>
<p>Ensure you have selected <strong>Environment variable</strong> button</p>
</blockquote>
</li>
<li>Perform the run that you want to trace</li>
</ul>
<h3 id="another-option-is-to-enable-local-execution">Another option is to enable local execution</h3>
<p>If you are working on your own project, it will be much more convenient to disable Remote Execution and execute the run locally. Go to workspace <strong>Settings</strong> and in <strong>Execution Mode</strong> panel switch the button to <strong>Local</strong>. Then you can run plan from your local machine.</p>
<hr>
<p>Once the issue is resolved, unset the <code>TF_LOG</code> environment variable to disable the enhanced logging.</p>
]]></content><category scheme="https://2a300508.mjasion.pages.dev/tags/terraform" term="terraform" label="terraform"/><category scheme="https://2a300508.mjasion.pages.dev/tags/terraform-cloud" term="terraform-cloud" label="terraform-cloud"/><category scheme="https://2a300508.mjasion.pages.dev/tags/debugging" term="debugging" label="debugging"/></entry></feed>