<?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: Mishin Nikolai</title>
    <description>The latest articles on DEV Community by Mishin Nikolai (@nmishin).</description>
    <link>https://dev.to/nmishin</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.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1043909%2F614f3d7d-d589-4d87-8912-3d05eca9cafb.jpeg</url>
      <title>DEV Community: Mishin Nikolai</title>
      <link>https://dev.to/nmishin</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/nmishin"/>
    <language>en</language>
    <item>
      <title>How to Manage Multiple OpenTofu Versions With Tofuenv</title>
      <dc:creator>Mishin Nikolai</dc:creator>
      <pubDate>Tue, 09 Jan 2024 21:14:41 +0000</pubDate>
      <link>https://dev.to/nmishin/how-to-manage-multiple-opentofu-versions-with-tofuenv-5g6e</link>
      <guid>https://dev.to/nmishin/how-to-manage-multiple-opentofu-versions-with-tofuenv-5g6e</guid>
      <description>&lt;p&gt;When we work with only one &lt;a href="https://github.com/opentofu/opentofu" rel="noopener noreferrer"&gt;OpenTofu&lt;/a&gt; project, we install needed version and don’t have any issues. But when we start to work with multiple projects with different versions of  OpenTofu - we are in trouble.&lt;/p&gt;

&lt;p&gt;How could this problem be solved earlier? We downloaded the required version of OpenTofu and placed it somewhere in &lt;code&gt;$PATH&lt;/code&gt;. After that we renamed the downloaded file and used it something like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ tofu-1.6.0-rc1 -version
OpenTofu v1.6.0-rc1
on darwin_amd64
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;But this is hard and inconvenient to switch between versions, and we need to remember, which version of OpenTofu has to be used every time.&lt;/p&gt;

&lt;p&gt;Here &lt;a href="https://github.com/tofuutils/tofuenv" rel="noopener noreferrer"&gt;tofuenv&lt;/a&gt; is going to help us. tofuenv is an OpenTofu version manager. It allows us to easily install a version, switch between them, and set specific version for specific repository.&lt;/p&gt;

&lt;h2&gt;
  
  
  Installing tofuenv
&lt;/h2&gt;

&lt;p&gt;tofuenv can be installed to all major operating systems, such as MacOS, Linux and Windows.&lt;/p&gt;

&lt;p&gt;We can use brew to install tofuenv to the macos:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ brew tap tofuutils/tap
$ brew install tofuenv
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For linux, we can manually install tofuenv.&lt;/p&gt;

&lt;p&gt;Check out tofuenv into any path (here is&amp;nbsp;&lt;code&gt;${HOME}/.tofuenv&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;$ git clone --depth=1 https://github.com/tofuutils/tofuenv.git ~/.tofuenv
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Add&amp;nbsp;&lt;code&gt;~/.tofuenv/bin&lt;/code&gt;&amp;nbsp;to your&amp;nbsp;&lt;code&gt;$PATH&lt;/code&gt;&amp;nbsp;any way you like:&lt;/p&gt;

&lt;p&gt;bash:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ echo 'export PATH="$HOME/.tofuenv/bin:$PATH"' &amp;gt;&amp;gt; ~/.bash_profile
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;zsh:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ echo 'export PATH="$HOME/.tofuenv/bin:$PATH"' &amp;gt;&amp;gt; ~/.zprofile 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;OR you can make symlinks for &lt;code&gt;tofuenv/bin/*&lt;/code&gt; scripts into a path that is already added to your &lt;code&gt;$PATH&lt;/code&gt; (e.g. &lt;code&gt;/usr/local/bin&lt;/code&gt;) OSX/Linux Only!&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ ln -s ~/.tofuenv/bin/* /usr/local/bin
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;On Ubuntu/Debian touching &lt;code&gt;/usr/local/bin&lt;/code&gt; might require sudo access, but you can create &lt;code&gt;${HOME}/bin&lt;/code&gt; or &lt;code&gt;${HOME}/.local/bin&lt;/code&gt; and on next login it will get added to the session &lt;code&gt;$PATH&lt;/code&gt; or by running . &lt;code&gt;${HOME}/.profile&lt;/code&gt; it will get added to the current shell session's &lt;code&gt;$PATH&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;$ mkdir -p ~/.local/bin/ 
$ . ~/.profile
$ ln -s ~/.tofuenv/bin/* ~/.local/bin 
$ which tofuenv
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Run tofuenv to verify installation and check available options:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ tofuenv
tofuenv 1.0.3
Usage: tofuenv &amp;lt;command&amp;gt; [&amp;lt;options&amp;gt;]

Commands:
   install       Install a specific version of OpenTofu
   use           Switch a version to use
   uninstall     Uninstall a specific version of OpenTofu
   list          List all installed versions
   list-remote   List all installable versions
   version-name  Print current version of OpenTofu
   init          Update environment to use tofuenv correctly.
   pin           Write the current active version to ./.opentofu-version
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In case of any problems, you may refer to official documentation at &lt;a href="https://github.com/tofuutils/tofuenv" rel="noopener noreferrer"&gt;tofuenv github repository&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Installing OpenTofu with tofuenv
&lt;/h2&gt;

&lt;p&gt;After we have tofuenv installed, we can install opentofu in the following way.&lt;/p&gt;

&lt;p&gt;To install specific version of opentofu use the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ tofuenv install 1.6.0-rc1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To install latest stable version we can use specific word latest:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ tofuenv install latest
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;But due to the fact that at the time of writing this article OpenTofu doesn’t have a stable version, installation via &lt;code&gt;latest&lt;/code&gt; word doesn't work.&lt;/p&gt;

&lt;p&gt;Anyway, we can install&amp;nbsp; the latest available version of OpenTofu 1.6:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ tofuenv install latest:1.6
tofuenv install latest:1.6
Installing OpenTofu v1.6.0-rc1
Downloading release tarball from https://github.com/opentofu/opentofu/releases/download/v1.6.0-rc1/tofu_1.6.0-rc1_darwin_amd64.zip
########################################################################################################################################################### 100.0%
Downloading SHA hash file from https://github.com/opentofu/opentofu/releases/download/v1.6.0-rc1/tofu_1.6.0-rc1_SHA256SUMS
Archive:  /var/folders/nb/k6bv49gd4pd9kyvwwn519_2m0000gn/T/tofuenv_download.XXXXXX.fqdxfWoz/tofu_1.6.0-rc1_darwin_amd64.zip
  inflating: /usr/local/Cellar/tofuenv/1.0.3/versions/1.6.0-rc1/CHANGELOG.md  
  inflating: /usr/local/Cellar/tofuenv/1.0.3/versions/1.6.0-rc1/LICENSE  
  inflating: /usr/local/Cellar/tofuenv/1.0.3/versions/1.6.0-rc1/README.md  
  inflating: /usr/local/Cellar/tofuenv/1.0.3/versions/1.6.0-rc1/tofu  
Installation of tofu v1.6.0-rc1 successful. To make this your default version, run 'tofuenv use 1.6.0-rc1'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For now the latest available version of OpenTofu 1.6 is 1.6.0-rc1 and for that reason, it was installed by tofuenv.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; If&amp;nbsp;shasum&amp;nbsp;is present in the path, tofuenv will verify the download against OpenTofu published sha256 hash. Also GPG signature will be added for verification as soon as OpenTofu will support it.&lt;/p&gt;

&lt;h2&gt;
  
  
  List OpenTofu versions
&lt;/h2&gt;

&lt;p&gt;With tofuenv we can list locally installed versions and remote versions, which are available for installation.&lt;/p&gt;

&lt;p&gt;To list locally installed versions, run the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ tofuenv list
  1.6.0-alpha1
* 1.6.0-rc1 (set by /usr/local/Cellar/tofuenv/1.0.3/version)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Asterisk marks the version currently used.&lt;/p&gt;

&lt;p&gt;To list remote versions, run the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ tofuenv list-remote
1.6.0-rc1
1.6.0-beta5
1.6.0-beta4
1.6.0-beta3
1.6.0-beta2
1.6.0-beta1
1.6.0-alpha5
1.6.0-alpha4
1.6.0-alpha3
1.6.0-alpha2
1.6.0-alpha1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;OpenTofu placed binary in GitHub, and GitHub has a strict rate limiting rule for non-authorised users. Because of this, you can catch the 403 error or "GitHub Rate limits exceeded" error. You can set environment variable &lt;code&gt;TOFUENV_GITHUB_TOKEN&lt;/code&gt; with your own GitHub token for authentication against GitHub api and drastically increase the rate limits.&lt;/p&gt;

&lt;h2&gt;
  
  
  Switch a version to use
&lt;/h2&gt;

&lt;p&gt;To switch between versions, we can use couple of techniques.&lt;/p&gt;

&lt;p&gt;First of all, with use &lt;code&gt;use&lt;/code&gt; parameter:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ tofuenv use 1.6.0-alpha1
Switching default version to v1.6.0-alpha1
Default version (when not overridden by .opentofu-version or TOFUENV_TOFU_VERSION) is now: 1.6.0-alpha1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;By default, environment variable &lt;code&gt;TOFUENV_AUTO_INSTALL&lt;/code&gt; is set to &lt;code&gt;true&lt;/code&gt;, and if version 1.6.0-alpha2 of OpenTofu isn’t available locally, it will be downloaded and used automatically:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ tofuenv use 1.6.0-alpha2
No installed versions of opentofu matched '^1.6.0-alpha2$'. Trying to install a matching version since TOFUENV_AUTO_INSTALL=true
Installing OpenTofu v1.6.0-alpha2
Downloading release tarball from https://github.com/opentofu/opentofu/releases/download/v1.6.0-alpha2/tofu_1.6.0-alpha2_darwin_amd64.zip
########################################################################################################################################################### 100.0%
Downloading SHA hash file from https://github.com/opentofu/opentofu/releases/download/v1.6.0-alpha2/tofu_1.6.0-alpha2_SHA256SUMS
Archive:  /var/folders/nb/k6bv49gd4pd9kyvwwn519_2m0000gn/T/tofuenv_download.XXXXXX.3DyehSoJ/tofu_1.6.0-alpha2_darwin_amd64.zip
  inflating: /usr/local/Cellar/tofuenv/1.0.3/versions/1.6.0-alpha2/CHANGELOG.md  
  inflating: /usr/local/Cellar/tofuenv/1.0.3/versions/1.6.0-alpha2/LICENSE  
  inflating: /usr/local/Cellar/tofuenv/1.0.3/versions/1.6.0-alpha2/README.md  
  inflating: /usr/local/Cellar/tofuenv/1.0.3/versions/1.6.0-alpha2/tofu  
Installation of tofu v1.6.0-alpha2 successful. To make this your default version, run 'tofuenv use 1.6.0-alpha2'
Switching default version to v1.6.0-alpha2
Default version (when not overridden by .opentofu-version or TOFUENV_TOFU_VERSION) is now: 1.6.0-alpha2
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Second option is to use &lt;code&gt;.opentofu-version&lt;/code&gt; file. If that file is present in the directory and contains needed version, it will be used automatically:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;project1$ tofu -version
OpenTofu v1.6.0-rc1
on darwin_amd64
project1$ cat .opentofu-version 
1.6.0-rc1

project1$ cd ../project2
project2$ tofu -version
OpenTofu v1.6.0-alpha1
on darwin_amd64
project2$ cat .opentofu-version 
1.6.0-alpha1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That file can be created manually, for example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ echo 1.6.0-alpha1 &amp;gt; .opentofu-version
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Or with using special command &lt;code&gt;pin&lt;/code&gt; from tofuenv. That command will save currently used version of opentofu to the file in current directory:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ tofu -version
OpenTofu v1.6.0-rc1
on darwin_amd64

$ tofuenv pin
Pinned version by writing "1.6.0-rc1" to ./.opentofu-version
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Uninstall unneeded versions
&lt;/h2&gt;

&lt;p&gt;For the cleanup of unneeded installed version we can use &lt;code&gt;uninstall&lt;/code&gt; command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ tofuenv uninstall 1.6.0-rc1
Uninstall OpenTofu v1.6.0-rc1
OpenTofu v1.6.0-rc1 is successfully uninstalled
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  In conclusion
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://github.com/opentofu/opentofu" rel="noopener noreferrer"&gt;OpenTofu&lt;/a&gt; is a great open-source alternative to Terraform. Our team of tofuenv creators (me, &lt;a href="https://dev.to/kvendingoldo"&gt;Alexander Sharov&lt;/a&gt; and &lt;a href="https://dev.to/anastasiiakozlova245"&gt;Anastasiia Kozlova&lt;/a&gt;) believes that OpenTofu will take decisive place in the market, and tofuenv will help everyone to use it successfully.&lt;/p&gt;

</description>
      <category>terraform</category>
      <category>opentofu</category>
      <category>tofuenv</category>
      <category>devops</category>
    </item>
  </channel>
</rss>
