Coder Social home page Coder Social logo

terraform_aws's Introduction

terraform_aws

Terraform AWS templates

Terraform

File Organization

- <env-group>
  - <account>
    - <region>
      - <service>
        - <application>
          - <terraform-templates (*.tf files)>
          - main.tf
          - state.tf
          - providers.tf
          - data.tf (- data can be further split into multiple files for better organization)

State Management

Sample Template

terraform {
  backend "s3" {
    bucket         = "terraform-states"
    key            = "<account>/<region>/<service>/<application>/terraform.tfstate"
    dynamodb_table = "TerraformState"
    encrypt        = true
    region         = "us-east-1"
    profile        = "<profile>"
  }
}

IAM Roles and Profiles

Setting up AWS resources require administrative permissions to perform most of the actions. It is important to make sure the credentials are not hardcoded and placed in any text files.

profile names

  • dev
  • prod
  • qa

Running Terraform template from root directory

Terraform provides -chdir option to run a terraform template from sub directory.

Example:

terraform -chdir=aws/tst/tst14/us-east-1/lambda/tst-module/ plan

Running Terraform using Docker container

  • Requires .aws config directory on the local system.
  • Should run from terraform root directory so that modules directory path resolves correctly.
  • Should run with -chdir to run point to right Terraform templates

Create shell script for re-use

Create a shell script (dt.sh) with the below content and make sure the directory is mapped in PATH variable.

#!/bin/bash

XUID=$(id -u)
GID=$(id -g)

docker run --rm -it \
    -u $XUID:$GID \
    -v ~/.aws/:/.aws/ \
    -v ~/.local/bin/:/.local/bin/ \
    -v "$PWD":/code/ \
    -w /code/ \
    --platform linux/amd64 \
    hashicorp/terraform $@

Run the terraform command.

Assumes that script name is dt.sh

dt.sh -chdir=aws/tst/tst14/us-east-1/lambda/tst-module/ plan

terraform_aws's People

Contributors

jonathanphillips avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.