Skip to content

Latest commit

 

History

History
280 lines (200 loc) · 5.82 KB

deck.mdx

File metadata and controls

280 lines (200 loc) · 5.82 KB

import { CodeSurfer, CodeSurferColumns, Step, } from "code-surfer"; import { github, vsDark } from "@code-surfer/themes";

import "prismjs/components/prism-hcl" import "prismjs/components/prism-bash"

export const theme = vsDark;

Hello 👋, its over

This is about Terraform : pitch, advantages & usages


What is Terraform

  • OpenSource
  • Modular
  • Infrastructure-as-Code (HCL Syntax)
  • NOT configuration management

What is Terraform

The Challenge

Manual provisioning is slow, error-prone and difficult to scale.

  • Low agility : manual workflow, GUI, ...
  • High cost : cloud waste (over provisionning)
  • High risk : human operator

What is Terraform

The Solution

Automate provisioning using infrastructure-as-code

  • Increaded agility : reduce time to provision
  • Control cost : scale as you really need
  • Lower risk : code reviews & embed provisioning guardrails

Advantages

  • Portability / Compatibility
  • Dry runs
  • Immutable infrastructure (avoid conf. drift)

Drawbacks

  • Stateful (sync.)
  • Existing stack
  • Secret management

Terraform & HashiCorp ecosystem

hashicorp suite


variable "access_key" {}
variable "secret_key" {}

provider "aws" {
    access_key = var.access_key
    secret_key = var.secret_key
    region = "eu-west-3"
}

data "aws_ami" "ubuntu" {
  most_recent = true

  filter {
    name   = "name"
    values = ["ubuntu/images/hvm-ssd/ubuntu-trusty-14.04-amd64-server-*"]
  }
}

resource "aws_instance" "web" {
  ami           = data.aws_ami.ubuntu.id
  instance_type = "t2.micro"

  tags = {
    Name = "ASampleTest"
  }
}

terraform init -- fetch plugin & other TF things
terraform plan -- build the execution plan & display
terraform apply -- build exec. plan & prompt to apply
terraform destroy -- danger zone, just drop everything

variable "netlify_token" {
  description = "The netlify application token to authorize against provider"
}

variable "github_token" {
  description = "The github auth token"
}

variable "github_organization" {
  default = "marmorag"
}
netlify_token = "<DA SECRET>"
github_token = "<DA BIGGER SECRET>"
provider "netlify" {
  token = var.netlify_token
}

provider "github" {
  token        = var.github_token
  organization = var.github_organization
}
provider "netlify" {
  token = var.netlify_token
}

provider "github" {
  token        = var.github_token
  organization = var.github_organization
}

resource "netlify_deploy_key" "key" {}

resource "github_repository_deploy_key" "key" {
  title      = "Netlify"
  repository = "terraform-presentation"
  key        = netlify_deploy_key.key.public_key
  read_only  = false
}
provider "netlify" {
  token = var.netlify_token
}

provider "github" {
  token        = var.github_token
  organization = var.github_organization
}

resource "netlify_deploy_key" "key" {}

resource "github_repository_deploy_key" "key" {
  title      = "Netlify"
  repository = "terraform-presentation"
  key        = netlify_deploy_key.key.public_key
  read_only  = false
}

resource "netlify_site" "tf-presentation" {
  name = "tf-presentation"

  repo {
    repo_branch = "master"
    command = "yarn build"
    deploy_key_id = netlify_deploy_key.key.id
    dir = "public"
    provider = "github"
    repo_path = "marmorag/terraform-presentation"
  }
}
provider "netlify" {
  token = var.netlify_token
}

provider "github" {
  token        = var.github_token
  organization = var.github_organization
}

resource "netlify_deploy_key" "key" {}

resource "github_repository_deploy_key" "key" {
  title      = "Netlify"
  repository = "terraform-presentation"
  key        = netlify_deploy_key.key.public_key
  read_only  = false
}

resource "netlify_site" "tf-presentation" {
  name = "tf-presentation"

  repo {
    repo_branch = "master"
    command = "yarn build"
    deploy_key_id = netlify_deploy_key.key.id
    dir = "public"
    provider = "github"
    repo_path = "marmorag/terraform-presentation"
  }
}

resource "github_repository_webhook" "webhook" {
  repository = "terraform-presentation"
  name       = "web"
  events     = ["delete", "push", "pull_request"]

  configuration {
    content_type = "json"
    url          = "https://api.netlify.com/hooks/github"
  }

  depends_on = [netlify_site.tf-presentation]
}

docs:
Terraform
made with:
MDX Deck
CodeSurfer