Skip to content

Instantly share code, notes, and snippets.

@EricLondon
Created October 18, 2018 10:34
Show Gist options
  • Select an option

  • Save EricLondon/91b4c57095594549e31e6de2904d1012 to your computer and use it in GitHub Desktop.

Select an option

Save EricLondon/91b4c57095594549e31e6de2904d1012 to your computer and use it in GitHub Desktop.

Revisions

  1. EricLondon created this gist Oct 18, 2018.
    1 change: 1 addition & 0 deletions .terraform-version
    Original file line number Diff line number Diff line change
    @@ -0,0 +1 @@
    0.11.8
    19 changes: 19 additions & 0 deletions main.tf
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,19 @@
    terraform {
    required_version = "0.11.8"

    backend "s3" {
    bucket = ""
    key = ""
    profile = ""
    region = ""
    }
    }

    provider "aws" {
    profile = "${var.aws_profile}"
    region = "${var.aws_region}"
    shared_credentials_file = "${var.aws_credentials_file}"
    version = "1.37.0"
    }

    data "aws_caller_identity" "current" {}
    30 changes: 30 additions & 0 deletions provision.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,30 @@
    #!/usr/bin/env bash

    : "${AWS_PROFILE:=some-aws-profile-name}"
    : "${AWS_REGION:=us-east-1}"
    : "${STATE_BUCKET:=some-s3-state-bucket}"
    : "${STATE_KEY:=some-s3-state-path/terraform/base.tfstate}"

    action="$1"
    TFENV=$(which tfenv)
    if [ $? -eq 0 ]; then
    $TFENV install $(cat .terraform-version)
    cat .terraform-version | xargs $TFENV use
    fi

    rm -f *.tfstate
    rm -rf ./.terraform

    terraform init \
    -force-copy \
    -backend=true \
    -backend-config "bucket=${STATE_BUCKET}" \
    -backend-config "key=${STATE_KEY}" \
    -backend-config "profile=${AWS_PROFILE}" \
    -backend-config "region=${AWS_REGION}"

    terraform plan

    if [ "$action" == "apply" ]; then
    terraform apply -auto-approve
    fi
    14 changes: 14 additions & 0 deletions variables.tf
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,14 @@
    variable "aws_region" {
    type = "string"
    default = "us-east-1"
    }

    variable "aws_profile" {
    type = "string"
    default = ""
    }

    variable "aws_credentials_file" {
    type = "string"
    default = "~/.aws/credentials"
    }