Skip to content

Instantly share code, notes, and snippets.

View huevos-y-bacon's full-sized avatar

Huevos y Bacon huevos-y-bacon

View GitHub Profile
@huevos-y-bacon
huevos-y-bacon / Makefile
Last active July 17, 2023 10:27
CloudFormation Makefile template
AWS_ARGS:=--profile $(AWS_PROFILE) --region $(AWS_REGION)
STACK_NAME:=some-infra
TEMPLATE_FILE:=some-infra.yaml
OWNER:="My Team"
CFN_TAGS:=--tags \
Key=Owner,Value='$(OWNER)' \
Key=DeployedBy,Value=CloudFormation
@huevos-y-bacon
huevos-y-bacon / ssmsm
Last active February 23, 2023 07:35
SSM Session Manager connection by tag:key=Name or instance-id. ssmsm is a straight cli session, while ssmsmwin does port forwarding to use RDP via localhost.
#!/usr/bin/env bash
# shellcheck disable=SC2086
ssm_sm(){
[[ -n $DEBUG ]] && set -x
ARG1="$1"
get_name(){
INSTANCENAME=$(aws ec2 describe-tags \
--filters \
# Source: https://missionimpossiblecode.io/building-a-best-practice-cloudformation-custom-resource-pattern
Parameters:
SpecifyVPCToUse:
Description: >
DefaultVPC - finds the VPC and configures all of its subnets for you. Otherwise type
in the VPC id of a VPC in the same region where you run the template.
All subnets and azs of the chosen vpc will be used.
The VPC and chosen subnets must be setup in a way that allows the runner instances
to resolve the DNS name and connect to port 443 on the GitLab instance URL you provide.
Default: DefaultVPC
@huevos-y-bacon
huevos-y-bacon / aws_global_disable_security_hub.sh
Created August 19, 2022 09:51
Disable AWS SecurityHub in all regions
#!/bin/bash
for r in `aws ec2 describe-regions --query 'Regions[].RegionName' --out text`; do
echo $r;
aws securityhub disable-security-hub --region $r;
done
@huevos-y-bacon
huevos-y-bacon / git_author_rewrite.sh
Last active July 25, 2022 10:16
*GIT AUTHOR REWRITES* - use at your own risk
#!/bin/bash
exit
# GIT AUTHOR AND COMMITTER REWRITES - !!!DANGEROUS!!!
# Sources:
# - https://stackoverflow.com/a/1566833
# - https://www.git-tower.com/learn/git/faq/change-author-name-email/
## REWRITE COMMITTER - BY EMAIL
@huevos-y-bacon
huevos-y-bacon / std-pipeline-destroy
Created April 29, 2022 14:54
check/delete terraform standard pipeline resources, incl codebuild projects, iam roles + policies
#!/usr/bin/env bash
# shellcheck disable=1091,2068,2086,2162,2016
STRING=pipeline
if command -v colours &> /dev/null; then source colours; fi
unset COUNT
[[ $* == *"--force"* ]] && FORCE=yes
[[ $* == *"--check"* ]] && CHECK=yes
@huevos-y-bacon
huevos-y-bacon / tf-destroy-backend
Last active April 29, 2022 14:52
Based on given strings, destroy Terraform remote backend config (DDB table, S3 buckets, SSM Parameters)
#!/usr/bin/env bash
# shellcheck disable=1091,2068,2162
SSMSTRING=backend
BUCKSTRING=state
DDBSTRING=locks
if command -v colours &> /dev/null; then source colours; fi
unset COUNT
[[ $* == *"--force"* ]] && FORCE=yes
@huevos-y-bacon
huevos-y-bacon / bash_prepend_lines.sh
Last active March 29, 2022 16:45
Insert lines at top of all files of specified extension
#!/usr/bin/env bash
# Insert lines at the top of a file
ext=sh
for f in *.${ext}; do
# e.g. add shebang and shellcheck disable
printf '%s\n%s\n' "#shellcheck disable=1072,1073,1035,1020" "$(cat ${f})" >${f}
printf '%s\n%s\n' "#\!/usr/bin/env bash" "$(cat ${f})" >${f}
done
@huevos-y-bacon
huevos-y-bacon / bash_bulk_ext_rename.sh
Last active March 29, 2022 16:45
Bulk rename given file extension to another
#!/usr/bin/env bash
# Bulk rename given file extension to another
ext_before=txt
ext_after=extend
for file in *.${ext_before}; do mv "$file" "${file%."${ext_before}"}.${ext_after}"; done
@huevos-y-bacon
huevos-y-bacon / aws_check_configservice.sh
Last active March 29, 2022 16:22
Check if AWS Config is enabled in all regions
#/bin/bash
# Check if AWS Config is enabled in all regions
for r in $(aws ec2 describe-regions --query 'Regions[].RegionName' --out text); do
aws configservice describe-configuration-recorder-status --region $r --out yaml --query \
'ConfigurationRecordersStatus[].{name:name,recording:recording,lastStatus:lastStatus}';
done