Skip to content

Instantly share code, notes, and snippets.

View akskap's full-sized avatar
🎯
Focusing

Akshay Kapoor akskap

🎯
Focusing
View GitHub Profile
@akskap
akskap / iam-policy-cross-account-bucket-access.json
Created May 22, 2020 14:18
IAM Policy Cross Account S3 Bucket Access
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "list-s3-resources",
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::<requester_acccount_id>:role/access-s3-objects"
},
"Resource": "arn:aws:s3:::my-test-bucket",
@akskap
akskap / gitlab-runner-autoscaling-group-schedules.tf
Created April 17, 2020 10:03
Gitlab Runner Autoscaling Group Shutdown/Startup
resource "aws_autoscaling_schedule" "gitlab_asg_shutdown_schedule" {
autoscaling_group_name = "${aws_autoscaling_group.gitlab_runner_autoscaling_group.name}"
scheduled_action_name = "gitlab-runner-cluster-shutdown"
recurrence = "30 19 * * Mon-Fri"
min_size = 0
max_size = 0
desired_capacity = 0
}
resource "aws_autoscaling_schedule" "gitlab_asg_startup_schedule" {
@akskap
akskap / gitlab_runner_autoscalinggroup.tf
Created April 17, 2020 09:54
Gitlab Runner Autoscaling Group
resource "aws_autoscaling_group" "gitlab-runner-autoscaling-group" {
name_prefix = "gitlab-runner-scaling-group"
desired_capacity = "${var.desired_capacity}"
max_size = "${var.max_instance_size}"
min_size = "${var.min_instance_size}"
vpc_zone_identifier = "${var.private_subnet_ids}"
launch_configuration = "${aws_launch_configuration.gitlab_runner_launch_config.name}"
lifecycle {
@akskap
akskap / terraform_launch_config_gitlab.tf
Last active April 17, 2020 09:50
Terraform Launch Config Gitlab
resource "aws_launch_configuration" "gitlab_runner_launch_config" {
name_prefix = "${var.application_name}-launch-config"
associate_public_ip_address = false
image_id = "${var.launch_config_ami_id}"
instance_type = "${var.launch_config_instance_type}"
}
@akskap
akskap / packer_provision.sh
Created April 16, 2020 23:47
Packer Provisioning Script
#!/usr/bin/env bash
# Update apt packages
set -ex
sudo yum update && sudo yum install -y wget
# Installing and configuring Gitlab Runner
sudo wget -O /usr/local/bin/gitlab-runner https://gitlab-runner-downloads.s3.amazonaws.com/latest/binaries/gitlab-runner-linux-amd64
sudo chmod +x /usr/local/bin/gitlab-runner
sudo useradd --comment 'GitLab Runner' --create-home gitlab-runner --shell /bin/bash
@akskap
akskap / packer_ami_build.json
Created April 16, 2020 23:21
Packer AMI Builder Template
{
"variables": {
"region": "eu-central-1"
},
"builders": [
{
"profile": "<AWS_CRED_PROFILE_NAME>",
"ami_name": "Gitlab-Runner-{{timestamp}}",
"instance_type": "t2.micro",
"vpc_id": "<VPC_ID>",
@akskap
akskap / logger-functions-bash.sh
Created October 12, 2019 06:36
Logger Functions in bash
#!/usr/bin/env bash
function __msg_error() {
[[ "${ERROR}" == "1" ]] && echo -e "[ERROR]: $*"
}
function __msg_debug() {
[[ "${DEBUG}" == "1" ]] && echo -e "[DEBUG]: $*"
}
@akskap
akskap / custom-exit-codes-bash.sh
Last active June 4, 2022 00:42
Custom Exit Codes in Bash
#!/usr/bin/env bash
SUCCESS=0
FILE_NOT_FOUND=240
DOWNLOAD_FAILED=241
function read_file() {
if ${file_not_found}; then
return ${FILE_NOT_FOUND}
fi
@akskap
akskap / set-builtins-bash.sh
Last active June 4, 2022 21:18
Set builtins in bash
#!/usr/bin/env bash
set -o errexit
set -o nounset
set -o pipefail
function print_var() {
echo "${var_value}"
}
@akskap
akskap / trap-handlers-bash.sh
Last active May 4, 2020 13:51
Trap handling in bash
function handle_exit() {
// Add cleanup code here
// for eg. rm -f "/tmp/${lock_file}.lock"
// exit with an appropriate status code
}
// trap <HANDLER_FXN> <LIST OF SIGNALS TO TRAP>
trap handle_exit 0 SIGHUP SIGINT SIGQUIT SIGABRT SIGTERM