Working with Terraform on a daily basis I feel it can be a good idea to share some small tips I have. Let me start with this one.

Initializing remote state S3 backend is pretty fast operation, but it can be even faster if you disable all unnecessary checks:

terraform {
  backend "s3" {
    encrypt        = true
    region         = "..."
    key            = "..."
    bucket         = "..."
    dynamodb_table = "..."

    skip_metadata_api_check     = true
    skip_region_validation      = true
    skip_credentials_validation = true
  }
}

provider "aws" {
  region = "..."
  skip_requesting_account_id  = true # this can be tricky
  skip_get_ec2_platforms      = true
  skip_metadata_api_check     = true
  skip_region_validation      = true
  skip_credentials_validation = true
}

Notes:

  1. Skipping region validation on S3 backends became available in Terraform 0.11.2 (see PR): skip_region_validation = true

I didn’t spend too much time measuring time difference, but it certainly reduces time required for initializing S3 backend by 20%. This is not a big deal if you have just a few remote states and you run terraform init seldom.

I usually use Terragrunt with lots of isolated state files and run terragrunt validate-all on CI. It saves second here, second there.

More importantly skipping these checks will allow you to run terraform plan without having internet access (on the plane, for eg).

Follow me on Twitter — @antonbabenko


Read more:

  1. AWS provider
  2. S3 backend configuration