Skip to content

Instantly share code, notes, and snippets.

View endofcake's full-sized avatar
🐢
slow to respond

Alexander Savchuk endofcake

🐢
slow to respond
  • Wellington, New Zealand
View GitHub Profile
@endofcake
endofcake / asg.tf
Last active August 20, 2018 23:54
Blue/Green ASG rollout
resource "aws_autoscaling_group" "worker" {
# Force a redeployment when launch configuration changes.
# This will reset the desired capacity if it was changed due to
# autoscaling events.
name = "${aws_launch_configuration.worker.name}-asg"
min_size = 10
desired_capacity = 15
max_size = 25
health_check_type = "EC2"
@endofcake
endofcake / launch_config.tf
Created August 20, 2018 01:46
Creating a launch configuration in Terraform
resource "aws_launch_configuration" "worker" {
# Launch Configurations cannot be updated after creation with the AWS API.
# In order to update a Launch Configuration, Terraform will destroy the
# existing resource and create a replacement.
#
# We're only setting the name_prefix here,
# Terraform will add a random string at the end to keep it unique.
name_prefix = "worker-"
image_id = "${data.aws_ami.amazon_linux.id}"
@endofcake
endofcake / boxstarter.ps1
Created July 24, 2018 10:51 — forked from jessfraz/boxstarter.ps1
Boxstarter Commands for a new Windows box.
# Description: Boxstarter Script
# Author: Jess Frazelle <jess@linux.com>
# Last Updated: 2017-09-11
#
# Install boxstarter:
# . { iwr -useb http://boxstarter.org/bootstrapper.ps1 } | iex; get-boxstarter -Force
#
# You might need to set: Set-ExecutionPolicy RemoteSigned
#
# Run this boxstarter by calling the following from an **elevated** command-prompt:
@endofcake
endofcake / sample.yaml
Created July 18, 2018 01:28
Test security group
AWSTemplateFormatVersion: '2010-09-09'
Resources:
VPC:
Type: "AWS::EC2::VPC"
Properties:
CidrBlock: 10.0.0.0/16
SecurityGroup:
Type: "AWS::EC2::SecurityGroup"
@endofcake
endofcake / service.tf
Created May 30, 2018 03:09
Ignore desired count to avoid scale ins during infrastructure deployments
resource "aws_ecs_service" "web" {
# Do not reset desired count if it was changed due to autoscaling
lifecycle {
ignore_changes = ["desired_count"]
}
}
@endofcake
endofcake / service.tf
Created May 30, 2018 03:07
Use current ACTIVE task in ECS service definition
# Get the current ACTIVE revision in ECS task family
data "aws_ecs_task_definition" "web" {
task_definition = "${module.web.ecs_task_family}"
}
resource "aws_ecs_service" "web" {
# Use the latest task revision - either the existing one, or the newly created
# if the task was updated.
task_definition = "${max("${aws_ecs_task_definition.web.revision}", "${var.ecs_task_current_revision}")}"
}
@endofcake
endofcake / task.tf
Last active June 8, 2018 00:25
Use current image tag as input parameter to the ECS task
task_variables {
app = "${var.app_name}"
image = "${module.ecr.repository_url}:${lookup(data.external.active_image_versions.result, var.app_name, "latest")}"
}
@endofcake
endofcake / data_source.tf
Created May 30, 2018 03:05
External data source for Terraform that provides tags for all images in an ECS task definition
# Use current image versions to avoid surreptitious app deployments
data "external" "active_image_versions" {
program = ["python", "/scripts/get_image_tags.py"]
query = {
cluster_name = "${data.terraform_remote_state.ecs.ecs_cluster_id}"
service_name = "${var.app_name}"
}
}
@endofcake
endofcake / run.sh
Created May 28, 2018 22:59
Run an ECS task and grab its output
#!/bin/bash
set -euo pipefail
# some env vars here
STARTED_BY="$(date +"%T") - $USERNAME"
AWS_DEFAULT_REGION="${REGION}"
TASK_ID=""
@endofcake
endofcake / Jenkinsfile
Last active May 27, 2018 04:20
Using a shared library to reduce the boilerplate code in our pipeline definitions
#!/usr/bin/env groovy
infraPipeline()