<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Lucas de Souza</title>
    <description>The latest articles on DEV Community by Lucas de Souza (@souzaxx).</description>
    <link>https://dev.to/souzaxx</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F248835%2F81db66d5-38fd-4044-9582-c2a167cd0ac3.jpeg</url>
      <title>DEV Community: Lucas de Souza</title>
      <link>https://dev.to/souzaxx</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/souzaxx"/>
    <language>en</language>
    <item>
      <title>Rolling update EC2 with Terraform</title>
      <dc:creator>Lucas de Souza</dc:creator>
      <pubDate>Sun, 27 Sep 2020 22:18:58 +0000</pubDate>
      <link>https://dev.to/souzaxx/rolling-update-ec2-with-terraform-13bf</link>
      <guid>https://dev.to/souzaxx/rolling-update-ec2-with-terraform-13bf</guid>
      <description>&lt;p&gt;This post is just an implementation of &lt;a href="https://medium.com/@endofcake" rel="noopener noreferrer"&gt;@endofcake's&lt;/a&gt; &lt;a href="https://medium.com/@endofcake/using-terraform-for-zero-downtime-updates-of-an-auto-scaling-group-in-aws-60faca582664" rel="noopener noreferrer"&gt;article&lt;/a&gt;. I'm going to show a real example on how to use the rolling update technique with EC2. If you want to get more background about the difference between Rolling Update and Blue/Green please check his post.&lt;/p&gt;


&lt;div class="ltag__link"&gt;
  &lt;a href="https://medium.com/@endofcake/using-terraform-for-zero-downtime-updates-of-an-auto-scaling-group-in-aws-60faca582664" class="ltag__link__link" rel="noopener noreferrer"&gt;
    &lt;div class="ltag__link__pic"&gt;
      &lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmiro.medium.com%2Fv2%2Fresize%3Afill%3A88%3A88%2F1%2A4Q1rlAvEI65QWgrhnODcag.png" alt="Alexander Savchuk"&gt;
    &lt;/div&gt;
  &lt;/a&gt;
  &lt;a href="https://medium.com/@endofcake/using-terraform-for-zero-downtime-updates-of-an-auto-scaling-group-in-aws-60faca582664" class="ltag__link__link" rel="noopener noreferrer"&gt;
    &lt;div class="ltag__link__content"&gt;
      &lt;h2&gt;Using Terraform for zero downtime updates of an Auto Scaling group in AWS | by Alexander Savchuk | Medium&lt;/h2&gt;
      &lt;h3&gt;Alexander Savchuk ・ &lt;time&gt;Aug 25, 2018&lt;/time&gt; ・ 
      &lt;div class="ltag__link__servicename"&gt;
        &lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev.to%2Fassets%2Fmedium-f709f79cf29704f9f4c2a83f950b2964e95007a3e311b77f686915c71574fef2.svg" alt="Medium Logo"&gt;
        Medium
      &lt;/div&gt;
    &lt;/h3&gt;
&lt;/div&gt;
  &lt;/a&gt;
&lt;/div&gt;


&lt;h1&gt;
  
  
  &lt;center&gt;🚨Warning🚨&lt;/center&gt;
&lt;/h1&gt;

&lt;h3&gt;
  
  
  Extreme rolling techniques ahead. Proceed with caution.
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/BL6Jq3lI1jHeU/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/BL6Jq3lI1jHeU/giphy.gif" alt="rolling"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Terraform can do Blue/Breen natively, just add &lt;code&gt;create_before_destroy = true&lt;/code&gt; in the &lt;a href="https://www.terraform.io/docs/configuration/resources.html#lifecycle-lifecycle-customizations" rel="noopener noreferrer"&gt;lifecycle block&lt;/a&gt; and the terraform will create the resource in a blue/green manner.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight terraform"&gt;&lt;code&gt;&lt;span class="k"&gt;resource&lt;/span&gt; &lt;span class="s2"&gt;"azurerm_resource_group"&lt;/span&gt; &lt;span class="s2"&gt;"example"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;# ...&lt;/span&gt;

  &lt;span class="nx"&gt;lifecycle&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;create_before_destroy&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
Fig.1 - Lifecycle block example.




&lt;p&gt;In other to show this update I decided to create a really simple web page using Packer to create the images.&lt;/p&gt;
&lt;h3&gt;
  
  
  Speed things up with Packer
&lt;/h3&gt;

&lt;p&gt;Before we dive into how to create rolling updates with terraform let's talk a little about Packer.&lt;/p&gt;

&lt;p&gt;HashiCorp &lt;a href="https://www.packer.io/intro#what-is-packer" rel="noopener noreferrer"&gt;Packer&lt;/a&gt; aims to build automated machine images, which means, we can create scripts to configure images with our application inside, installing all the dependencies that our application needs.&lt;/p&gt;

&lt;p&gt;In our example, we use Packer to build a very simple HTTP server. I created a simple script that will install Apache web server and create a web page with a specif background color ( you can choose the color, exciting isn't it? ).&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;



&lt;p&gt;To update the "version" of our application just change the color variable to any color of your preference. The default color of our web page is red.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight hcl"&gt;&lt;code&gt;&lt;span class="nx"&gt;variable&lt;/span&gt; &lt;span class="s2"&gt;"color"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;default&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"red"&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
variable.pkr.hcl




&lt;p&gt;I won't get into details of Packer in this post, but basically, Packer will create an EC2 instance, execute the &lt;code&gt;scripts/basic-website.sh&lt;/code&gt; inside it, and take a snapshot of that instance, saving it as &lt;code&gt;rolling_update_{{timestamp}}&lt;/code&gt;. The execution of this script is described in the &lt;code&gt;provisioner&lt;/code&gt; block.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;



&lt;p&gt;I know that isn't a good tutorial, but enough of Packer for now.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/lUB49ZnxhLsZi/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/lUB49ZnxhLsZi/giphy.gif" alt="enough"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Rolling Update with Terraform
&lt;/h2&gt;

&lt;p&gt;Well, here's the fun part. Terraform has no way to do this. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/pPhyAv5t9V8djyRFJH/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/pPhyAv5t9V8djyRFJH/giphy.gif" alt="rolling"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Terraform has no way to know if your application is alive nor to check what is the current version; because it was not built for this purpose.&lt;/p&gt;

&lt;p&gt;Although we can configure health-checks on Targets Groups and Auto Scaling Groups, Terraform will not care if the application is healthy after finishing the apply phase.&lt;/p&gt;

&lt;p&gt;In other to create the rolling update with Terraform we are going to use a little hack... We are going to use CloudFormation!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.imgflip.com%2Fzxlb8.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.imgflip.com%2Fzxlb8.jpg" alt="isThatSo"&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;CloudFormation gives to Auto Scaling Group a really cool feature, the &lt;strong&gt;UpdatePolicy&lt;/strong&gt;. This is a policy that is triggered every time that ASG is updated, which means if we launch a new version of a launch template we can trigger our ASG to update its instances.&lt;/p&gt;

&lt;p&gt;We can take advantage of this CloudFormation automation and blend it into Terraform!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/TbYgHMnICI1A4/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/TbYgHMnICI1A4/giphy.gif" alt="fusion"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Ok, Lucas, &lt;a href="https://medium.com/@endofcake" rel="noopener noreferrer"&gt;@endofcake&lt;/a&gt; already explains all this to us.&lt;/p&gt;

&lt;p&gt;Less talk and more code.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/l2JecCAExsqUC4HDy/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/l2JecCAExsqUC4HDy/giphy.gif" alt="start"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;First, clone this git repository:&lt;/p&gt;


&lt;div class="ltag-github-readme-tag"&gt;
  &lt;div class="readme-overview"&gt;
    &lt;h2&gt;
      &lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev.to%2Fassets%2Fgithub-logo-5a155e1f9a670af7944dd5e12375bc76ed542ea80224905ecaf878b9157cdefc.svg" alt="GitHub logo"&gt;
      &lt;a href="https://github.com/souzaxx" rel="noopener noreferrer"&gt;
        souzaxx
      &lt;/a&gt; / &lt;a href="https://github.com/souzaxx/Rolling-Update-Terraform" rel="noopener noreferrer"&gt;
        Rolling-Update-Terraform
      &lt;/a&gt;
    &lt;/h2&gt;
    &lt;h3&gt;
      Code example for RollingUpdate with Terraform and Packer
    &lt;/h3&gt;
  &lt;/div&gt;
&lt;/div&gt;


&lt;p&gt;Create our first AMI going inside the &lt;code&gt;packer&lt;/code&gt; folder.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;cd &lt;/span&gt;packer
packer build &lt;span class="nb"&gt;.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Wait until the AMI is created
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F5e1d7y5s3918ol22wp26.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F5e1d7y5s3918ol22wp26.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After that, go back to the root of the repository and apply the terraform.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;cd&lt;/span&gt; ..
terraform init
terraform apply
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To check that our web page is up and running gets the LoadBalancer DNS from Terraform output &lt;code&gt;terraform output lb_dns&lt;/code&gt; and open it in your favorite browser or just curl it &lt;code&gt;curl $(terraform output lb_dns)&lt;/code&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Update the Image
&lt;/h3&gt;

&lt;p&gt;In other to check the update progress, execute this loop in another terminal:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="k"&gt;while &lt;/span&gt;&lt;span class="nb"&gt;true&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;do
&lt;/span&gt;curl &lt;span class="si"&gt;$(&lt;/span&gt;terraform output lb_dns&lt;span class="si"&gt;)&lt;/span&gt;
&lt;span class="nb"&gt;sleep &lt;/span&gt;1
&lt;span class="k"&gt;done&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, create a new "version" of our application by choosing a color. You can overwrite the default variable passing &lt;code&gt;-var 'color=green'&lt;/code&gt; into the packer CLI.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cd packer
packer build -var 'color=green' .
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Wait for its completion and apply the terraform again:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;cd&lt;/span&gt; ..
terraform apply
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We can check that &lt;code&gt;lauchconfiguration&lt;/code&gt; and &lt;code&gt;cloudformation&lt;/code&gt; resources have changed.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fv9mgy54emkuq7fth7w3z.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fv9mgy54emkuq7fth7w3z.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Confirm the apply and check the curl loop to see the changes in realtime.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fu3x03istrtxyza0rcw2x.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fu3x03istrtxyza0rcw2x.png" alt="final"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Conclusion
&lt;/h1&gt;

&lt;p&gt;I hope this post was useful for your studies in Terraform and in my next post I want to show this process with a real application such as Consul.&lt;/p&gt;

&lt;h2&gt;
  
  
  Clean up
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;terraform destroy --auto-approve
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;and delete all the AMI created by Packer:&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F8l8hytsh28jbjfonqdf8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F8l8hytsh28jbjfonqdf8.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Thank you for your time and&lt;/p&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/js0dt5JLCU01bvlt7d/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/js0dt5JLCU01bvlt7d/giphy.gif" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>terraform</category>
      <category>packer</category>
      <category>devops</category>
      <category>aws</category>
    </item>
    <item>
      <title>Terraform + Helm = ❤️</title>
      <dc:creator>Lucas de Souza</dc:creator>
      <pubDate>Sun, 20 Sep 2020 14:53:54 +0000</pubDate>
      <link>https://dev.to/souzaxx/terraform-helm-57bk</link>
      <guid>https://dev.to/souzaxx/terraform-helm-57bk</guid>
      <description>&lt;p&gt;If you ever tried to manage IaC with Terraform you might end up with “Well, the cloud resources are fine, but how am I going to deal with my Kubernetes cluster???”&lt;/p&gt;

&lt;p&gt;In this post, I want to share a simple and functional example of how you can integrate Helm with Terraform using the best of each tool.&lt;/p&gt;

&lt;p&gt;The setup of this integration became much easier after Helm v3 was released. Now, you can simply pass your Kubernetes credentials to the Helm Provider and start deploying your charts using Terraform!&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight terraform"&gt;&lt;code&gt;&lt;span class="k"&gt;provider&lt;/span&gt; &lt;span class="s2"&gt;"helm"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;kubernetes&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;config_path&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"/path/to/kube_cluster.yaml"&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;You can now deploy Charts using the &lt;code&gt;helm_release&lt;/code&gt; resource 🎉.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight terraform"&gt;&lt;code&gt;&lt;span class="k"&gt;resource&lt;/span&gt; &lt;span class="s2"&gt;"helm_release"&lt;/span&gt; &lt;span class="s2"&gt;"example"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;name&lt;/span&gt;       &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"my-redis-release"&lt;/span&gt;
  &lt;span class="nx"&gt;repository&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"https://kubernetes-charts.storage.googleapis.com"&lt;/span&gt; 
  &lt;span class="nx"&gt;chart&lt;/span&gt;      &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"redis"&lt;/span&gt;
  &lt;span class="nx"&gt;version&lt;/span&gt;    &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"6.0.1"&lt;/span&gt;

  &lt;span class="nx"&gt;values&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;file&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"values.yaml"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
  &lt;span class="p"&gt;]&lt;/span&gt;

  &lt;span class="nx"&gt;set&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;name&lt;/span&gt;  &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"cluster.enabled"&lt;/span&gt;
    &lt;span class="nx"&gt;value&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"true"&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="nx"&gt;set&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;name&lt;/span&gt;  &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"metrics.enabled"&lt;/span&gt;
    &lt;span class="nx"&gt;value&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"true"&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="nx"&gt;set_string&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;name&lt;/span&gt;  &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"service.annotations.prometheus&lt;/span&gt;&lt;span class="se"&gt;\\&lt;/span&gt;&lt;span class="s2"&gt;.io/port"&lt;/span&gt;
    &lt;span class="nx"&gt;value&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"9127"&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Ok, that's fine Lucas, but you have basically shown the Helm provider &lt;a href="https://registry.terraform.io/providers/hashicorp/helm/latest/docs/resources/release" rel="noopener noreferrer"&gt;page&lt;/a&gt;... Am I wasting my time here?&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.kym-cdn.com%2Fentries%2Ficons%2Foriginal%2F000%2F029%2F433%2Fholdup.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.kym-cdn.com%2Fentries%2Ficons%2Foriginal%2F000%2F029%2F433%2Fholdup.jpg" alt="hold-up"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In this post, I want to deal with all this excessive &lt;code&gt;set {}&lt;/code&gt; parameters in the helm_relase resource. There must be an easier way to manage these variables.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/lKXEBR8m1jWso/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/lKXEBR8m1jWso/giphy.gif" alt="thinking"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Actually, the tutorial has already shown us how! We can use the &lt;code&gt;values&lt;/code&gt; parameter and pass all our variables in a YAML format.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight terraform"&gt;&lt;code&gt;&lt;span class="nx"&gt;values&lt;/span&gt; &lt;span class="err"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
  &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;file&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"values.yaml"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Instead of using the file function, we can also pass in EOF format:&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;



&lt;p&gt;Lucas...&lt;/p&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/cA9nwFy2pVXmU/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/cA9nwFy2pVXmU/giphy.gif" alt="am-i-joke-to-you?"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Okay, okay, I'm sorry! I'm getting into the point, wait a little longer!&lt;/p&gt;

&lt;h2&gt;
  
  
  templatefile
&lt;/h2&gt;

&lt;p&gt;In terraform, we can create dynamic templates using the &lt;code&gt;templatefile&lt;/code&gt; &lt;a href="https://www.terraform.io/docs/configuration/functions/templatefile.html" rel="noopener noreferrer"&gt;function&lt;/a&gt;. Combe this function with the &lt;code&gt;values&lt;/code&gt; parameter in the helm_release resource and we get a lot of flexibility!&lt;/p&gt;

&lt;p&gt;The templatefile function has a slite different syntax than Terraform, but you can easily adapt to it.&lt;/p&gt;

&lt;p&gt;An example would be:&lt;/p&gt;

&lt;p&gt;backends.tmpl&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight terraform"&gt;&lt;code&gt;&lt;span class="err"&gt;%&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;for&lt;/span&gt; &lt;span class="nx"&gt;addr&lt;/span&gt; &lt;span class="nx"&gt;in&lt;/span&gt; &lt;span class="nx"&gt;ip_addrs&lt;/span&gt; &lt;span class="err"&gt;~&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nx"&gt;backend&lt;/span&gt; &lt;span class="nx"&gt;$&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;addr&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="err"&gt;:&lt;/span&gt;&lt;span class="nx"&gt;$&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;port&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="err"&gt;%&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;endfor&lt;/span&gt; &lt;span class="err"&gt;~&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;And to render this template:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight terraform"&gt;&lt;code&gt;&lt;span class="nx"&gt;templatefile&lt;/span&gt;&lt;span class="err"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;path&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;module}&lt;/span&gt;&lt;span class="s2"&gt;/backends.tmpl"&lt;/span&gt;&lt;span class="err"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;port&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;8080&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;ip_addrs&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"10.0.0.1"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"10.0.0.2"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="err"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Giving the output:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;backend 10.0.0.1:8080
backend 10.0.0.2:8080
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;And yes, we can also use if statements if you wondered.&lt;/p&gt;

&lt;p&gt;We can use all this flexibility right into the values parameter, and here is an example of how to create a dynamic &lt;code&gt;values.yaml&lt;/code&gt;:&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;



&lt;p&gt;Templatefile also accept terraform objects making our life easier&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;If you want to follow the complete example:&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag-github-readme-tag"&gt;
  &lt;div class="readme-overview"&gt;
    &lt;h2&gt;
      &lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev.to%2Fassets%2Fgithub-logo-5a155e1f9a670af7944dd5e12375bc76ed542ea80224905ecaf878b9157cdefc.svg" alt="GitHub logo"&gt;
      &lt;a href="https://github.com/souzaxx" rel="noopener noreferrer"&gt;
        souzaxx
      &lt;/a&gt; / &lt;a href="https://github.com/souzaxx/EKS-on-steroids" rel="noopener noreferrer"&gt;
        EKS-on-steroids
      &lt;/a&gt;
    &lt;/h2&gt;
    &lt;h3&gt;
      
    &lt;/h3&gt;
  &lt;/div&gt;
&lt;/div&gt;


&lt;p&gt;&lt;a href="https://i.giphy.com/media/V2ZrZfHghzSNi/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/V2ZrZfHghzSNi/giphy.gif" alt="thats-all"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In my next post, I'll explain in more detail about this project and how it can help eks clusters running out IPs address.&lt;/p&gt;

&lt;p&gt;Thank you for your reading,&lt;/p&gt;

&lt;p&gt;Stay safe; stay well.&lt;/p&gt;

&lt;p&gt;Lucas.&lt;/p&gt;

</description>
      <category>kubernetes</category>
      <category>devops</category>
      <category>terraform</category>
    </item>
  </channel>
</rss>
