Makefile commands to create Terraform Backend resources

Makefile commands to init, plan and apply configuration:

# makefile
plan:
	cd infra && terraform plan
 
apply:
	cd infra && terraform apply
 
apply-auto-approve:
	cd infra && terraform apply --auto-approve

Terraform block config then looks like this:

# main.tf
terraform {
  backend "s3" {
    encrypt = true
  }
 
  required_providers {
    aws = {
      source  = "hashicorp/aws"
      version = "~> 4.0"
    }
  }
  required_version = ">= 1.4.0"
}

In variables.tf I set a default value for aws_profile:

# variables.tf
variable "aws_profile" {
  description = "AWS profile to use for deployment."
  type        = string
  default     = null
}