Initialize Terraform directory with AWS Provider

Stefano Monti
AWS Infrastructure
Published in
2 min readDec 24, 2022

Install Terraform

First, you must install Terraform on your machine; you can find all the instructions in the Hashicorp official documentation.

AWS Account

For this tutorial, you need an AWS account with admin permission to create resources on it. You can find here instructions for starting with AWS.

Initialize template

Once you have Terraform installed on your machine, be sure you can launch this command from the command line:

$ terraform version

The command line should prompt something like this:

Terraform v1.3.6
on darwin_arm64
+ provider registry.terraform.io/hashicorp/aws v3.66.0

Time to start writing the template!

Create a file called main.tf and paste the following lines:

terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "3.66.0"
}
}
}

Terraform relies on plugins called “providers” to interact with remote systems. Terraform configurations must declare which providers they require so that Terraform can install and use them.
In this case, our provider will be AWS.

Now, let’s provide Terraform credentials for deploying our resources by copying/pasting the following code:

provider "aws" {
region = "eu-west-1"
profile = "insert-here-your-aws-profile-name"
}

You can choose the AWS region you want; here is an entire regions list.
Insert your AWS profile, and make sure to have permission to provide the following resources. This is a page where you can learn how to create an AWS profile on your machine.

Let’s check everything is OK!

$ terraform init

The terraform init command initializes a working directory containing Terraform configuration files. This is the first command that should be run after writing a new Terraform configuration or cloning an existing one from version control. It is safe to run this command multiple times.

This should be the result:

If you obtained a similar result you initialized Terraform correctly and you’re ready to add resources to your template in order to create AWS infrastructure in the cloud!!

--

--