Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

terraform
aws

How to set up your first Terraform project with AWS

Umme Ammara

Terraform allows us to create, manage, and update infrastructure safely and effectively. To set up your first Terraform project with the AWS provider, you will need to perform the following steps:

AWS account

To create an AWS account, click here. Follow the steps until you reach the ‘Create User’ section. After successful creation of the user, the site will provide you the following:

  • Access key ID

  • Secret access key

Save these keys as you will need them to set up your first Terraform project with AWS.

Install terraform

Follow the steps given in Terraform’s official documentation to download and install Terraform on your operating system.

Code

To create your first Terraform project, create a file named main.tf and write the following text in HashiCorp Configuration Langauge (HCL):



provider "aws" {
  access_key = "Your access key here"
  secret_key = "Your secret key here"
  region = "eu-east-1"
}

resource "aws_s3_bucket" "first_bucket" {
    bucket = "example-first-bucket"
}

In the code above, we are stating that we want to use the AWS provider plugin from Terraform. We also provide our secret access key and access key ID that we saved when creating an AWS account. We are also specifying the region (eu-east-1) in which we want to make the changes.

The second part of the code defines the resource. Here, it creates an S3 bucket with the name example-first-bucket in the region specified earlier.

With this, you have now successfully set up your first Terraform project with AWS.

After the setup, you can create your infrastructure by running the simple commands given below:

RELATED TAGS

terraform
aws

CONTRIBUTOR

Umme Ammara
Copyright ©2022 Educative, Inc. All rights reserved
RELATED COURSES

View all Courses

Keep Exploring