Skip to content

Instantly share code, notes, and snippets.

View AndrewBestbier's full-sized avatar

Andrew AndrewBestbier

  • McKinsey & Company
  • London
View GitHub Profile
Database:
Type: AWS::RDS::DBInstance # (1)
Properties:
VPCSecurityGroups:
- !Ref DbSecurityGroup # (2)
AllocatedStorage: "10"
DBSubnetGroupName: !Ref DbSubnetGroup # (3)
DBInstanceClass: "db.t2.micro"
Engine: "postgres"
MasterUsername: Username
AWSTemplateFormatVersion: 2010-09-09
Resources:
VPC:
Type: AWS::EC2::VPC
Properties:
CidrBlock: 10.0.0.0/16
PublicSubnetA:
Type: AWS::EC2::Subnet
provider "aws" {
version = "~> 2.0"
region = "eu-west-2" # Setting my region to London. Use your own region here
}
resource "aws_ecr_repository" "my_first_ecr_repo" {
name = "my-first-ecr-repo" # Naming my repository
}
resource "aws_ecs_cluster" "my_cluster" {
name = "my-cluster" # Naming the cluster
}
resource "aws_ecs_task_definition" "my_first_task" {
family = "my-first-task" # Naming our first task
container_definitions = <<DEFINITION
[
{
"name": "my-first-task",
"image": "${aws_ecr_repository.my_repo.repository_url}",
"essential": true,
"portMappings": [
{
resource "aws_ecs_task_definition" "my_first_task" {
family = "my-first-task" # Naming our first task
container_definitions = <<DEFINITION
[
{
"name": "my-first-task",
"image": "${aws_ecr_repository.my_first_ecr_repo.repository_url}",
"essential": true,
"portMappings": [
{
# General setup
provider "aws" {
version = "~> 2.0"
region = "eu-west-2" # Setting our region
}
# Providing a reference to our default VPC
resource "aws_default_vpc" "default_vpc" {
}
resource "aws_ecs_service" "my_first_service" {
name = "my-first-service" # Naming our first service
cluster = "${aws_ecs_cluster.my_cluster.id}" # Referencing our created Cluster
task_definition = "${aws_ecs_task_definition.my_first_task.arn}" # Referencing the task our service will spin up
launch_type = "FARGATE"
desired_count = 3 # Setting the number of containers we want deployed to 3
}
# Providing a reference to our default VPC
resource "aws_default_vpc" "default_vpc" {
}
# Providing a reference to our default subnets
resource "aws_default_subnet" "default_subnet_a" {
availability_zone = "eu-west-2a"
}
resource "aws_default_subnet" "default_subnet_b" {
resource "aws_ecs_service" "my_first_service" {
name = "my-first-service" # Naming our first service
cluster = "${aws_ecs_cluster.my_cluster.id}" # Referencing our created Cluster
task_definition = "${aws_ecs_task_definition.my_first_task.arn}" # Referencing the task our service will spin up
launch_type = "FARGATE"
desired_count = 3 # Setting the number of containers we want deployed to 3
network_configuration {
subnets = ["${aws_default_subnet.default_subnet_a.id}", "${aws_default_subnet.default_subnet_b.id}", "${aws_default_subnet.default_subnet_c.id}"]
assign_public_ip = true # Providing our containers with public IPs