Going to the Cloud

Now that we have a basic understanding on how to use Terraform, we can look into more intermediate usages by utilising cloud providers. Since servers require a lot more info such as the network CIDRs, inbound and outbound connections, image IDs and more, we will need to start organising our files from the get-go to reduce the amount of clutter we might get later on when we scale.

AWS Provider

Start by setting up your providers.tf file in accordance to the AWS Provider documentation.

providers.tf
terraform {
  required_providers {
    aws = {
      source = "hashicorp/aws"
      version = "~> 5.70.0"
    }
  }
}

provider "aws" {
  region = "us-east-1" # Default for now, we will turn this into a variable later on
}

Now, initialise this environment with terraform init so you have the files necessary to create resources, then log into your AWS User/IAM through the AWS CLI tool if you have not already.

Note on storing secrets

You can store authentication inside of the provider's config though this is not recommended unless if you're using a secrets vault. We'll look into this more when we integrate it into a DevOps server

provider "aws" {
  region     = "us-west-2"
  access_key = "my-access-key"
  secret_key = "my-secret-key" # Bad Practice
}

Creating an EC2 Instance

Last updated