Giter Club home page Giter Club logo

terraform-starter-kit's Introduction

Terraform
Terraform Starter Kit

The basic building blocks for configuring a cloud infrastructure inside of a monorepo project using Terraform.

image

Requirements

Initial Setup

How to install Terraform CLI on macOS?
$ brew tap hashicorp/tap
$ brew install hashicorp/tap/terraform
$ brew update
$ brew upgrade hashicorp/tap/terraform
$ yarn tf -version
How to create Google Cloud Platform projects?

Simply navigate to Google Cloud Resource Manager and create two GCP projects for both test (QA) and prod (production) environments, e.g. "example" and "example-test".

Fore more information visit https://cloud.google.com/resource-manager/docs/creating-managing-projects

How to configure Terraform Cloud workspaces?
  1. Sign in to Terraform Cloud dashboard.
  2. Create or join an organization.
  3. Create two workspaces — app-test and app-prod for test/QA and production environments.
  4. In each of these workspaces create an environment variable called GOOGLE_CREDENTIALS with the value containing JSON key of a GCP service account. Note, this GCP service account needs to have Owner or Editor + Service Usage Admin roles.

For more information visit https://registry.terraform.io/providers/hashicorp/google/latest/docs/guides/provider_reference

How to authenticate Terraform CLI in Terraform Cloud?
  1. Create a personal or team API Token via Terraform Cloud dashboard → Settings.
  2. Save API token to the .terraformrc file in root of the project:
credentials "app.terraform.io" {
  token = "xxxxxx.atlasv1.zzzzzzzzzzzzz"
}

NOTE: This would allow to using different Terraform credentials per software project if you want to.

Customize the project
  1. Run yarn install to bootstrap .terraformrc and infra/overrides.tf files
  2. Create a Terraform API Token and save it to .terraformrc file
  3. Update Terraform Cloud organization name in infra/backend.tf
  4. Update other variables in the infra/locals.tf file
  5. Ensure that Terraform Cloud workspaces exist and have all the required environment variables

Getting Started

Once the initial configuration steps are done (see infra/backend.tf, infra/locals.tf), you should be able to run Terraform CLI commands either directly or via a Yarn-based wrapper:

$ terraform -chdir=infra init -upgrade
$ terraform -chdir=infra plan
$ terraform -chdir=infra apply -auto-approve

Note that it uses test as the default workspace environment defined in VSCode's integrated terminal settings.

To use a different environment set the TF_WORKSPACE environment variable:

$ TF_WORKSPACE=prod terraform -chdir=infra plan
$ TF_WORKSPACE=prod terraform -chdir=infra apply -auto-approve

Alternatively, use the wrapper CLI:

# Uses `test` environment by default
$ yarn plan
$ yarn apply -auto-approve

# Explicitly setting `prod` as the selected workspace environment
$ yarn plan --env=prod
$ yarn apply --env=prod -auto-approve

Fore more information visit learn.hashicorp.com/terraform or join the discussion on Discord.

Backers

              

Related Projects

How to Contribute

Anyone and everyone is welcome to contribute. Submit a pull request (PR) or send me a message on Discord.

License

Copyright © 2022-present Kriasoft. This source code is licensed under the MIT license found in the LICENSE file.


Made with ♥ by Konstantin Tarkus (@koistya, blog) and contributors.

terraform-starter-kit's People

Contributors

koistya avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

deniskin82

terraform-starter-kit's Issues

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.