DEV Community

atsushi-ambo
atsushi-ambo

Posted on

How to install Terraform for Mac and get started using it

In this blog, I write how to install Terraform for Mac and get started using it.

  1. Install Terraform on Mac
  2. Verify that Terraform is installed
  3. Basic commands of Terraform

1. Install Terraform on Mac

To install, run the following two commands:

% brew tap hashicorp/tap
% brew install hashicorp/tap/terraform
Enter fullscreen mode Exit fullscreen mode

But for my Mac, I got the following error message.

Error: No developer tools installed.
Install the Command Line Tools:
  xcode-select --install
Error: 'git' must be installed and in your PATH!
Enter fullscreen mode Exit fullscreen mode

By installing xcode and git, I was able to fix the error message.

% xcode-select --install
% brew install git
Enter fullscreen mode Exit fullscreen mode

2. Verify that Terraform is installed

Now I may have managed to get Terraform to install completely.
So I need to check if this is the case with the following commands.

% terraform --version
Terraform v1.3.7
on darwin_arm64
Enter fullscreen mode Exit fullscreen mode

3. Basic commands of Terraform

  1. Initialise Terraform You need to initialise Terraform before using it.
% terraform init
Terraform initialized in an empty directory!
Enter fullscreen mode Exit fullscreen mode
  1. Check the status of Terraform To check the current status of your infrastructure resources, use the following command I get an error because I have nothing configured at the moment.
% terraform plan
│ Error: No configuration files
Enter fullscreen mode Exit fullscreen mode
  1. Apply Terraform Apply Terraform to make changes to the infrastructure.
% terraform apply
│ Error: No configuration files
Enter fullscreen mode Exit fullscreen mode
  1. Deleting Terraform You can use the following commands to delete an infrastructure resource.
% terraform destroy
Enter fullscreen mode Exit fullscreen mode
  1. Managing Terraform Status You can use the following commands to check and manage your current state.
% terraform state list 
% terraform state show <resource_name>
% terraform state mv <resource_name> <new_name>
% terraform state pull
% terraform state push
Enter fullscreen mode Exit fullscreen mode

I have nothing to configure at the moment. I will use these commands when I create my infrastructure resource.

Top comments (0)