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;
This is about Terraform : pitch, advantages & usages
- OpenSource
- Modular
- Infrastructure-as-Code (HCL Syntax)
- NOT configuration management
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
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
- Portability / Compatibility
- Dry runs
- Immutable infrastructure (avoid conf. drift)
- Stateful (sync.)
- Existing stack
- Secret management
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