caseybecking / 12345-aws-12345-martians-prod

Demo setup for training purposes.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

CircleCI

Martian Co

Making planets more betters.

Usage

This is a demo repo for training purposes. The prefered method of using this repo is to fork it so that you can edit and modify as you see fit.

Setup

You will need to have an up to date installation of Terrafrom before you begin working with this repo. Installation instructions can be found here: https://www.terraform.io/intro/getting-started/install.html

AWS Credentials

We will be using the AWS provider in order to deploy to and AWS account with terraform. Learn more about configuring this provider here: https://www.terraform.io/docs/providers/aws/

In order for this repo to function, you must export your AWS account credentials as environment variables:

export AWS_ACCESS_KEY_ID={your AWS Key here}
export AWS_SECRET_ACCESS_KEY={your AWS Secret here}
export AWS_SESSION_TOKEN={your AWS Session Token here}

You will need to modify the AWS Region and the allowed AWS accounts in the variables.tf file:

variable "aws_region" {
  default = ""
}

variable "account_ids" {
  type    = "list"
  default = ["000000000"]
}

You will need to set the aws_region to the region where you want to deploy resources, and set the account_ids to the account number for the AWS account you will be using. this is a list of ID's and can be set to more than one. This is a security feature that makes sure you dont accidentally apply the wrong terraform config to the wrong account.

Configuring Remote State

Prior to working with this repo, I would suggest getting familiar with terraform Remote states if you are note already. More information on them can be found here: Remote States

This repo also configures a remote backend for state storage in S3. You will need to perform the following steps before preforming a the terraform init command.

Create an s3 bucket using the bucket name configured in the terraform config block found in the main.tf:

terraform {
  backend "s3" {
    bucket  = "martian-prod-tfstate"
    key     = "terraform.tfstate"
    encrypt = "true"
  }
}

the default bucket name in this repo is martian-prod-tfstate. Since AWS S3 bucket names are globally unique, you will need to change this to a unique name in your account. Enabling Encryption and Versioning on the bucket is highly recomended.

Initialize

After setting your credentials and creating the s3 bucket in your AWS Account, you should be able to initialize your terraform repo. Run terraform init from the root directory of this repo. You should be prompted to enter information that was excluded from the terraform configuration block, this will include the AWS Region that you would like to use for the terraform backend (where your state file is located).

You will need to understand the difference between the init and apply commands. You can find more details on this page: https://www.terraform.io/intro/getting-started/build.html

After that initialization is complete, you should be ready to begin working with terraform!

About

Demo setup for training purposes.


Languages

Language:HCL 97.8%Language:Shell 2.2%