Skip to content

Instantly share code, notes, and snippets.

View samloh84's full-sized avatar

Samuel Loh Yin Kang samloh84

View GitHub Profile
@samloh84
samloh84 / tf.sh
Last active November 8, 2022 01:45
Terraform Bash script
#!/bin/bash
set -euo pipefail
export DEBUG="${DEBUG:-0}"
export RC_FILES="${RC_FILES:-}"
export TF_HTTP_BACKEND_GITLAB="${TF_HTTP_BACKEND_GITLAB:-1}"
if [[ "${DEBUG}" -eq 1 ]]; then
set -x
#!/usr/bin/bash
set -Eeuxo pipefail
git config --global user.name "Samuel Loh"
git config --global user.email "samuel.loh.yk@gmail.com"
git config user.email "samuel_loh@tech.gov.sg"
@samloh84
samloh84 / Makefile
Created October 6, 2021 00:58
AWS ECR Terraform + Docker Makefile
SHELL := /bin/bash
.SHELLFLAGS := -ec
.PHONY: apply destroy refresh output
TERRAFORM_TFVARS_FILE_PATTERNS := *.tfvars
define _LOAD_AWSRC :=
if [[ -f "~/.awsrc" ]]; then \
source "~/.awsrc"; \
@samloh84
samloh84 / production-grade-checklist.md
Last active July 27, 2021 07:42
production-grade-checklist.md
Task Description Example Tools
Install Install the software binaries and all dependencies. Bash, Chef, Ansible, Puppet
Configure Configure the software at runtime: e.g. configure port settings, file paths, users, leaders, followers, replication, etc. Bash, Chef, Ansible, Puppet
Provision Provision the infrastructure: e.g. EC2 instances, load balancers, network topology, security groups, IAM permissions, etc. Terraform, CloudFormation
Deploy Deploy the service on top of the infrastructure. Roll out updates with no downtime: e.g. blue-green, rolling, canary deployments. Scripts, Orchestration tools (ECS, K8S, Nomad)
Security Encryption in transit (TLS) and on disk, authentication, authorization, secrets management, server hardening ACM, EBS Volumes, Cognito, Vault, CiS
Monitoring Availability metrics, business metrics, app metrics, server metrics, events, observability, tracing, alerting. CloudWatch, DataDog, New Relic, Honeycomb
Logs Rot
@samloh84
samloh84 / getMasExchangeRate.js
Created May 12, 2021 02:33
Get MAS Exchange Rate
const luxon = require('luxon');
const DateTime = luxon.DateTime;
const _ = require('lodash');
const axios = require('axios');
const qs = require('qs');
let getMasExchangeRate = function (date) {
if (_.isNil(date)) {
date = DateTime.now();
}
#!/bin/bash
AWS_PROFILE="${AWS_PROFILE:-}"
AWSRC_CACHE_DIR="~/.aws/.awsrc"
AWS_PROFILE_CACHE_JSON="${AWSRC_CACHE_DIR}/${AWS_PROFILE}.json"
function get-session-token() {
AWS_MFA_SERIAL=$(aws --profile ${AWS_PROFILE} configure get mfa_serial)
@samloh84
samloh84 / .azurerc
Created July 6, 2020 02:57
.azurerc
#!/bin/bash
ARM_TENANT_ID="${ARM_TENANT_ID:-}"
ARM_SUBSCRIPTION_ID="${ARM_SUBSCRIPTION_ID:-}"
ARM_SERVICE_PRINCIPAL_CREDENTIALS_PATH="${HOME}/.azure/terraform_service_principal_credentials.json"
AZURE_LOGGED_IN=0
AZURE_ACCESS_TOKEN=$(az account get-access-token --subscription "${ARM_SUBSCRIPTION_ID}")
@samloh84
samloh84 / gist:4d9faca52a47a1c143b935b6c4cd2e9f
Created May 23, 2020 08:38
Logos for Commonly Used Tools
https://www.docker.com/company/newsroom/media-resources
https://www.hashicorp.com/brand
https://github.com/logos
https://github.com/kubernetes/kubernetes/tree/master/logo
https://www.ansible.com/logos
https://git-scm.com/downloads/logos
https://about.gitlab.com/press/press-kit/
@samloh84
samloh84 / git-chmod.cmd
Created May 18, 2020 04:14
Chmod git on windows
for /f %G in ('dir /b /s *.sh') do (git update-index --chmod=+x %G)
import boto3
client = boto3.client('route53')
def delete_zone(zone_id):
""" List all records and deletes non SOA/NS records, before deleting the zone
"""
record_sets = client.list_resource_record_sets(HostedZoneId=zone_id)
# print(record_sets)