Coder Social home page Coder Social logo

terraform-onboarding's Introduction

i18n

日本語版はこちらになります

What's Terraform

Terraform is an IaC(infrastructure as code) software tool, which created by HashiCorp.
Listed as a recommended tool for Infrastructure Provisioning at DevOps Roadmap,
Terraform is a perfect tool for those engaged in occupations such as IT infrastructure engineer, DevOps engineer, and SRE.

Getting Started

  • Based on the content for help junior SRE onboarding used in-house. -> Drecom
  • A practice repository for using terraform via hands-on to show you how terraform working and what's Drecom-style.
  • Please note that the Drecom-style terraform usage patterns are included, these may not be best practice but we use them for our daily work.
  • AWS Resources used:
    • IAM
    • S3
    • Api-gateway
    • Lambda function
    • ECR
    • App Runner

Who might be interested

  • Terraform beginners
  • Junior DevOps engineers
  • Junior SREs
  • etc.

Prerequisite

  • Terminal application(e.g. iTerm2, wsl2)
  • curl
  • AWS account(with access key & secret access key)
  • A modern browser
  • Terraform(0.12+)
    • Used Ver. 1.0.0 here
  • docker

Usage

  • Set your AWS Credentials into a example file
    • service_account_id = ""
    • aws_access_key = ""
    • aws_secret_key = ""
    • region = "ap-northeast-1"
$ mv terraform.tfvars.example terraform.tfvars
$ vi terraform.tfvars
  • To prevent the resources of each environment (staging, production, etc.) from being influenced by each other, Drecom use terraform workspace to get it done.
  • Firstly, make a workspace called 'common' to build IAM, S3 bucket resources to your AWS env, via terraform plan & apply
  • Secondly, make a workspace called 'system' to build lambda-function, api-gateway, ecr resources to your AWS env, via terraform plan & apply
  • Finally, make a workspace called 'production' to build apprunner resources to your AWS env, via terraform plan & apply
    • Be free to add other .tf files to see how to build others resources.
    • Discussion with your partner based on issues, and see what you can do togerther.
  • Don't forget to clear up all AWS resources after workshop, or you may recieve a surprise bill from AWS. :)

Workshop

You may found the tfstate files are stored here in the local environment,
but the truth is we do all that stuff via CI tool(gitlab-ci, in our case),
since it has some sensitive information that not suitable to be published, so let's do it locally here.

1)Build common resources

$ git clone [email protected]:drecom/terraform-onboarding.git
$ cd terraform-onboarding
$ mv terraform.tfvars.example terraform.tfvars
$ vi terraform.tfvars
# Several variables are defined by variables.tf   
# Before running other command, you may take a look at it.  
$ vi variables.tf
$ terraform init
# show all existing workspaces
$ terraform workspace list
$ terraform workspace select common
$ terraform plan
$ terraform apply

2)Build system resources

2-1)Upload lambda function to S3 bucket

See drecom/demo-box's README for more details.

2-2)Build resources

$ terraform workspace select system
$ terraform plan
$ terraform apply

2-3)Say hello to lambda function

# on workspace system
$ terraform output | grep deployment-invoke-url | awk '{print $3}' | xargs curl
{"drecom": "with entertainment <TIME_NOW+0900>"}

3)Build production resources

3-1) Push application image to AWS ECR

See sample-app's README for more details.

3-2) Build resources

$ terraform workspace select production
$ terraform plan
# It usually takes several minutes
$ terraform apply

3-3) Access the output's URL via browser

  • apprunner-url

3-option) Create an EC2 instance and install nginx

$ terraform workspace select production
# switch “production = false” to “production = true”
$ vi ec2_variables.tf
$ terraform plan
# It usually takes several minutes
$ terraform apply
# until instance healthy(about 3min)
# check it via AWS console
$ terraform output | grep practice-ec2-public-dns | awk '{print $3}' | xargs curl

Don't forget to clear up resources after workshop

$ terraform workspace select production
$ terraform destroy
$ terraform workspace select system
$ terraform destroy
$ terraform workspace select common
$ terraform destroy

Tips

  • We use some runtime manager to help us handling different versions of terraform. (e.g.

terraform-onboarding's People

Contributors

kuritan avatar sasa-d-soni avatar

Stargazers

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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

Forkers

sasa-d-soni

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.