Skip to content

Instantly share code, notes, and snippets.

View estenssoros's full-sized avatar

Sebastian Estenssoro estenssoros

View GitHub Profile
@estenssoros
estenssoros / route53.tf
Created September 20, 2023 09:39
Docker, ECR, Elastic Beanstalk, & Terraform route53.tf
locals {
api_name = var.environment == "prod" ? "api" : "api-${var.environment}"
}
resource "aws_acm_certificate" "cert" {
domain_name = var.domain_name
validation_method = "DNS"
subject_alternative_names = ["www.${var.domain_name}"]
}
@estenssoros
estenssoros / s3.tf
Created September 20, 2023 09:10
Docker, ECR, Elastic Beanstalk, & Terraform s3.tf
resource "random_pet" "ebs_bucket_name" {}
resource "aws_s3_bucket" "ebs" {
bucket = "${local.common_name}-${random_pet.ebs_bucket_name.id}"
}
data "template_file" "ebs_config" {
template = file("${path.module}/Dockerrun.aws.json.tpl")
vars = {
image_name = var.acr_repository_url
@estenssoros
estenssoros / Dockerrun.aws.json.tpl
Created September 20, 2023 09:08
Docker, ECR, Elastic Beanstalk, & Terraform Dockerrun.aws.json.tpl
{
"AWSEBDockerrunVersion": "1",
"Image": {
"Name": "${image_name}",
"Update": "true"
},
"Ports": [
{
"ContainerPort": "1323",
"HostPort": "1323"
@estenssoros
estenssoros / Dockerfile
Created September 20, 2023 09:06
Docker, ECR, Elastic Beanstalk, & Terraform Dockerfile
FROM golang:1.20 AS builder
WORKDIR /go/src/github.com/path/to/your/code
COPY go.mod go.mod
COPY go.sum go.sum
RUN go mod download
COPY main.go main.go
@estenssoros
estenssoros / docker-push.sh
Last active September 20, 2023 09:04
Docker, ECR, Elastic Beanstalk, & Terraform docker-push.sh
#!/bin/bash
docker build -t $ECR_URL/$ECR_NAME:latest
aws ecr get-login-password --region $REGION | docker login --username AWS --password-stdin $ECR_URL
docker push $ECR_URL/$ECR_NAME:latest
@estenssoros
estenssoros / ecr.tf
Created September 20, 2023 08:59
Docker, ECR, Elastic Beanstalk, & Terraform ecr.tf
resource "aws_ecr_repository" "app" {
name = local.common_name
image_tag_mutability = "MUTABLE"
image_scanning_configuration {
scan_on_push = true
}
}
@estenssoros
estenssoros / certificates.tf
Created September 20, 2023 07:40
Docker, ECR, Elastic Beanstalk, & Terraform certificates.tf
resource "aws_acm_certificate" "cert" {
domain_name = var.domain_name
validation_method = "DNS"
subject_alternative_names = ["www.${var.domain_name}"]
}
data "aws_route53_zone" "zone" {
name = var.route53_zone_name
private_zone = false
}
@estenssoros
estenssoros / security_groupts.tf
Created September 20, 2023 07:38
Docker, ECR, Elastic Beanstalk, & Terraform security_groups.tf
data "http" "myip" {
url = "http://ipv4.icanhazip.com"
}
resource "aws_security_group" "ebs" {
name = "${local.common_name}-ebs"
vpc_id = var.vpc_id
# for ssh
ingress {
from_port = 22
@estenssoros
estenssoros / route53.tf
Last active September 20, 2023 07:38
Docker, ECR, Elastic Beanstalk, & Terraform route53.tf
locals {
api_name = var.environment == "prod" ? "api" : "api-${var.environment}"
}
module "certificate" {
source = "../certificates"
domain_name = "${local.api_name}.${var.domain_name}"
route53_zone_name = var.route53_zone_name
region = "us-west-2"
}
@estenssoros
estenssoros / instance_profile.tf
Created September 20, 2023 07:35
Docker, ECR, Elastic Beanstalk, & Terraform instance_profile.tf
resource "aws_iam_role" "ebs" {
name = "${local.common_name}-ebs"
assume_role_policy = <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Action": "sts:AssumeRole",
"Principal": {