Recently, I decided to set up a project using Terraform and the Azure CLI. I had Terraform installed and working on my system, but I quickly ran into challenges when trying to get Azure’s command-line tool up and running. Here’s a rundown of the steps—and obstacles—I encountered.
I began my journey by ensuring that Terraform was properly installed:
which terraform
/usr/local/bin/terraform
Then I navigated to my project directory and confirmed that my Terraform configuration (main.tf) was in place:
cd /Users/eaton/my-terraform-project
ls -l
However, when I checked for the Azure CLI, I encountered an error:
az --version
zsh: command not found: az
Clearly, the Azure CLI wasn’t installed yet.
Attempting to Install Azure CLI via Homebrew
I tried to install the Azure CLI via Homebrew:
brew install azure-cli
But then I saw:
zsh: command not found: brew
Installing Homebrew
This meant Homebrew wasn’t installed yet. So, I ran the official Homebrew installation script:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
The script started off well, listing the directories it would create and mentioning that the Xcode Command Line Tools would be installed. But then I encountered an issue: the installer required at least 10.12 GB of free disk space to install the Command Line Tools, and my system didn’t have enough space. This was reflected in the error messages and the subsequent failure of the xcode-select command.
...
Not enough free disk space: a total of 10.12 GB is required.
...
xcode-select: error: invalid developer directory '/Library/Developer/CommandLineTools'
Freeing Up Disk Space
Realizing that disk space might be the root of the problem, I checked the available space using:
df -h /
After a couple of attempts, I saw that my available space was improving—from about 2.0 GiB up to nearly 19 GiB in later checks—but I still encountered challenges. I tried to clear some space by emptying the Trash and cleaning out the cache directories:
rm -rf ~/Library/Caches/*
rm -rf ~/.Trash/*
While some cache directories were successfully removed, macOS’s built-in protections prevented deletion in certain areas (such as CloudKit and FamilyCircle), leading to several “Operation not permitted” messages.
I even tried to find large files on my system using:
find ~/ -type f -size +1G
This helped me identify a couple of sizeable media files, though the command also flagged many protected directories.
Reattempting Homebrew and Azure CLI Installation
With some disk space freed up and the PATH updated (by appending /usr/local/bin to my ~/.zshrc), I tried the Homebrew installation again:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Unfortunately, the same disk space and Xcode Command Line Tools issues persisted. I ran through the installation prompts, only to see errors regarding insufficient free space and invalid developer directories.
After cleaning the Trash and cache a few more times and verifying free space with df -h /, I was finally able to update my environment by adding:
echo 'export PATH="/usr/local/bin:$PATH"' >> ~/.zshrc
source ~/.zshrc
This step ensured that when Homebrew was eventually installed, its binaries (like brew itself and the Azure CLI) would be easily accessible from the terminal.
Lessons Learned
This session was a practical lesson in:
- Verifying prerequisites:Ensuring tools like Terraform are installed before moving on.
- Dependency management:Realizing that installing one tool (Azure CLI) might require another (Homebrew), which in turn depends on system resources and tools (like Xcode Command Line Tools).
- Troubleshooting disk space:Learning how to check disk usage, safely remove files, and work around macOS protections.
- Patience in setup:Sometimes, setting up the development environment is as much about system housekeeping as it is about writing code.
While the journey wasn’t entirely smooth, I’m optimistic that with a little more cleanup and disk management, I’ll be back on track to using Terraform and Azure CLI seamlessly.