<?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: Arun Singh Sisodiya</title>
    <description>The latest articles on DEV Community by Arun Singh Sisodiya (@arunsinghsisodiya).</description>
    <link>https://dev.to/arunsinghsisodiya</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%2F228876%2Fb3a27104-5cf2-4922-a916-1b408b428306.jpg</url>
      <title>DEV Community: Arun Singh Sisodiya</title>
      <link>https://dev.to/arunsinghsisodiya</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/arunsinghsisodiya"/>
    <language>en</language>
    <item>
      <title>Mastering Terraform Functions: A Guide with Examples 👨‍💻</title>
      <dc:creator>Arun Singh Sisodiya</dc:creator>
      <pubDate>Sat, 25 Feb 2023 10:52:20 +0000</pubDate>
      <link>https://dev.to/arunsinghsisodiya/mastering-terraform-functions-a-guide-with-examples-4819</link>
      <guid>https://dev.to/arunsinghsisodiya/mastering-terraform-functions-a-guide-with-examples-4819</guid>
      <description>&lt;p&gt;Discover the power of Terraform functions and learn how to use them to simplify your infrastructure as code. From filesystem functions to collection and encoding functions, we cover it all with examples and images.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--G2pL9dfY--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/4800/1%2Ay0HZCbscmEJoWtG9LMaueA.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--G2pL9dfY--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/4800/1%2Ay0HZCbscmEJoWtG9LMaueA.png" alt="Terraform banner" width="880" height="461"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;In this blog post, we’ll explore the world of Terraform functions and how they can help you write more concise and powerful infrastructure as code. With Terraform functions, you can perform advanced data manipulation, simplify variable interpolation, and work with files and directories. We’ll show you how to use Terraform functions in your code, with examples and images to guide you.&lt;/p&gt;

&lt;h2&gt;
  
  
  What are Terraform functions?
&lt;/h2&gt;

&lt;p&gt;👋 Hey there, fellow Terraform users! Are you looking to level up your infrastructure-as-code game? Well, have you considered using Terraform functions? 🤔&lt;/p&gt;

&lt;p&gt;Terraform functions allow you to perform various operations on your Terraform code. They can generate dynamic values, manipulate strings, and perform mathematical calculations, among other things. This blog post will cover some of the most common Terraform functions and how you can use them in your code.&lt;/p&gt;

&lt;p&gt;Terraform functions are used in the expression of an argument and return a value of a specified type. The built-in functions can be generalized using the syntax below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&amp;lt;function_name&amp;gt;&lt;span class="o"&gt;(&lt;/span&gt;arg 1, arg 2&lt;span class="o"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The number and type of arguments accepted by Terraform functions are predefined. The Terraform language includes several built-in functions that you can call from within expressions to transform and combine values.&lt;/p&gt;

&lt;h2&gt;
  
  
  🌟 Interpolation Functions 🌟
&lt;/h2&gt;

&lt;p&gt;Interpolation functions are used to insert a value into a string. They can be used in resource configuration blocks, data source configuration blocks, and other parts of your Terraform code.&lt;/p&gt;

&lt;p&gt;Let’s see some examples and do some hands-on:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href="https://developer.hashicorp.com/terraform/language/functions/format"&gt;format()&lt;/a&gt;: This function is used to format a string. It takes one or more arguments and returns a formatted string.&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;Syntax→ &lt;span class="sb"&gt;`&lt;/span&gt;fomrat&lt;span class="o"&gt;(&lt;/span&gt;spec, values...&lt;span class="o"&gt;)&lt;/span&gt;&lt;span class="sb"&gt;`&lt;/span&gt;

E.g.
&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; format&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Hello, %s!"&lt;/span&gt;, &lt;span class="s2"&gt;"Terraform"&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
Hello Terraform
&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; format&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"There are %d lights"&lt;/span&gt;, 4&lt;span class="o"&gt;)&lt;/span&gt;
There are 4 lights
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href="https://developer.hashicorp.com/terraform/language/functions/join"&gt;join()&lt;/a&gt;: This function is used to concatenate a list of strings. It takes two arguments: a separator and a list of strings.&lt;/p&gt;

&lt;p&gt;Syntax→ &lt;code&gt;join(separator, list)&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;E.g.
&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;join&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;", "&lt;/span&gt;, &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"foo"&lt;/span&gt;, &lt;span class="s2"&gt;"bar"&lt;/span&gt;, &lt;span class="s2"&gt;"baz"&lt;/span&gt;&lt;span class="o"&gt;])&lt;/span&gt;
foo, bar, baz
&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;join&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;", "&lt;/span&gt;, &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"foo"&lt;/span&gt;&lt;span class="o"&gt;])&lt;/span&gt;
foo
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href="https://developer.hashicorp.com/terraform/language/functions/lookup"&gt;lookup()&lt;/a&gt;: This function is used to look up a value in a map. It takes two arguments: the map and the key.&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;Syntax→ &lt;span class="sb"&gt;`&lt;/span&gt;lookup&lt;span class="o"&gt;(&lt;/span&gt;map, key, default&lt;span class="o"&gt;)&lt;/span&gt;&lt;span class="sb"&gt;`&lt;/span&gt;

E.g.
&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; lookup&lt;span class="o"&gt;({&lt;/span&gt;&lt;span class="nv"&gt;a&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"ay"&lt;/span&gt;, &lt;span class="nv"&gt;b&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"bee"&lt;/span&gt;&lt;span class="o"&gt;}&lt;/span&gt;, &lt;span class="s2"&gt;"a"&lt;/span&gt;, &lt;span class="s2"&gt;"what?"&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
ay
&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; lookup&lt;span class="o"&gt;({&lt;/span&gt;&lt;span class="nv"&gt;a&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"ay"&lt;/span&gt;, &lt;span class="nv"&gt;b&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"bee"&lt;/span&gt;&lt;span class="o"&gt;}&lt;/span&gt;, &lt;span class="s2"&gt;"c"&lt;/span&gt;, &lt;span class="s2"&gt;"what?"&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
what?
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  🌟 Numeric Functions 🌟
&lt;/h2&gt;

&lt;p&gt;Numeric functions are used to perform mathematical calculations. They can be used in resource configuration blocks, data source configuration blocks, and other parts of your Terraform code.&lt;/p&gt;

&lt;p&gt;Let’s see some examples and do some hands-on:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href="https://developer.hashicorp.com/terraform/language/functions/abs"&gt;abs()&lt;/a&gt;: abs returns the absolute value of the given number.&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; abs&lt;span class="o"&gt;(&lt;/span&gt;23&lt;span class="o"&gt;)&lt;/span&gt;
23
&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; abs&lt;span class="o"&gt;(&lt;/span&gt;0&lt;span class="o"&gt;)&lt;/span&gt;
0
&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; abs&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nt"&gt;-12&lt;/span&gt;.4&lt;span class="o"&gt;)&lt;/span&gt;
12.4
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href="https://developer.hashicorp.com/terraform/language/functions/ceil"&gt;ceil()&lt;/a&gt;: ceil returns the closest whole number that is greater than or equal to the given value, which may be a fraction.&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; ceil&lt;span class="o"&gt;(&lt;/span&gt;5&lt;span class="o"&gt;)&lt;/span&gt;
5
&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; ceil&lt;span class="o"&gt;(&lt;/span&gt;5.1&lt;span class="o"&gt;)&lt;/span&gt;
6
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href="https://developer.hashicorp.com/terraform/language/functions/floor"&gt;floor()&lt;/a&gt;: floor returns the closest whole number that is less than or equal to the given value, which may be a fraction.&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; floor&lt;span class="o"&gt;(&lt;/span&gt;5&lt;span class="o"&gt;)&lt;/span&gt;
5
&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; floor&lt;span class="o"&gt;(&lt;/span&gt;4.9&lt;span class="o"&gt;)&lt;/span&gt;
4
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href="https://developer.hashicorp.com/terraform/language/functions/log"&gt;log()&lt;/a&gt;: log returns the logarithm of a given number in a given base.&lt;/p&gt;

&lt;p&gt;Syntax→ log(number, base)&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;E.g.
&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; log&lt;span class="o"&gt;(&lt;/span&gt;50, 10&lt;span class="o"&gt;)&lt;/span&gt;
1.6989700043360185
&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; log&lt;span class="o"&gt;(&lt;/span&gt;16, 2&lt;span class="o"&gt;)&lt;/span&gt;
4
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href="https://developer.hashicorp.com/terraform/language/functions/max"&gt;max()&lt;/a&gt;: max takes one or more numbers and returns the greatest number from the set. If the numbers are in a list or set value, use ... to expand the collection to individual arguments:&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; max&lt;span class="o"&gt;(&lt;/span&gt;12, 54, 3&lt;span class="o"&gt;)&lt;/span&gt;
54
&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; max&lt;span class="o"&gt;([&lt;/span&gt;12, 54, 3]...&lt;span class="o"&gt;)&lt;/span&gt;
54
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href="https://developer.hashicorp.com/terraform/language/functions/min"&gt;min()&lt;/a&gt;: min takes one or more numbers and returns the smallest number from the set.If the numbers are in a list or set value, use ... to expand the collection to individual arguments:&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; min&lt;span class="o"&gt;(&lt;/span&gt;12, 54, 3&lt;span class="o"&gt;)&lt;/span&gt;
3
&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; min&lt;span class="o"&gt;([&lt;/span&gt;12, 54, 3]...&lt;span class="o"&gt;)&lt;/span&gt;
3
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href="https://developer.hashicorp.com/terraform/language/functions/pow"&gt;pow()&lt;/a&gt;: pow calculates an exponent, by raising its first argument to the power of the second argument.&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; pow&lt;span class="o"&gt;(&lt;/span&gt;3, 2&lt;span class="o"&gt;)&lt;/span&gt;
9
&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; pow&lt;span class="o"&gt;(&lt;/span&gt;4, 0&lt;span class="o"&gt;)&lt;/span&gt;
1
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href="https://developer.hashicorp.com/terraform/language/functions/signum"&gt;signum()&lt;/a&gt;: signum determines the sign of a number, returning a number between -1 and 1 to represent the sign.&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; signum&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nt"&gt;-13&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
&lt;span class="nt"&gt;-1&lt;/span&gt;
&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; signum&lt;span class="o"&gt;(&lt;/span&gt;0&lt;span class="o"&gt;)&lt;/span&gt;
0
&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; signum&lt;span class="o"&gt;(&lt;/span&gt;344&lt;span class="o"&gt;)&lt;/span&gt;
1
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href="https://developer.hashicorp.com/terraform/language/functions/parseint"&gt;parseint()&lt;/a&gt;: parseint parses the given string as a representation of an integer in the specified base and returns the resulting number. The base must be between 2 and 62 inclusive. All bases use the arabic numerals 0 through 9 first. Bases between 11 and 36 inclusive use case-insensitive latin letters to represent higher unit values. Bases 37 and higher use lowercase latin letters and then uppercase latin letters. If the given string contains any non-digit characters or digit characters that are too large for the given base then parseint will produce an error.&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; parseint&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"100"&lt;/span&gt;, 10&lt;span class="o"&gt;)&lt;/span&gt;
100

&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; parseint&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"FF"&lt;/span&gt;, 16&lt;span class="o"&gt;)&lt;/span&gt;
255

&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; parseint&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"-10"&lt;/span&gt;, 16&lt;span class="o"&gt;)&lt;/span&gt;
&lt;span class="nt"&gt;-16&lt;/span&gt;

&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; parseint&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"1011111011101111"&lt;/span&gt;, 2&lt;span class="o"&gt;)&lt;/span&gt;
48879

&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; parseint&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"aA"&lt;/span&gt;, 62&lt;span class="o"&gt;)&lt;/span&gt;
656

&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; parseint&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"12"&lt;/span&gt;, 2&lt;span class="o"&gt;)&lt;/span&gt;

Error: Invalid &lt;span class="k"&gt;function &lt;/span&gt;argument

Invalid value &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="s2"&gt;"number"&lt;/span&gt; parameter: cannot parse &lt;span class="s2"&gt;"12"&lt;/span&gt; as a base 2 integer.
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  🌟 String Functions 🌟
&lt;/h2&gt;

&lt;p&gt;String functions are used to manipulate strings. They can be used in resource configuration blocks, data source configuration blocks, and other parts of your Terraform code.&lt;/p&gt;

&lt;p&gt;Let’s see some examples and do some hands-on:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href="https://developer.hashicorp.com/terraform/language/functions/lower"&gt;lower()&lt;/a&gt;: lower converts all cased letters in the given string to lowercase.&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; lower&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"HELLO"&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
hello
&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; lower&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"АЛЛО!"&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
алло!
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href="https://developer.hashicorp.com/terraform/language/functions/upper"&gt;upper()&lt;/a&gt;: upper converts all cased letters in the given string to uppercase.&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; upper&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"hello"&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
HELLO
&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; upper&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"алло!"&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
АЛЛО!
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href="https://developer.hashicorp.com/terraform/language/functions/replace"&gt;replace()&lt;/a&gt;: replace searches a given string for another given substring, and replaces each occurrence with a given replacement string.&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;Syntax→ &lt;span class="sb"&gt;`&lt;/span&gt;replace&lt;span class="o"&gt;(&lt;/span&gt;string, substring, replacement&lt;span class="o"&gt;)&lt;/span&gt;&lt;span class="sb"&gt;`&lt;/span&gt;

E.g.
&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; replace&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"1 + 2 + 3"&lt;/span&gt;, &lt;span class="s2"&gt;"+"&lt;/span&gt;, &lt;span class="s2"&gt;"-"&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
1 - 2 - 3

&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; replace&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"hello world"&lt;/span&gt;, &lt;span class="s2"&gt;"/w.*d/"&lt;/span&gt;, &lt;span class="s2"&gt;"everybody"&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
hello everybody
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href="https://developer.hashicorp.com/terraform/language/functions/trim"&gt;trim()&lt;/a&gt;: trim removes the specified set of characters from the start and end of the given string.&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;Syntax→ &lt;span class="sb"&gt;`&lt;/span&gt;trim&lt;span class="o"&gt;(&lt;/span&gt;string, str_character_set&lt;span class="o"&gt;)&lt;/span&gt;&lt;span class="sb"&gt;`&lt;/span&gt;

E.g.
&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; trim&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"?!hello?!"&lt;/span&gt;, &lt;span class="s2"&gt;"!?"&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
&lt;span class="s2"&gt;"hello"&lt;/span&gt;

&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; trim&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"foobar"&lt;/span&gt;, &lt;span class="s2"&gt;"far"&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
&lt;span class="s2"&gt;"oob"&lt;/span&gt;

&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; trim&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"   hello! world.!  "&lt;/span&gt;, &lt;span class="s2"&gt;"! "&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
&lt;span class="s2"&gt;"hello! world."&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;There are many more terraform functions. You can find the details here: &lt;a href="https://developer.hashicorp.com/terraform/language/functions"&gt;https://developer.hashicorp.com/terraform/language/functions&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  🌟 Conclusion 🌟
&lt;/h2&gt;

&lt;p&gt;Terraform functions can help you write more efficient and dynamic infrastructure code. By using these functions, you can easily manipulate strings, perform mathematical calculations, and generate dynamic values. So give them a try and see how they can improve your Terraform workflows! 🔥&lt;/p&gt;

</description>
      <category>terraform</category>
      <category>tutorial</category>
      <category>devops</category>
      <category>cloud</category>
    </item>
    <item>
      <title>🔒💻 Master EKS IRSA and Terraform for Fine-Grained AWS Resource Access Control on Kubernetes.🚀</title>
      <dc:creator>Arun Singh Sisodiya</dc:creator>
      <pubDate>Wed, 22 Feb 2023 16:29:21 +0000</pubDate>
      <link>https://dev.to/arunsinghsisodiya/mastering-eks-irsa-with-terraform-a-comprehensive-guide-to-granular-aws-resource-access-control-on-kubernetes-4lc9</link>
      <guid>https://dev.to/arunsinghsisodiya/mastering-eks-irsa-with-terraform-a-comprehensive-guide-to-granular-aws-resource-access-control-on-kubernetes-4lc9</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;&lt;a href="https://docs.aws.amazon.com/eks/latest/userguide/iam-roles-for-service-accounts.html"&gt;IRSA (IAM Roles for Service Accounts)&lt;/a&gt; is a feature of EKS (Amazon Elastic Kubernetes Service) that allows you to grant Kubernetes pods and containers permissions to AWS resources using IAM roles. This allows you to use IAM policies to control access to your AWS resources from your Kubernetes applications.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Prerequisites
&lt;/h2&gt;

&lt;p&gt;An AWS account with permissions to create EKS clusters and IAM roles.&lt;br&gt;
The &lt;a href="https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html"&gt;AWS CLI&lt;/a&gt; and &lt;a href="https://kubernetes.io/docs/tasks/tools/#kubectl"&gt;kubectl&lt;/a&gt; are installed on your local machine.&lt;br&gt;
A running EKS cluster with at least one node group. You can use &lt;a href="https://eksctl.io/"&gt;eksctl&lt;/a&gt; or &lt;a href="https://registry.terraform.io/modules/terraform-aws-modules/eks/aws/latest"&gt;terraform eks module&lt;/a&gt; to spin up the EKS cluster&lt;/p&gt;

&lt;p&gt;Let us begin by describing the steps we must follow to implement IRSA on the EKS cluster.&lt;/p&gt;
&lt;h3&gt;
  
  
  Step 1: Create an IAM policy
&lt;/h3&gt;

&lt;p&gt;The first step is to create an IAM policy that grants the necessary permissions to your EKS pods. You can use the following example policy as a starting point:&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;resource&lt;/span&gt; &lt;span class="s2"&gt;"aws_iam_policy"&lt;/span&gt; &lt;span class="s2"&gt;"s3_access_policy"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;name_prefix&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"eks-s3-access-policy-"&lt;/span&gt;
  &lt;span class="nx"&gt;policy&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;jsonencode&lt;/span&gt;&lt;span class="err"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&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;"2012-10-17"&lt;/span&gt;
    &lt;span class="nx"&gt;Statement&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
      &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;Effect&lt;/span&gt;   &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"Allow"&lt;/span&gt;
        &lt;span class="nx"&gt;Action&lt;/span&gt;   &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
          &lt;span class="s2"&gt;"s3:Get*"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
          &lt;span class="s2"&gt;"s3:List*"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="p"&gt;]&lt;/span&gt;
        &lt;span class="nx"&gt;Resource&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"*"&lt;/span&gt;
      &lt;span class="p"&gt;},&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;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This policy allows your pods to read and list objects in all S3 buckets in your AWS account. Replace the resource ARN with the ARN of the specific resource you want to grant access to.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 2: Create an IAM role
&lt;/h3&gt;

&lt;p&gt;Next, create an IAM role that your EKS pods can assume to gain the permissions defined in the IAM policy. You can use the following Terraform code to create a new IAM role:&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;resource&lt;/span&gt; &lt;span class="s2"&gt;"aws_iam_role"&lt;/span&gt; &lt;span class="s2"&gt;"s3_access_role"&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;"eks-s3-access"&lt;/span&gt;
  &lt;span class="nx"&gt;assume_role_policy&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;jsonencode&lt;/span&gt;&lt;span class="err"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&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;"2012-10-17"&lt;/span&gt;
    &lt;span class="nx"&gt;Statement&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
      &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;Effect&lt;/span&gt;    &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"Allow"&lt;/span&gt;
        &lt;span class="nx"&gt;Principal&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
          &lt;span class="nx"&gt;Service&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"eks.amazonaws.com"&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="nx"&gt;Action&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"sts:AssumeRole"&lt;/span&gt;
      &lt;span class="p"&gt;},&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;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Replace &lt;code&gt;eks-s3-access&lt;/code&gt; with a name of your choice.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 3: Attach the IAM policy to the IAM role
&lt;/h3&gt;

&lt;p&gt;Once you've created the IAM role, attach the IAM policy you created in step 1 to the role using the following Terraform code:&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;resource&lt;/span&gt; &lt;span class="s2"&gt;"aws_iam_role_policy_attachment"&lt;/span&gt; &lt;span class="s2"&gt;"s3_access_policy_attachment"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;policy_arn&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;aws_iam_policy&lt;/span&gt;&lt;span class="err"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;s3_access_policy&lt;/span&gt;&lt;span class="err"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;arn&lt;/span&gt;
  &lt;span class="nx"&gt;role&lt;/span&gt;       &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;aws_iam_role&lt;/span&gt;&lt;span class="err"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;s3_access_role&lt;/span&gt;&lt;span class="err"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Replace &lt;code&gt;aws_iam_policy.s3_access_policy.arn&lt;/code&gt; with the ARN of the IAM policy you created in step 1, and &lt;code&gt;aws_iam_role.s3_access_role.name&lt;/code&gt; with the name of the IAM role you created in step 2.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 4: Create a Kubernetes service account
&lt;/h3&gt;

&lt;p&gt;Next, create a Kubernetes service account that you can associate with the IAM role you created in step 2. Use the following Terraform code to create a new service account:&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;resource&lt;/span&gt; &lt;span class="s2"&gt;"kubernetes_service_account"&lt;/span&gt; &lt;span class="s2"&gt;"s3_access_sa"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;metadata&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;"s3-access-sa"&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;blockquote&gt;
&lt;p&gt;Note: If you want to create Kubernetes service account using terraform, you must use &lt;a href="https://registry.terraform.io/providers/hashicorp/kubernetes/latest/docs"&gt;Kubernetes Provider&lt;/a&gt; by terraform.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  Step 5: Annotate the service account with the IAM role ARN
&lt;/h3&gt;

&lt;p&gt;To associate the Kubernetes service account with the IAM role you created in step 2, annotate the service account with the ARN of the role using the following Terraform code:&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;resource&lt;/span&gt; &lt;span class="s2"&gt;"kubernetes_service_account_annotation"&lt;/span&gt; &lt;span class="s2"&gt;"s3_access_sa_annotation"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;metadata&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="nx"&gt;kubernetes_service_account&lt;/span&gt;&lt;span class="err"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;s3_access_sa&lt;/span&gt;&lt;span class="err"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;metadata&lt;/span&gt;&lt;span class="err"&gt;.&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="err"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;
    &lt;span class="nx"&gt;namespace&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"default"&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="nx"&gt;annotations&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="s2"&gt;"eks.amazonaws.com/role-arn"&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;aws_iam_role&lt;/span&gt;&lt;span class="err"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;s3_access_role&lt;/span&gt;&lt;span class="err"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;arn&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;Replace &lt;code&gt;aws_iam_role.s3_access_role.arn&lt;/code&gt; with the ARN of the IAM role you created in step 2, and &lt;code&gt;kubernetes_service_account.s3_access_sa.metadata.0.name&lt;/code&gt; with the name of the Kubernetes service account you created in step 4.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 6: Deploy a sample pod
&lt;/h3&gt;

&lt;p&gt;Finally, deploy a sample pod that uses the IAM role you created in step 2 to access an AWS resource. Use the following Terraform code to deploy a sample pod:&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;resource&lt;/span&gt; &lt;span class="s2"&gt;"kubernetes_manifest"&lt;/span&gt; &lt;span class="s2"&gt;"sample_pod"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;manifest&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;jsonencode&lt;/span&gt;&lt;span class="err"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;apiVersion&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"v1"&lt;/span&gt;
    &lt;span class="nx"&gt;kind&lt;/span&gt;       &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"Pod"&lt;/span&gt;
    &lt;span class="nx"&gt;metadata&lt;/span&gt; &lt;span class="p"&gt;=&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;"sample-pod"&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="nx"&gt;spec&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nx"&gt;containers&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&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;"sample-container"&lt;/span&gt;
          &lt;span class="nx"&gt;image&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"nginx"&lt;/span&gt;
          &lt;span class="nx"&gt;volumeMounts&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&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;"aws-credentials"&lt;/span&gt;
              &lt;span class="nx"&gt;mountPath&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"/var/run/secrets/aws"&lt;/span&gt;
            &lt;span class="p"&gt;},&lt;/span&gt;
          &lt;span class="p"&gt;]&lt;/span&gt;
          &lt;span class="nx"&gt;env&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&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;"AWS_REGION"&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;"us-west-2"&lt;/span&gt;
            &lt;span class="p"&gt;},&lt;/span&gt;
          &lt;span class="p"&gt;]&lt;/span&gt;
        &lt;span class="p"&gt;},&lt;/span&gt;
      &lt;span class="p"&gt;]&lt;/span&gt;
      &lt;span class="nx"&gt;volumes&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&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;"aws-credentials"&lt;/span&gt;
          &lt;span class="nx"&gt;projected&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="nx"&gt;sources&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
              &lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="nx"&gt;serviceAccountToken&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                  &lt;span class="nx"&gt;path&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"aws-credentials"&lt;/span&gt;
                  &lt;span class="nx"&gt;expirationSeconds&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;86400&lt;/span&gt;
                &lt;span class="p"&gt;}&lt;/span&gt;
              &lt;span class="p"&gt;},&lt;/span&gt;
            &lt;span class="p"&gt;]&lt;/span&gt;
          &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="p"&gt;},&lt;/span&gt;
      &lt;span class="p"&gt;]&lt;/span&gt;
      &lt;span class="nx"&gt;serviceAccountName&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;kubernetes_service_account&lt;/span&gt;&lt;span class="err"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;s3_access_sa&lt;/span&gt;&lt;span class="err"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;metadata&lt;/span&gt;&lt;span class="err"&gt;.&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="err"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&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;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This deploys a sample Nginx container that mounts the AWS credentials from the Kubernetes service account and sets the AWS region environment variable. Replace &lt;code&gt;kubernetes_service_account.s3_access_sa.metadata.0.name&lt;/code&gt; with the name of the Kubernetes service account you created in step 4.&lt;br&gt;
That's it! Once you apply these Terraform configurations, you should have a Kubernetes pod that has access to the AWS resource specified in the IAM policy you created in step 1, using the IAM role you created in step 2.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;In conclusion, EKS IRSA is a powerful feature that allows you to achieve fine-grained access control to AWS resources on Kubernetes clusters. With Terraform, you can easily automate the process of creating and managing IAM roles, Kubernetes service accounts, and their association, allowing you to streamline your infrastructure management workflow. By following this step-by-step guide, you can implement EKS IRSA with Terraform and take advantage of its benefits to achieve greater security and efficiency in your Kubernetes environment.&lt;/p&gt;

</description>
      <category>tutorial</category>
      <category>devops</category>
      <category>aws</category>
      <category>eks</category>
    </item>
  </channel>
</rss>
