A Rock Solid, Modern Web Stack—Rails 5 API + ActiveAdmin + Create React App on Heroku

https://blog.heroku.com/a-rock-solid-modern-web-stack

Advertisements

Use Packer and Terraform create AWS EC2 instance

Packer

packer.json

{
  "variables": {
    "aws_access_key": "",
    "aws_secret_key": ""
  },
  "builders": [{
    "type": "amazon-ebs",
    "access_key": "{{user `aws_access_key`}}",
    "secret_key": "{{user `aws_secret_key`}}",
    "region": "ap-northeast-1",
    "source_ami": "ami-0d74386b",
    "instance_type": "t2.xlarge",
    "force_deregister": "true",
    "force_delete_snapshot": "true",
    "ssh_username": "ubuntu",
    "ami_name": "packer- {{timestamp}}"
  }],
  "provisioners": [{
    "type": "shell",
    "inline": [
      "sleep 30",
      "sudo apt-get update",
      "sudo apt-get install -y git"
    ]
  }]
}
$ packer validate packer.json
$ packer build \
    -var 'aws_access_key=XXX' \
    -var 'aws_secret_key=XXX' \
    packer.json

Terraform

terraform.tf

variable "aws_access_key" {}
variable "aws_secret_key" {}

provider "aws" {
  region = "ap-northeast-1"
  access_key = "${var.aws_access_key}"
  secret_key = "${var.aws_secret_key}"
}

resource "aws_instance" "hello" {
  ami = "ami-XXX" # Created by Packer above
  instance_type = "t2.xlarge"
  tags {
    Name = "HelloServer"
  }
  key_name = "XXX" # Make it from AWS console: EC2 Dashboard -> NETWORKING & SECURITY -> Key Pairs
}
$ terraform init
$ terraform plan
$ terraform apply