Posted: Tuesday, January 17, 2023

Word Count: 482

Reading Time: 3 minutes


This article leverages chocolatey to quickly install IaC tools onto a windows based workstation.

Prerequisites

Tools Table

The code installs the following tools:

ToolsInformation
Visual Studio Codehttps://code.visualstudio.com/
Azure Command Line Interfacehttps://learn.microsoft.com/en-us/cli/azure/what-is-azure-cli
aws clihttps://aws.amazon.com/cli/
gcloud clihttps://cloud.google.com/cli
Powershell 7https://learn.microsoft.com/en-us/training/modules/introduction-to-powershell/
Terraformhttps://www.terraform.io/
Chocolatey Package Installer

What is Chocolatey?

Chocolatey is a command-line installer for windows software. Similar to apt-get or yum leveraged in Linux-based OSes, It simplifies the process of downloading and installing software.

Chocolatey’s syntax is fairly straightforward. All commands begin with choco, followed by the action, and then the package name.

Choco ActionDescription
listlists remote or local packages
inforetrieves package information. Shorthand for choco search pkgname
searchsearches remote or local packages (alias for list)
installinstalls packages from various sources
upgradeupgrades packages from various sources
uninstalluninstalls a package
Common Choco Actions

Installing Chocolatey

Installing chocolatey is very straight-forward and only requires a single line of code.

Launch PowerShell
  1. Select the start or windows icon and type powershell in the search bar.
  2. Locate the Windows PowerShell application in the best matches section of the start menu, right-click and select Run as administrator. . Optionally, the version of Windows may present a submenu which will allow you to select Run as Administrator as well.
Launch PowerShell
Run PowerShell Script
  1. Within the PowerShell window, Type the following command:

    Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))

  2. Press Enter to run the script. The script will download and install chocolatey. Once the script complete, it should return a status of “Chocolatey (choco.exe) is now ready.”
Launch PowerShell
  1. To validate the installation, simply Type the following command:

    choco --version

  2. Press Enter. The command should return the currently installed version
Verify Choco
Install Chocolatey Packages

With chocolatey installed, tools such as visual studio code, PowerShell 7, and az CLI can quickly be installed. Installing packages begins with the syntax of choco install followed by the name of the package or packages to be installed. Multiple packages can be installed by separating them with a space. Packages can be located by using the choco search command or simply searching the chocolatey. To install the packages listed in the table below, type in the following command:

choco install awscli terraform azure-cli gcloudsdk powershell-core vscode -y

The -y switch is optional and removes the need to confirm the prompts that will pop up during the installation.

Once the script is complete it will provide a list of packages that were successfully installed. The machine may need to be rebooted before using some of the applications.

Conclusion

The script can be catered to your needs by simply removing or adding additional packages. The time of installation will vary depending on the complexity of the application.