<?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>Forem: Abhishek Anand Amralkar</title>
    <description>The latest articles on Forem by Abhishek Anand Amralkar (@abhishekamralkar).</description>
    <link>https://forem.com/abhishekamralkar</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%2F8837%2F5a3a4be2-a453-4acb-93ee-6d8e010a962e.png</url>
      <title>Forem: Abhishek Anand Amralkar</title>
      <link>https://forem.com/abhishekamralkar</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/abhishekamralkar"/>
    <language>en</language>
    <item>
      <title>My Zig with Ghostty</title>
      <dc:creator>Abhishek Anand Amralkar</dc:creator>
      <pubDate>Thu, 09 Jan 2025 16:18:45 +0000</pubDate>
      <link>https://forem.com/abhishekamralkar/my-zig-with-ghostty-4kmk</link>
      <guid>https://forem.com/abhishekamralkar/my-zig-with-ghostty-4kmk</guid>
      <description>&lt;p&gt;Ghostty is a fast, feature-rich, and cross-platform terminal emulator that uses platform-native UI and GPU acceleration. Ghostty is written in Zig.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Install:-&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;To install in MacOS&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# update formulae
brew update

# stable
brew install --cask ghostty

# tip
brew install --cask ghostty@tip
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://medium.com/r/?url=https%3A%2F%2Fghostty.org%2Fdocs" rel="noopener noreferrer"&gt;Ghostty Docs&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Actions:-&lt;/p&gt;

&lt;p&gt;Ghostty supports below actions&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Available actions:

  +version
  +help
  +list-fonts
  +list-keybinds
  +list-themes
  +list-colors
  +list-actions
  +show-config
  +validate-config
  +crash-report
  +show-face
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;see all available themes&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;code&gt;ghostty +list-themes&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Flrzrvlnokapty49wxwbc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Flrzrvlnokapty49wxwbc.png" alt="Image description" width="800" height="488"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;see all keybindings&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;code&gt;ghostty +list-keybinds&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;super + alt   + shift + j               write_scrollback_file:open
super + alt   + shift + w               close_all_windows
super + alt   + i                       inspector:toggle
super + alt   + right                   goto_split:right
super + alt   + down                    goto_split:bottom
super + alt   + left                    goto_split:left
super + alt   + up                      goto_split:top
super + ctrl  + equal                   equalize_splits
super + ctrl  + down                    resize_split:down,10
super + ctrl  + left                    resize_split:left,10
super + ctrl  + up                      resize_split:up,10
super + ctrl  + f                       toggle_fullscreen
super + ctrl  + right                   resize_split:right,10
super + shift + down                    jump_to_prompt:1
super + shift + w                       close_window
super + shift + left_bracket            previous_tab
super + shift + right_bracket           next_tab
super + shift + up                      jump_to_prompt:-1
super + shift + comma                   reload_config
super + shift + enter                   toggle_split_zoom
super + shift + j                       write_scrollback_file:paste
super + shift + d                       new_split:down
ctrl  + shift + left_bracket            previous_tab
ctrl  + shift + period                  move_tab:1
ctrl  + shift + comma                   move_tab:-1
ctrl  + shift + right_bracket           next_tab
ctrl  + shift + tab                     previous_tab
super + page_up                         scroll_page_up
super + physical:four                   goto_tab:4
super + backspace                       esc:
super + w                               close_surface
super + physical:eight                  goto_tab:8
super + down                            jump_to_prompt:1
super + enter                           toggle_fullscreen
super + t                               new_tab
super + c                               copy_to_clipboard
super + physical:one                    goto_tab:1
super + equal                           increase_font_size:1
super + physical:three                  goto_tab:3
super + right                           text:\x05
super + d                               new_split:right
super + plus                            increase_font_size:1
super + q                               quit
super + home                            scroll_to_top
super + left                            text:\x01
super + comma                           open_config
super + minus                           decrease_font_size:1
super + a                               select_all
super + n                               new_window
super + page_down                       scroll_page_down
super + left_bracket                    goto_split:previous
super + physical:nine                   last_tab
super + right_bracket                   goto_split:next
super + end                             scroll_to_bottom
super + zero                            reset_font_size
super + physical:five                   goto_tab:5
super + physical:seven                  goto_tab:7
super + up                              jump_to_prompt:-1
super + k                               clear_screen
super + s                               toggle_quick_terminal
super + physical:two                    goto_tab:2
super + physical:six                    goto_tab:6
super + v                               paste_from_clipboard
alt   + left                            esc:b
alt   + right                           esc:f
ctrl  + v                               new_split:right
ctrl  + h                               new_split:down
ctrl  + tab                             next_tab
ctrl  + z                               close_surface
shift + up                              adjust_selection:up
shift + left                            adjust_selection:left
shift + page_up                         adjust_selection:page_up
shift + end                             adjust_selection:end
shift + right                           adjust_selection:right
shift + page_down                       adjust_selection:page_down
shift + down                            adjust_selection:down
shift + home                            adjust_selection:home
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For me migration from iTerm to Ghostty is super easy. I'm looking forward to using Ghostty as my default shell moving forward.&lt;/p&gt;

</description>
      <category>ghostty</category>
      <category>terminal</category>
      <category>linux</category>
      <category>productivity</category>
    </item>
    <item>
      <title>Oh, My Xmonad!</title>
      <dc:creator>Abhishek Anand Amralkar</dc:creator>
      <pubDate>Sun, 23 Aug 2020 15:56:44 +0000</pubDate>
      <link>https://forem.com/abhishekamralkar/oh-my-xmonad-119d</link>
      <guid>https://forem.com/abhishekamralkar/oh-my-xmonad-119d</guid>
      <description>&lt;p&gt;Well, I use Linux(On Debian Buster currently) on almost all of my personal laptops + desktop, and when you use Linux you get N numbers of options for almost everything to plug and play and use it.&lt;/p&gt;

&lt;p&gt;In Linux, you have various GUIs available and my personal favorite is Gnome3 because of its clean user interface and the tweaks it allows for the look and feels. &lt;/p&gt;

&lt;h2&gt;
  
  
  The problems with GUIs
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;How to manage the various windows. I ended up buying an extra monitor.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Space issues like a title bar and subtitle bar etc so in the end you end up with a very small space (actually not that small) for your actual work.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Sometime it feels sluggish and needs a lot more resources than you want to spend on GUIs stuff.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The unwanted stuff you get along with the GUIs which you will never be going to use.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  So What's the Fix?
&lt;/h2&gt;

&lt;p&gt;Enter the Tiling Window Manager. There are many options available but my favorite is Xmonad. &lt;/p&gt;

&lt;p&gt;Xmonad a minimal tiling window manager written in Haskell and DIY tiling manager which means it comes with no batteries you need to manage your Xmonad via a config file&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;~/.xmonad/xmonad.hs
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Xmonad is very light and easy to use (actually not that easy) but man once you understand the terminologies you will love it and again you will learn little bit Haskell isn't it cool?&lt;/p&gt;

&lt;p&gt;Another cool thing about the tiling window manager is you move towards a keyboard-driven approach and that means a less distraction at least for me and super productive.&lt;/p&gt;

&lt;h2&gt;
  
  
  Configurations
&lt;/h2&gt;

&lt;p&gt;Let's walk through the config file snippet for the Xmonad&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight haskell"&gt;&lt;code&gt;&lt;span class="kr"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;XMonad&lt;/span&gt;
&lt;span class="kr"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;System.Exit&lt;/span&gt;

&lt;span class="kr"&gt;import&lt;/span&gt; &lt;span class="k"&gt;qualified&lt;/span&gt; &lt;span class="nn"&gt;XMonad.StackSet&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;W&lt;/span&gt;
&lt;span class="kr"&gt;import&lt;/span&gt; &lt;span class="k"&gt;qualified&lt;/span&gt; &lt;span class="nn"&gt;Data.Map&lt;/span&gt;        &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;M&lt;/span&gt;

&lt;span class="n"&gt;myTerminal&lt;/span&gt;      &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"terminator"&lt;/span&gt;

&lt;span class="n"&gt;myBorderWidth&lt;/span&gt;   &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;

&lt;span class="n"&gt;myModMask&lt;/span&gt;       &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;mod1Mask&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;In the above config&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;I have defined my default &lt;code&gt;terminal&lt;/code&gt; and I love &lt;a href="https://terminator-gtk3.readthedocs.io/en/latest/#"&gt;Terminator&lt;/a&gt; .&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;I defined &lt;code&gt;myModmask&lt;/code&gt; which means my &lt;code&gt;modkey&lt;/code&gt; which I bind to &lt;code&gt;mod1Mask&lt;/code&gt; which means the left &lt;code&gt;Alt&lt;/code&gt; key on QWERTY keyboard.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Key Bindings
&lt;/h2&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight haskell"&gt;&lt;code&gt;&lt;span class="n"&gt;myKeys&lt;/span&gt; &lt;span class="n"&gt;conf&lt;/span&gt;&lt;span class="o"&gt;@&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;XConfig&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="kt"&gt;XMonad&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;modMask&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;modm&lt;/span&gt;&lt;span class="p"&gt;})&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kt"&gt;M&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;fromList&lt;/span&gt; &lt;span class="o"&gt;$&lt;/span&gt;

    &lt;span class="p"&gt;[&lt;/span&gt; &lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="n"&gt;modm&lt;/span&gt; &lt;span class="o"&gt;.|.&lt;/span&gt; &lt;span class="n"&gt;shiftMask&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;xK_Return&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="n"&gt;spawn&lt;/span&gt; &lt;span class="o"&gt;$&lt;/span&gt; &lt;span class="kt"&gt;XMonad&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;terminal&lt;/span&gt; &lt;span class="n"&gt;conf&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="n"&gt;modm&lt;/span&gt; &lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;xK_Print&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="n"&gt;spawn&lt;/span&gt; &lt;span class="s"&gt;"scrot screen_%Y-%m-%d-%H-%M-%S.png -d 1"&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="n"&gt;modm&lt;/span&gt; &lt;span class="o"&gt;.|.&lt;/span&gt; &lt;span class="n"&gt;controlMask&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;xK_Print&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="n"&gt;spawn&lt;/span&gt; &lt;span class="s"&gt;"scrot window_%Y-%m-%d-%H-%M-%S.png -d 1-u"&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="n"&gt;modm&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;  &lt;span class="n"&gt;xK_p&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="n"&gt;spawn&lt;/span&gt; &lt;span class="s"&gt;"exe=`dmenu_path | dmenu` &amp;amp;&amp;amp; eval &lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s"&gt;exec $exe&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s"&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="n"&gt;modm&lt;/span&gt; &lt;span class="o"&gt;.|.&lt;/span&gt; &lt;span class="n"&gt;shiftMask&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;xK_p&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="n"&gt;spawn&lt;/span&gt; &lt;span class="s"&gt;"gmrun"&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="n"&gt;modm&lt;/span&gt; &lt;span class="o"&gt;.|.&lt;/span&gt; &lt;span class="n"&gt;shiftMask&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;xK_c&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="n"&gt;kill&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="n"&gt;modm&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;xK_h&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="n"&gt;sendMessage&lt;/span&gt; &lt;span class="kt"&gt;Shrink&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="n"&gt;modm&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;xK_l&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="n"&gt;sendMessage&lt;/span&gt; &lt;span class="kt"&gt;Expand&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="n"&gt;modm&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;xK_t&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="n"&gt;withFocused&lt;/span&gt; &lt;span class="o"&gt;$&lt;/span&gt; &lt;span class="n"&gt;windows&lt;/span&gt; &lt;span class="o"&gt;.&lt;/span&gt; &lt;span class="kt"&gt;W&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;sink&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;The above is just a snippet from my Xmonad config file. Let's go through the keywords we are seeing in the above snippet.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight haskell"&gt;&lt;code&gt;&lt;span class="kt"&gt;XMonad&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;modMask&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;modm&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;For my meta key or mod key, I will be using modm. Later part we can define our key bindings. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;To launch a terminal
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight haskell"&gt;&lt;code&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="n"&gt;modm&lt;/span&gt; &lt;span class="o"&gt;.|.&lt;/span&gt; &lt;span class="n"&gt;shiftMask&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;xK_Return&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="n"&gt;spawn&lt;/span&gt; &lt;span class="o"&gt;$&lt;/span&gt; &lt;span class="kt"&gt;XMonad&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;terminal&lt;/span&gt; &lt;span class="n"&gt;conf&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;The above code snippet will bind the &lt;code&gt;meta key&lt;/code&gt; or &lt;code&gt;mod key&lt;/code&gt; in my case its &lt;code&gt;Alt&lt;/code&gt; key and &lt;code&gt;shiftMask = Shift Key&lt;/code&gt; plus &lt;code&gt;Enter = xK_Return&lt;/code&gt; to &lt;code&gt;spawn&lt;/code&gt; my terminal which is &lt;code&gt;Terminator&lt;/code&gt;.&lt;/p&gt;

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

&lt;div class="highlight"&gt;&lt;pre class="highlight haskell"&gt;&lt;code&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="n"&gt;modm&lt;/span&gt; &lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;xK_Print&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="n"&gt;spawn&lt;/span&gt; &lt;span class="s"&gt;"scrot screen_%Y-%m-%d-%H-%M-%S.png -d 1"&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="n"&gt;modm&lt;/span&gt; &lt;span class="o"&gt;.|.&lt;/span&gt; &lt;span class="n"&gt;controlMask&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;xK_Print&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="n"&gt;spawn&lt;/span&gt; &lt;span class="s"&gt;"scrot window_%Y-%m-%d-%H-%M-%S.png -d 1-u"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;To take a screenshot for full screen or for the focused window bind the key &lt;code&gt;modm and ControlKey + PrintScreen Key&lt;/code&gt; and it will spawn a daemon name &lt;a href="https://github.com/dreamer/scrot"&gt;scrot&lt;/a&gt;. On other note &lt;code&gt;scrot&lt;/code&gt; stands for &lt;code&gt;SCReenshoT&lt;/code&gt;.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Open a Menu or DMenu
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight haskell"&gt;&lt;code&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="n"&gt;modm&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;  &lt;span class="n"&gt;xK_p&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="n"&gt;spawn&lt;/span&gt; &lt;span class="s"&gt;"exe=`dmenu_path | dmenu` &amp;amp;&amp;amp; eval &lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s"&gt;exec $exe&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;The above command will open Dmenu and we can just type the program name we want to access like &lt;code&gt;nautilus&lt;/code&gt;, &lt;code&gt;brave&lt;/code&gt;, &lt;code&gt;emacs&lt;/code&gt; etc.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;To kill a focus window
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight haskell"&gt;&lt;code&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="n"&gt;modm&lt;/span&gt; &lt;span class="o"&gt;.|.&lt;/span&gt; &lt;span class="n"&gt;shiftMask&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;xK_c&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="n"&gt;kill&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;The above command which is &lt;code&gt;alt and shift + c&lt;/code&gt; will kill the focused window.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;To shrink the window
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight haskell"&gt;&lt;code&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="n"&gt;modm&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;xK_h&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="n"&gt;sendMessage&lt;/span&gt; &lt;span class="kt"&gt;Shrink&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;The above command which is &lt;code&gt;alt + h&lt;/code&gt; will shrink the focused window.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;To expand the window
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight haskell"&gt;&lt;code&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="n"&gt;modm&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;xK_l&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="n"&gt;sendMessage&lt;/span&gt; &lt;span class="kt"&gt;Expand&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;The above command which is &lt;code&gt;alt + l&lt;/code&gt; will expand the focused window.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;To move focus to next window
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight haskell"&gt;&lt;code&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="n"&gt;modm&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;xK_j&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="n"&gt;sendMessage&lt;/span&gt; &lt;span class="kt"&gt;Expand&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;To move focus to the previous window
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight haskell"&gt;&lt;code&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="n"&gt;modm&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;xK_j&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="n"&gt;sendMessage&lt;/span&gt; &lt;span class="kt"&gt;Expand&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;To switch between tiling mode
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight haskell"&gt;&lt;code&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="n"&gt;modm&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;xK_space&lt;/span&gt; &lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="n"&gt;sendMessage&lt;/span&gt; &lt;span class="kt"&gt;NextLayout&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;All above key bindings are a few drops out of the ocean. Please refer to the official documentation for more config settings.&lt;/p&gt;

&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Tiling window manager is really good when you need a minimal GUI and mostly your work is Keyboard driven.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Tiling window manager needs some learning actually it really needs to rewire your mind in order to operate.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Tiling window manager is lightweight and can work on low-end machines, old machines.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Happy Tiling!!&lt;/p&gt;

</description>
      <category>xmonad</category>
      <category>tiling</category>
      <category>linux</category>
      <category>newbie</category>
    </item>
    <item>
      <title>Collection Functions</title>
      <dc:creator>Abhishek Anand Amralkar</dc:creator>
      <pubDate>Sat, 01 Aug 2020 16:58:35 +0000</pubDate>
      <link>https://forem.com/abhishekamralkar/collection-functions-3g9k</link>
      <guid>https://forem.com/abhishekamralkar/collection-functions-3g9k</guid>
      <description>&lt;h2&gt;
  
  
  concat
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;concat&lt;/code&gt; functions take 2 lists as a input and returns a new list&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight hcl"&gt;&lt;code&gt;&lt;span class="err"&gt;``&lt;/span&gt;

&lt;span class="c1"&gt;## element&lt;/span&gt;

&lt;span class="err"&gt;`&lt;/span&gt;&lt;span class="nx"&gt;element&lt;/span&gt;&lt;span class="err"&gt;`&lt;/span&gt; &lt;span class="nx"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;in&lt;/span&gt; &lt;span class="nx"&gt;TF&lt;/span&gt; &lt;span class="nx"&gt;is&lt;/span&gt; &lt;span class="nx"&gt;selects&lt;/span&gt; &lt;span class="nx"&gt;single&lt;/span&gt; &lt;span class="nx"&gt;element&lt;/span&gt; &lt;span class="nx"&gt;from&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="nx"&gt;list&lt;/span&gt;&lt;span class="err"&gt;.&lt;/span&gt; 

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;&lt;br&gt;
hcl&lt;br&gt;
 element(concat(aws_vpc.generic.*.id, [""]), 0)&lt;/p&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;


In above code, we have used `concat` and `element` both with using `element` we are just selecting the value at the 0th index in the list.

## flatten

`flatten` function in 
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

</description>
      <category>aws</category>
      <category>terraform</category>
      <category>cloud</category>
      <category>codenewbie</category>
    </item>
    <item>
      <title>Collection Functions</title>
      <dc:creator>Abhishek Anand Amralkar</dc:creator>
      <pubDate>Fri, 31 Jul 2020 09:26:36 +0000</pubDate>
      <link>https://forem.com/abhishekamralkar/collection-functions-42ca</link>
      <guid>https://forem.com/abhishekamralkar/collection-functions-42ca</guid>
      <description>&lt;p&gt;The next in line is TF Collection Functions and they are very useful in day to day use for writing TF code.&lt;/p&gt;

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

&lt;p&gt;&lt;code&gt;concat&lt;/code&gt; functions take 2 lists as an input and returns a new list.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight hcl"&gt;&lt;code&gt;&lt;span class="nx"&gt;concat&lt;/span&gt;&lt;span class="err"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;aws_vpc_endpoint&lt;/span&gt;&lt;span class="err"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;sts&lt;/span&gt;&lt;span class="err"&gt;.*.&lt;/span&gt;&lt;span class="nx"&gt;id&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="p"&gt;]&lt;/span&gt;&lt;span class="err"&gt;)&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



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

&lt;p&gt;&lt;code&gt;contains&lt;/code&gt; functions checks for the element in the given list or set and returns a boolean.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight hcl"&gt;&lt;code&gt;&lt;span class="nx"&gt;contains&lt;/span&gt;&lt;span class="err"&gt;(&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"a"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"b"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"c"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="err"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"a"&lt;/span&gt;&lt;span class="err"&gt;)&lt;/span&gt;
&lt;span class="kc"&gt;true&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



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

&lt;p&gt;&lt;code&gt;element&lt;/code&gt; functions return the item from the list given the index&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight hcl"&gt;&lt;code&gt;
&lt;span class="nx"&gt;element&lt;/span&gt;&lt;span class="err"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;var&lt;/span&gt;&lt;span class="err"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;azs&lt;/span&gt;&lt;span class="err"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;count&lt;/span&gt;&lt;span class="err"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;index&lt;/span&gt;&lt;span class="err"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;The above code will return an &lt;code&gt;availability zone&lt;/code&gt; at index start with &lt;code&gt;count.index&lt;/code&gt; usually start from 0 and so on depending upon the count you set.&lt;/p&gt;

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

&lt;p&gt;&lt;code&gt;flatten&lt;/code&gt; takes a list and replaces any elements that are lists with a flattened sequence of the list contents.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight hcl"&gt;&lt;code&gt;&lt;span class="nx"&gt;flatten&lt;/span&gt;&lt;span class="err"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;module&lt;/span&gt;&lt;span class="err"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;nginx&lt;/span&gt;&lt;span class="err"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;vpc_security_group_ids&lt;/span&gt;&lt;span class="err"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;With the above code, we can flatten the list of lists.&lt;/p&gt;

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

&lt;p&gt;&lt;code&gt;map&lt;/code&gt; takes an even number of arguments and returns a map whose elements are constructed from consecutive pairs of arguments.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight hcl"&gt;&lt;code&gt;&lt;span class="nx"&gt;map&lt;/span&gt;&lt;span class="err"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'BusinessUnit'&lt;/span&gt;&lt;span class="err"&gt;,&lt;/span&gt;&lt;span class="s1"&gt;'XYZ'&lt;/span&gt;&lt;span class="err"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



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

&lt;p&gt;&lt;code&gt;merge&lt;/code&gt; takes an arbitrary number of maps and returns a single map that contains a merged set of elements from all of the maps.&lt;/p&gt;

&lt;p&gt;If more than one given map defines the same key then the one that is later in the argument sequence takes precedence.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight hcl"&gt;&lt;code&gt;&lt;span class="nx"&gt;tags&lt;/span&gt; &lt;span class="err"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;merge&lt;/span&gt;&lt;span class="err"&gt;(&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="s2"&gt;"Name"&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;format&lt;/span&gt;&lt;span class="err"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"%s-%03d-%s"&lt;/span&gt;&lt;span class="err"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;var&lt;/span&gt;&lt;span class="err"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;namespace&lt;/span&gt;&lt;span class="err"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;count&lt;/span&gt;&lt;span class="err"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;index&lt;/span&gt;&lt;span class="err"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;var&lt;/span&gt;&lt;span class="err"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;environment&lt;/span&gt;&lt;span class="err"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="err"&gt;,&lt;/span&gt;
    &lt;span class="nx"&gt;var&lt;/span&gt;&lt;span class="err"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;tags&lt;/span&gt;&lt;span class="err"&gt;,&lt;/span&gt;
  &lt;span class="err"&gt;)&lt;/span&gt;

  &lt;span class="nx"&gt;volume_tags&lt;/span&gt; &lt;span class="err"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;merge&lt;/span&gt;&lt;span class="err"&gt;(&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="s2"&gt;"Name"&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;format&lt;/span&gt;&lt;span class="err"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"%s-%03d-%s"&lt;/span&gt;&lt;span class="err"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;var&lt;/span&gt;&lt;span class="err"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;namespace&lt;/span&gt;&lt;span class="err"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;count&lt;/span&gt;&lt;span class="err"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;index&lt;/span&gt;&lt;span class="err"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;var&lt;/span&gt;&lt;span class="err"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;environment&lt;/span&gt;&lt;span class="err"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="err"&gt;,&lt;/span&gt;
    &lt;span class="nx"&gt;var&lt;/span&gt;&lt;span class="err"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;volume_tags&lt;/span&gt;&lt;span class="err"&gt;,&lt;/span&gt;
  &lt;span class="err"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;In the above code, we are merging all maps and passing them as a single map. &lt;/p&gt;

&lt;p&gt;The above listed functions are few of the many Collection Functions Terraform have and are opiniaoted depending on my usage.&lt;/p&gt;

</description>
      <category>aws</category>
      <category>terraform</category>
      <category>cloud</category>
      <category>codenewbie</category>
    </item>
    <item>
      <title>String Functions</title>
      <dc:creator>Abhishek Anand Amralkar</dc:creator>
      <pubDate>Wed, 29 Jul 2020 17:59:37 +0000</pubDate>
      <link>https://forem.com/abhishekamralkar/string-functions-5fek</link>
      <guid>https://forem.com/abhishekamralkar/string-functions-5fek</guid>
      <description>&lt;h2&gt;
  
  
  format
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;format&lt;/code&gt; function produces a string by formatting a number of other values according to a specification string. Let's see an example&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Note:- From now on we will refer Terraform as TF&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;We can use &lt;code&gt;format&lt;/code&gt; function as a &lt;code&gt;printf&lt;/code&gt; function in many other languages. I heavily used them in tagging my resources&lt;br&gt;
in cloud.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight hcl"&gt;&lt;code&gt;  &lt;span class="nx"&gt;tags&lt;/span&gt; &lt;span class="err"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;merge&lt;/span&gt;&lt;span class="err"&gt;(&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="s2"&gt;"Name"&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;format&lt;/span&gt;&lt;span class="err"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"%s-%03d-%s"&lt;/span&gt;&lt;span class="err"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;var&lt;/span&gt;&lt;span class="err"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;namespace&lt;/span&gt;&lt;span class="err"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;count&lt;/span&gt;&lt;span class="err"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;index&lt;/span&gt;&lt;span class="err"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;var&lt;/span&gt;&lt;span class="err"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;environment&lt;/span&gt;&lt;span class="err"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="err"&gt;,&lt;/span&gt;
    &lt;span class="nx"&gt;var&lt;/span&gt;&lt;span class="err"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;tags&lt;/span&gt;&lt;span class="err"&gt;,&lt;/span&gt;
  &lt;span class="err"&gt;)&lt;/span&gt;

&lt;span class="nx"&gt;or&lt;/span&gt;

&lt;span class="nx"&gt;name&lt;/span&gt; &lt;span class="err"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;format&lt;/span&gt;&lt;span class="err"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"%s-%s-%s"&lt;/span&gt;&lt;span class="err"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"elastic"&lt;/span&gt;&lt;span class="err"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;var&lt;/span&gt;&lt;span class="err"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;environment&lt;/span&gt;&lt;span class="err"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"SG"&lt;/span&gt;&lt;span class="err"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;consider variables are defined as below&lt;br&gt;
&lt;/p&gt;

&lt;div class="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;"environment"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;description&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"Name of the Environment"&lt;/span&gt;
  &lt;span class="nx"&gt;type&lt;/span&gt;        &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;string&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;"Stage"&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;


&lt;span class="nx"&gt;variable&lt;/span&gt; &lt;span class="s2"&gt;"namespace"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;description&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"Name to be used with identifier"&lt;/span&gt;
  &lt;span class="nx"&gt;type&lt;/span&gt;        &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;string&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;"elastic"&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;The above first code will generate the tag &lt;code&gt;elastic-000-Stage&lt;/code&gt; and with &lt;code&gt;count.index&lt;/code&gt; it will keep incrementing the &lt;code&gt;%d&lt;/code&gt; depending upon the number defined and the second code block will generate &lt;code&gt;elastic-Stage-SG&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  join
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;join&lt;/code&gt; takes 2 input the separator and the list of string and concatenate them and returns the strings&lt;/p&gt;

&lt;p&gt;For example, see below code block&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight hcl"&gt;&lt;code&gt;
&lt;span class="nx"&gt;role&lt;/span&gt;  &lt;span class="err"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;join&lt;/span&gt;&lt;span class="err"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;""&lt;/span&gt;&lt;span class="err"&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;elastic_iam_role&lt;/span&gt;&lt;span class="err"&gt;.*.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="err"&gt;)&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;The above code will generate the IAM role name as a string separated by blank space.&lt;/p&gt;

&lt;h2&gt;
  
  
  split
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;split&lt;/code&gt; function produces the list when given input as a string lets see example below&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight hcl"&gt;&lt;code&gt;
&lt;span class="nx"&gt;availability_zone&lt;/span&gt; &lt;span class="err"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;element&lt;/span&gt;&lt;span class="err"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;split&lt;/span&gt;&lt;span class="err"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;","&lt;/span&gt;&lt;span class="err"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;var&lt;/span&gt;&lt;span class="err"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;azs&lt;/span&gt;&lt;span class="err"&gt;),&lt;/span&gt; &lt;span class="nx"&gt;count&lt;/span&gt;&lt;span class="err"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;index&lt;/span&gt;&lt;span class="err"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;with the above code, we will get a list of all the availability zones (azs).&lt;/p&gt;

&lt;h2&gt;
  
  
  replace
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;replace&lt;/code&gt; function in TF is like &lt;code&gt;sed&lt;/code&gt; in Linux it searches for the given string and replaces it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight hcl"&gt;&lt;code&gt;&lt;span class="nx"&gt;is_t_instance_type&lt;/span&gt; &lt;span class="err"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;replace&lt;/span&gt;&lt;span class="err"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;var&lt;/span&gt;&lt;span class="err"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;instance_type&lt;/span&gt;&lt;span class="err"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"/^t[23]{1}&lt;/span&gt;&lt;span class="err"&gt;\\&lt;/span&gt;&lt;span class="s2"&gt;..*$/"&lt;/span&gt;&lt;span class="err"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"1"&lt;/span&gt;&lt;span class="err"&gt;)&lt;/span&gt; &lt;span class="err"&gt;==&lt;/span&gt; &lt;span class="s2"&gt;"1"&lt;/span&gt; &lt;span class="err"&gt;?&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt; &lt;span class="err"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Your substring wrapped in &lt;code&gt;//&lt;/code&gt; like &lt;code&gt;/foo/&lt;/code&gt; will be considered as a &lt;code&gt;regular expression&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;In above example the value of &lt;code&gt;var.instance_type&lt;/code&gt; will be replace  by the regular expression which will match &lt;code&gt;t2&lt;/code&gt; and &lt;code&gt;t3&lt;/code&gt; instance families in &lt;code&gt;aws&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Above functions are just very few out of mmany String Functions by Terraform.&lt;/p&gt;

</description>
      <category>terraform</category>
      <category>aws</category>
      <category>codenewbie</category>
      <category>cloud</category>
    </item>
    <item>
      <title>Terraform Functions</title>
      <dc:creator>Abhishek Anand Amralkar</dc:creator>
      <pubDate>Wed, 29 Jul 2020 17:59:33 +0000</pubDate>
      <link>https://forem.com/abhishekamralkar/terraform-functions-317f</link>
      <guid>https://forem.com/abhishekamralkar/terraform-functions-317f</guid>
      <description>&lt;p&gt;I am using Terraform since I was a kid, just kidding. I first used Terraform when Terraform was at version 0.6 and since then I never looked back for any other cloud provisioning tool.&lt;/p&gt;

&lt;p&gt;In this blog series, we will not discuss the basics of the terraform but rather we will try to see the Functions in Terraform, though we will not discuss all functions a few functions which are really helpful and widely used at least I have used them widely in my Terraform Code.&lt;/p&gt;

&lt;p&gt;Below is the link for all the supported &lt;a href="https://www.terraform.io/docs/configuration/functions.html"&gt;Functions in Terraform&lt;/a&gt;.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;String&lt;/li&gt;
&lt;li&gt;Collection&lt;/li&gt;
&lt;li&gt;Filesystem&lt;/li&gt;
&lt;li&gt;Date and Time&lt;/li&gt;
&lt;li&gt;Type Conversion&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>terraform</category>
      <category>aws</category>
      <category>infrastructureasacode</category>
      <category>cloud</category>
    </item>
    <item>
      <title>Getting started with CDK for Terraform </title>
      <dc:creator>Abhishek Anand Amralkar</dc:creator>
      <pubDate>Thu, 23 Jul 2020 16:13:16 +0000</pubDate>
      <link>https://forem.com/abhishekamralkar/getting-started-with-cdk-for-terraform-5d9l</link>
      <guid>https://forem.com/abhishekamralkar/getting-started-with-cdk-for-terraform-5d9l</guid>
      <description>&lt;h3&gt;
  
  
  CDK for Terraform
&lt;/h3&gt;

&lt;p&gt;Hashicorp recently announced &lt;code&gt;cdktf&lt;/code&gt; Cloud Development Kit for Terraform which currently supports &lt;code&gt;Python3&lt;/code&gt; and &lt;code&gt;Typescript&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;With &lt;code&gt;cdktf&lt;/code&gt; we can write Terraform code in &lt;code&gt;Python3&lt;/code&gt; or &lt;code&gt;Typescript&lt;/code&gt; instead of &lt;code&gt;HCL&lt;/code&gt; which is the default language for Terraform.&lt;/p&gt;

&lt;p&gt;Well, I thought of giving it a try and check out how it works out with &lt;code&gt;Python3&lt;/code&gt;.&lt;/p&gt;

&lt;h1&gt;
  
  
  Install cdktf
&lt;/h1&gt;

&lt;p&gt;To install the most recent stable release of cdktf, use npm.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;--global&lt;/span&gt; cdktf-cli
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To get up to date with the cutting edge development version&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;--global&lt;/span&gt; cdktf-cli@next
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once the installation is done you can check the cdktf installation via &lt;code&gt;cdktf&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;Commands:
  cdktf deploy &lt;span class="o"&gt;[&lt;/span&gt;OPTIONS]   Deploy the given stack
  cdktf destroy &lt;span class="o"&gt;[&lt;/span&gt;OPTIONS]  Destroy the given stack
  cdktf diff &lt;span class="o"&gt;[&lt;/span&gt;OPTIONS]     Perform a diff &lt;span class="o"&gt;(&lt;/span&gt;terraform plan&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="k"&gt;for &lt;/span&gt;the given stack
  cdktf get &lt;span class="o"&gt;[&lt;/span&gt;OPTIONS]      Generate CDK Constructs &lt;span class="k"&gt;for &lt;/span&gt;Terraform providers and modules.
  cdktf init &lt;span class="o"&gt;[&lt;/span&gt;OPTIONS]     Create a new cdktf project from a template.
  cdktf login              Retrieves an API token to connect to Terraform Cloud.
  cdktf synth &lt;span class="o"&gt;[&lt;/span&gt;OPTIONS]    Synthesizes Terraform code &lt;span class="k"&gt;for &lt;/span&gt;the given app &lt;span class="k"&gt;in &lt;/span&gt;a directory.                                                                                                                                  &lt;span class="o"&gt;[&lt;/span&gt;aliases: synthesize]

Options:
  &lt;span class="nt"&gt;--version&lt;/span&gt;          Show version number                                                                                                                                                                                             &lt;span class="o"&gt;[&lt;/span&gt;boolean]
  &lt;span class="nt"&gt;--disable-logging&lt;/span&gt;  Dont write log files. Supported using the &lt;span class="nb"&gt;env &lt;/span&gt;CDKTF_DISABLE_LOGGING.                                                                                                                            &lt;span class="o"&gt;[&lt;/span&gt;boolean] &lt;span class="o"&gt;[&lt;/span&gt;default: &lt;span class="nb"&gt;true&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt;
  &lt;span class="nt"&gt;--log-level&lt;/span&gt;        Which log level should be written. Only supported via setting the &lt;span class="nb"&gt;env &lt;/span&gt;CDKTF_LOG_LEVEL                                                                                                                            &lt;span class="o"&gt;[&lt;/span&gt;string]
  &lt;span class="nt"&gt;-h&lt;/span&gt;, &lt;span class="nt"&gt;--help&lt;/span&gt;         Show &lt;span class="nb"&gt;help&lt;/span&gt;                                                                                                                                                                                                       &lt;span class="o"&gt;[&lt;/span&gt;boolean]

Options can be specified via environment variables with the &lt;span class="s2"&gt;"CDKTF_"&lt;/span&gt; prefix &lt;span class="o"&gt;(&lt;/span&gt;e.g. &lt;span class="s2"&gt;"CDKTF_OUTPUT"&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Okay now, let's do some real work we will create a project where we will deploy Nginx on top of Docker using &lt;code&gt;cdktf&lt;/code&gt; and Python3. For the Typescript example please check &lt;a href="https://github.com/hashicorp/terraform-cdk/tree/master/examples/typescript-docker" rel="noopener noreferrer"&gt;terraform-cdk&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Create a directory by any name in our case we will use below the &lt;code&gt;python-docker&lt;/code&gt;&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;mkdir &lt;/span&gt;python-docker &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nb"&gt;cd&lt;/span&gt; &lt;span class="nv"&gt;$_&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Initialize the project with the init command. We will use the &lt;code&gt;--local&lt;/code&gt; flag so that the infrastructure state will be stored locally.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;cdktf init &lt;span class="nt"&gt;--template&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;python &lt;span class="nt"&gt;--local&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Make sure you pass &lt;code&gt;python&lt;/code&gt; and not &lt;code&gt;python3&lt;/code&gt; else you will get below error&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;Invalid values:
  Argument: template, Given: &lt;span class="s2"&gt;"python3"&lt;/span&gt;, Choices: &lt;span class="s2"&gt;"python"&lt;/span&gt;, &lt;span class="s2"&gt;"typescript"&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;cdktf&lt;/code&gt; will generate the template for us, in our case, we will be using docker to get Nginx running so make sure to change the provider in &lt;code&gt;cdktf.json&lt;/code&gt;&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="o"&gt;{&lt;/span&gt;
  &lt;span class="s2"&gt;"language"&lt;/span&gt;: &lt;span class="s2"&gt;"python"&lt;/span&gt;,
  &lt;span class="s2"&gt;"app"&lt;/span&gt;: &lt;span class="s2"&gt;"pipenv run ./main.py"&lt;/span&gt;,
  &lt;span class="s2"&gt;"terraformProviders"&lt;/span&gt;: &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"docker"&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt;,
  &lt;span class="s2"&gt;"codeMakerOutput"&lt;/span&gt;: &lt;span class="s2"&gt;"imports"&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Run the get command to download the dependencies for using Docker with Python.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;cdktf get
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now add your code in &lt;code&gt;main.py&lt;/code&gt; file for building Docker&lt;/p&gt;

&lt;p&gt;First import the Docker provider, this means the imports is a local directory created by the above command&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;from imports.docker import Image, Container
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;and later add below code&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker_image &lt;span class="o"&gt;=&lt;/span&gt; Image&lt;span class="o"&gt;(&lt;/span&gt;self, &lt;span class="s1"&gt;'nginx-latest'&lt;/span&gt;, &lt;span class="nv"&gt;name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s1"&gt;'nginx:latest'&lt;/span&gt;, &lt;span class="nv"&gt;keep_locally&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;False&lt;span class="o"&gt;)&lt;/span&gt;

Container&lt;span class="o"&gt;(&lt;/span&gt;self, &lt;span class="s1"&gt;'nginx-cdktf'&lt;/span&gt;, &lt;span class="nv"&gt;name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s1"&gt;'nginx-python-cdktf'&lt;/span&gt;,
                  &lt;span class="nv"&gt;image&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;docker_image.name, &lt;span class="nv"&gt;ports&lt;/span&gt;&lt;span class="o"&gt;=[&lt;/span&gt;
                      &lt;span class="o"&gt;{&lt;/span&gt;
                          &lt;span class="s1"&gt;'internal'&lt;/span&gt;: 80,
                          &lt;span class="s1"&gt;'external'&lt;/span&gt;: 8000
                      &lt;span class="o"&gt;}]&lt;/span&gt;, &lt;span class="nv"&gt;privileged&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;False&lt;span class="o"&gt;)&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Add the dependencies in &lt;code&gt;Pipenv&lt;/code&gt; file in our case&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="o"&gt;[&lt;/span&gt;packages]
&lt;span class="nv"&gt;constructs&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"3.0.4"&lt;/span&gt;
&lt;span class="nv"&gt;cdktf&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"0.0.12"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Pipenv will throw an error if you don't define the version for the packages&lt;/p&gt;

&lt;p&gt;Run &lt;code&gt;pipenv&lt;/code&gt; to get all the dependencies to install the pipenv check the official website &lt;a href="https://pipenv.pypa.io/en/latest/" rel="noopener noreferrer"&gt;pipenv&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;pipenv &lt;span class="nb"&gt;install&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now compile and generate Terraform configuration&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;cdktf synth
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The above command will create a folder called cdktf.out that contains all Terraform JSON configuration that was generated.&lt;/p&gt;

&lt;p&gt;We can run the regular Terraform commands&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;cdktf.out
terraform init
terraform plan
terraform apply
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;OR&lt;/p&gt;

&lt;p&gt;We can deploy&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;cdktf deploy
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Lets see a demo
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://asciinema.org/a/349186" rel="noopener noreferrer"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fasciinema.org%2Fa%2F349186.png" alt="asciicast"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>cdktf</category>
      <category>terraform</category>
      <category>python</category>
    </item>
    <item>
      <title>Manage Your Systems with Nix Package Manager</title>
      <dc:creator>Abhishek Anand Amralkar</dc:creator>
      <pubDate>Mon, 13 Jul 2020 06:40:11 +0000</pubDate>
      <link>https://forem.com/abhishekamralkar/manage-your-systems-with-nix-package-manager-167k</link>
      <guid>https://forem.com/abhishekamralkar/manage-your-systems-with-nix-package-manager-167k</guid>
      <description>&lt;h1&gt;
  
  
  Nix Package Manager
&lt;/h1&gt;

&lt;p&gt;We will walk through the Nix Package Manager and how we can build immutable systems. This is my first attempt to get Nix for all of my machines mostly Debian's(2 Laptops and 1 Desktop) and a MacBook.&lt;/p&gt;

&lt;p&gt;The quickest way to install Nix is to open a terminal and run the following command (as a user other than root with sudo permission):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;curl &lt;span class="nt"&gt;-L&lt;/span&gt; https://nixos.org/nix/install | sh
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Add &lt;code&gt;source $HOME/.nix-profile/etc/profile.d/nix.sh&lt;/code&gt; to your .bashrc or .zshrc.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s1"&gt;'source $HOME/.nix-profile/etc/profile.d/nix.sh'&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&amp;gt;&lt;/span&gt; ~/.bashrc
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h2&gt;
  
  
  The Basics
&lt;/h2&gt;

&lt;p&gt;After installation we have some new commands available:&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;* nix-env used to install dependencies and alter your current profile
* nix-shell used to start shells based on nix expressions
* nix-store used to query or manipulate the nix store
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h3&gt;
  
  
  Install a Package
&lt;/h3&gt;


&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;nix-env &lt;span class="nt"&gt;-iA&lt;/span&gt; nixpkgs.clojure 

&lt;span class="c"&gt;# Output&lt;/span&gt;
installing &lt;span class="s1"&gt;'clojure-1.10.1.507'&lt;/span&gt;
building &lt;span class="s1"&gt;'/nix/store/y6r745pjimp232bgknncx27a074i4j0z-user-environment.drv'&lt;/span&gt;...
created 44 symlinks &lt;span class="k"&gt;in &lt;/span&gt;user environment
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h3&gt;
  
  
  Query a Package
&lt;/h3&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;nix-env &lt;span class="nt"&gt;-qaP&lt;/span&gt; &lt;span class="s1"&gt;'consul'&lt;/span&gt;

&lt;span class="c"&gt;# Output&lt;/span&gt;
nixpkgs.consul                      consul-1.7.2
nixpkgs.consul-alerts               consul-alerts-0.6.0
nixpkgs.consul-template             consul-template-0.19.4
nixpkgs.prometheus-consul-exporter  consul_exporter-0.3.0

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h3&gt;
  
  
  Uninstall a Package
&lt;/h3&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;nix-env &lt;span class="nt"&gt;-e&lt;/span&gt; clojure

&lt;span class="c"&gt;#Output&lt;/span&gt;
uninstalling &lt;span class="s1"&gt;'clojure-1.10.1.507'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h1&gt;
  
  
  Nix Shell
&lt;/h1&gt;

&lt;p&gt;Nix-shell lets you open a shell in a new environment.&lt;/p&gt;

&lt;p&gt;In Nix; an environment is a collection of derivations (aka functions) that are put into your PATH. &lt;/p&gt;

&lt;p&gt;We can create an environment by creating a .nix file to define the environment. Create a file called consul.nix with below content&lt;/p&gt;

&lt;h3&gt;
  
  
  Derivations
&lt;/h3&gt;

&lt;p&gt;Nix is built around the concept of derivations. A derivation is simply defined as "a build action". It produces 1 (or maybe more) output paths in the nix store.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;with import &amp;lt;nixpkgs&amp;gt; &lt;span class="o"&gt;{}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nb"&gt;let
  &lt;/span&gt;clj &lt;span class="o"&gt;=&lt;/span&gt; pkgs.clojure&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;in
&lt;/span&gt;stdenv.mkDerivation rec &lt;span class="o"&gt;{&lt;/span&gt;
  name &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"clojure-environment"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  buildInputs &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;
    clj
    pkgs.leiningen
  &lt;span class="o"&gt;]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  shellHook &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;''&lt;/span&gt;
    &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"using clojure: &lt;/span&gt;&lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;clojure&lt;/span&gt;&lt;span class="p"&gt;.name&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
  &lt;span class="s1"&gt;'

&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;and finally login to your env shell&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;nix-shell packages/clojure.nix
using clojure: clojure-1.10.1.507

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h3&gt;
  
  
  To install packages from Non NixOS
&lt;/h3&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="o"&gt;{&lt;/span&gt; pkgs ? import &amp;lt;nixpkgs&amp;gt; &lt;span class="o"&gt;{}&lt;/span&gt; &lt;span class="o"&gt;}&lt;/span&gt;:
with import &amp;lt;nixpkgs&amp;gt; &lt;span class="o"&gt;{}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

pkgs.stdenv.mkDerivation &lt;span class="o"&gt;{&lt;/span&gt;
  name &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"consul"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  src &lt;span class="o"&gt;=&lt;/span&gt; pkgs.fetchurl &lt;span class="o"&gt;{&lt;/span&gt;
    url &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"https://releases.hashicorp.com/consul/1.8.0/consul_1.8.0_linux_amd64.zip"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    sha256 &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"98df3e0a8ede84794fa4d20b1b6b5d52ad3b983dec916c4d612cecba7c48a421"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="o"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  phases &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"unpackPhase"&lt;/span&gt; &lt;span class="s2"&gt;"installPhase"&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;



  unpackPhase &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;''&lt;/span&gt;


&lt;span class="s1"&gt;''&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  installPhase &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;''&lt;/span&gt;
    &lt;span class="nb"&gt;mkdir&lt;/span&gt; &lt;span class="nt"&gt;-p&lt;/span&gt; &lt;span class="nv"&gt;$out&lt;/span&gt;/bin
    &lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;pkgs&lt;/span&gt;&lt;span class="p"&gt;.unzip&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;/bin/unzip &lt;span class="nv"&gt;$src&lt;/span&gt; &lt;span class="nt"&gt;-d&lt;/span&gt; &lt;span class="nv"&gt;$out&lt;/span&gt;/bin
    &lt;span class="nb"&gt;chmod&lt;/span&gt; +x &lt;span class="nv"&gt;$out&lt;/span&gt;/bin/consul

  &lt;span class="s1"&gt;''&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h3&gt;
  
  
  To run it
&lt;/h3&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;nix-env &lt;span class="nt"&gt;-f&lt;/span&gt; consul.nix &lt;span class="nt"&gt;-i&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h1&gt;
  
  
  The stdenv
&lt;/h1&gt;

&lt;p&gt;The standard build environment in the Nix Packages collection provides an environment for building Unix packages.&lt;/p&gt;

&lt;p&gt;To build a package with the standard environment, you use the function stdenv.mkDerivation, instead of the primitive built-in function derivation, e.g.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;with import &amp;lt;nixpkgs&amp;gt; &lt;span class="o"&gt;{}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nb"&gt;let
  &lt;/span&gt;py &lt;span class="o"&gt;=&lt;/span&gt; pkgs.python&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;in
&lt;/span&gt;stdenv.mkDerivation rec &lt;span class="o"&gt;{&lt;/span&gt;
  name &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"python-environment"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  buildInputs &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;
    py
  &lt;span class="o"&gt;]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  shellHook &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;''&lt;/span&gt;
    &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"using python: &lt;/span&gt;&lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;python&lt;/span&gt;&lt;span class="p"&gt;.name&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
  &lt;span class="s1"&gt;'
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h3&gt;
  
  
  The standard environment provides the following packages:
&lt;/h3&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;    The GNU C Compiler, configured with C and C++ support.
    GNU coreutils &lt;span class="o"&gt;(&lt;/span&gt;contains a few dozen standard Unix commands&lt;span class="o"&gt;)&lt;/span&gt;&lt;span class="nb"&gt;.&lt;/span&gt;
    GNU findutils &lt;span class="o"&gt;(&lt;/span&gt;contains find&lt;span class="o"&gt;)&lt;/span&gt;&lt;span class="nb"&gt;.&lt;/span&gt;
    GNU diffutils &lt;span class="o"&gt;(&lt;/span&gt;contains diff, cmp&lt;span class="o"&gt;)&lt;/span&gt;&lt;span class="nb"&gt;.&lt;/span&gt;
    GNU sed.
    GNU grep.
    GNU awk.
    GNU tar.
    &lt;span class="nb"&gt;gzip &lt;/span&gt;and bzip2.
    GNU Make. 
    Bash. 
    The patch command.
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h3&gt;
  
  
  Phases
&lt;/h3&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    patch phase
    configure phase
    build phase
    check phase
    install phase
    buildup phase
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h1&gt;
  
  
  Nix Expressions
&lt;/h1&gt;

&lt;p&gt;Nix is not just a package manager. Nix is OS and a Language too.&lt;/p&gt;

&lt;p&gt;The Nix expression language is a pure, lazy, functional language. Purity means that operations in the language don't have side-effects (for instance, there is no variable assignment). Laziness means that arguments to functions are evaluated only when they are needed. Functional means that functions are “normal” values that can be passed around and manipulated in interesting ways. The language is not a full-featured, general-purpose language. Its main job is to describe packages, compositions of packages, and the variability within packages.&lt;/p&gt;

&lt;p&gt;To read more &lt;/p&gt;

&lt;p&gt;&lt;a href="https://nixos.org/nix/manual/#ch-expression-language"&gt;https://nixos.org/nix/manual/#ch-expression-language&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In this blog, we just looked into just a small functionality of NIX. NIX is much more than that.&lt;/p&gt;

&lt;p&gt;Happy Nixing!&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Unspecified Location Constraint</title>
      <dc:creator>Abhishek Anand Amralkar</dc:creator>
      <pubDate>Fri, 17 Apr 2020 05:14:37 +0000</pubDate>
      <link>https://forem.com/abhishekamralkar/unspecified-location-constraint-ie2</link>
      <guid>https://forem.com/abhishekamralkar/unspecified-location-constraint-ie2</guid>
      <description>&lt;p&gt;I was creating an AWS S3 bucket using AWS CLI, but I was getting below error while creating bucket&lt;/p&gt;

&lt;h4&gt;
  
  
  Problem:
&lt;/h4&gt;

&lt;h6&gt;
  
  
  Command:-
&lt;/h6&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;aws s3api create-bucket --bucket abhishek-qa-state-store --region us-west-2                                                                                                                                    
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h6&gt;
  
  
  Error:-
&lt;/h6&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;An error occurred (IllegalLocationConstraintException) when calling the CreateBucket operation: The unspecified location constraint is incompatible for the region-specific endpoint this request was sent to.
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h4&gt;
  
  
  Solution:
&lt;/h4&gt;

&lt;p&gt;For any other region than &lt;code&gt;us-east-1&lt;/code&gt; in AWS, we need to define the &lt;code&gt;LocationConstraint&lt;/code&gt;. Below is the command which will create a bucket for you in any other region apart from &lt;code&gt;us-east-1&lt;br&gt;
&lt;/code&gt;&lt;/p&gt;

&lt;h6&gt;
  
  
  Command:-
&lt;/h6&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;aws s3api create-bucket --bucket abhishek-qa-state-store --region us-west-2 --create-bucket-configuration LocationConstraint=us-west-2                                                                         
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h6&gt;
  
  
  Output:-
&lt;/h6&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
    "Location": "http://abhishek-qa-state-store.s3.amazonaws.com/"
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;More info available here&lt;/p&gt;

&lt;p&gt;&lt;a href="https://docs.aws.amazon.com/cli/latest/reference/s3api/get-bucket-location.html"&gt;AWS S3 Location Constraint&lt;/a&gt;&lt;/p&gt;

</description>
      <category>aws</category>
      <category>s3</category>
      <category>awscli</category>
    </item>
    <item>
      <title>Hi, I'm Abhishek A Amralkar</title>
      <dc:creator>Abhishek Anand Amralkar</dc:creator>
      <pubDate>Mon, 06 Mar 2017 04:55:41 +0000</pubDate>
      <link>https://forem.com/abhishekamralkar/hi-im-abhishek-a-amralkar</link>
      <guid>https://forem.com/abhishekamralkar/hi-im-abhishek-a-amralkar</guid>
      <description>&lt;p&gt;I am DevOps Engineer and I have been coding for [2] years.  &lt;/p&gt;

&lt;p&gt;You can find me on Twitter as &lt;a href="https://twitter.com/aamralkar" rel="noopener noreferrer"&gt;@aamralkar&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I live in Pune.&lt;/p&gt;

&lt;p&gt;I mostly program in these languages: [Clojure, Shell].&lt;/p&gt;

&lt;p&gt;I am currently learning more about [Clojure, DevOPs].&lt;/p&gt;

&lt;p&gt;Nice to meet you.&lt;/p&gt;

</description>
      <category>introduction</category>
    </item>
  </channel>
</rss>
