Skip to content

Instantly share code, notes, and snippets.

@jandudulski
Created February 22, 2018 10:08
Show Gist options
  • Save jandudulski/6a92f07d172a6cd4f5140d9d9106e3f8 to your computer and use it in GitHub Desktop.
Save jandudulski/6a92f07d172a6cd4f5140d9d9106e3f8 to your computer and use it in GitHub Desktop.
Chicken or the Egg. Terraform’s Remote Backend
# this won't work
terraform {
backend "s3" {
bucket = "${var.bucket}"
dynamodb_table = "${var.dynamodb_table}"
# reminder of the config...
}
}
# setup/main.tf
provider "aws" {
profile = "${var.profile}"
region = "${var.region}"
}
module "backend" {
source = "../modules/backend"
# configuration goes here
}
#!/usr/bin/env bash
# Initialize the local Terraform backend
terraform init setup
# Set up remote backend infrastructure
terraform apply -var-file=backend.tfvars setup
# Initialize the remote Terraform backend and migrate local to remote
terraform init -backend-config=backend.tfvars base
- backend.tfvars
- setup
-- main.tf
-- variables.tf
- base
-- main.tf (symlink to ../setup/main.tf)
-- variables.tf (symlink to ../setup/variables.tf)
-- backend.tf (symlink to ../common/backend.tf)
- common
-- backend.tf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment