Learn the basics of using terraform to manage your AWS infrastructure.
For a quick installation instructions, check out HashiCorp Learn
Chapters:
- 0:00 Intro
- 2:10 Project Setup
- 2:39 Setting up the project
- 3:57 Terraform CLI
- 5:46 EC2 Resource Block
- 7:38 terraform apply
- 8:55 terraform state
- 11:34 Security Group Resource
- 15:29 Idempotent
- 18:16 terraform destroy
- 19:20 Data Block
- 22:35 Review
Code:
https://github.com/Sam-Meech-Ward/intro-to-terraform
terraform {
  required_providers {
    aws = {
      source  = "hashicorp/aws"
      version = "~> 4.0"
    }
  }
}
# Configure the AWS Provider
provider "aws" {
  region = "us-west-2"
}
resource "aws_security_group" "app_sg" {
  name        = "app_sg"
  description = "allow on port 8080"
  ingress {
    from_port        = 8080
    to_port          = 8080
    protocol         = "tcp"
    cidr_blocks      = ["0.0.0.0/0"]
    ipv6_cidr_blocks = ["::/0"]
  }
  egress {
    from_port        = 0
    to_port          = 0
    protocol         = "-1"
    cidr_blocks      = ["0.0.0.0/0"]
    ipv6_cidr_blocks = ["::/0"]
  }
}
data "aws_ami" "app_ami" {
  most_recent      = true
  name_regex       = "cocktails-app-*"
  owners           = ["self"]
}
resource "aws_instance" "web_app" {
  instance_type          = "t2.micro"
  ami                    = data.aws_ami.app_ami.id
  vpc_security_group_ids = [aws_security_group.app_sg.id]
}
S3 and IAM with Terraform: https://sammeechward.com/s3-and-iam-with-terraform/ Cloud-init and Terraform with AWS: https://sammeechward.com/cloud-init-and-terraform-with-aws/