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 / tf_log.sh
Created April 4, 2018 09:23
Terraform debug logging
#!/bin/bash
# Run in temrinal session, before terraform init
# Launch using ". tf_log.sh"
# If NOT running on Mac, comment out last line
export TF_LOG=DEBUG
export TF_LOG_PATH=./TF_LOG.log
touch $TF_LOG_PATH
open /Applications/Utilities/Console.app $TF_LOG_PATH
@huevos-y-bacon
huevos-y-bacon / aws_ec2_termination_protection.md
Last active February 20, 2024 07:56
Enable or disable EC2 instance "Termination Protection" via AWS CLI (shell)

Loop through all EC2 instances (excluding terminated and spot) and enable termination protection

for I in $(aws ec2 describe-instances --query \
  'Reservations[].Instances[?(InstanceLifecycle!=`spot` && InstanceState!=terminated)].[InstanceId]' \
  --output text); do
  aws ec2 modify-instance-attribute --disable-api-termination --instance-id $I;
done
@huevos-y-bacon
huevos-y-bacon / aws_s3_presigner_md.sh
Last active March 29, 2022 16:25
Create presigned URLs for every object in a given S3 bucket & output to Markdown
#!/bin/bash
# Generate presigned URLs for every object in a given bucket
# Outputs markdown. Preview in IDE and copy to email.
# Prereqs: awscli, jq
EXPIRY=604800 # in SECONDS
BUCKET=$1
OUTFILE=$BUCKET-signed-urls.md
@huevos-y-bacon
huevos-y-bacon / aws_ec2_get_supported_instance_types.sh
Last active March 29, 2022 16:25
Get supported EC2 instance types in the current account and region. If you only need to check for specific types, then specify them in types.txt in the script directory, otherwise it will process all available instance types in the region. Tested on MacOS.
#!/usr/bin/env bash
# Get supported EC2 instance types in the current account and region. If you
# only need to check for specific types, then specify them in types.txt in
# the script directory, otherwise it will process all available instance types
# in the region. Tested on MacOS.
# Prereqs: awscli, jq
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
TMPTYPES=/tmp/types
@huevos-y-bacon
huevos-y-bacon / Brewfile
Last active August 17, 2022 21:50
MacOS: bulk install apps via Homebrew, including App Store apps. Edit the various Brewfiles and run `brew-bundle.sh`
# BASE
tap "homebrew/bundle"
tap "homebrew/cask"
tap "homebrew/core"
# BASE Apps
cask "joplin"
cask "bettertouchtool"
cask "visual-studio-code"
cask "bitwarden"
@huevos-y-bacon
huevos-y-bacon / dd_api.sh
Last active October 20, 2021 14:18
DataDog API (AWS Integration) Interactions using Bash
#!/usr/bin/env bash
# shellcheck disable=SC2034
# API DOCUMENTATION: https://docs.datadoghq.com/api/latest/aws-integration/
# ============================================================
# TO BE REMOVED AND PROVIDED VIA EXPORTS
DD_API_KEY="DATADOG_API_KEY"
DD_APPLICATION_KEY="DATADOG_APPLICATION_KEY"
ACCOUNTID="AWS_ACCOUNT_ID"
@huevos-y-bacon
huevos-y-bacon / aws_get_session_token.sh
Last active September 27, 2023 18:21
GET AWS SESSION TOKEN WITH MFA allowing CLI access to commands without switching to an IAM Role
#!/usr/bin/env bash
# shellcheck disable=2086,2162,2005,2046,1091
# GET AWS SESSION TOKEN WITH MFA
# allowing CLI access to commands without switching to an IAM Role, e.g. for accessing the Well-Architected Tool
source colours > /dev/null 2>&1 # import colours script if it exists in the PATH
usage(){
echo "
@huevos-y-bacon
huevos-y-bacon / aws_wat_workload_arns.sh
Last active March 29, 2022 16:22
Export AWS Well-Architected Tool Workload ARNs to CSV
#!/usr/bin/env bash
# Export AWS Well-Architected Tool Workload ARNs to CSV
usage(){
echo "EXPORT WELL-ARCHITECTED TOOL WORKLOAD ARNs TO CSV
ARGUMENTS:
-d | --days \${number of days} - number of days to include (since last update). Default 3650
-u | --upload | --arns - output APN portal upload-friendly CSV of ARNs only
-h | --help - this output
@huevos-y-bacon
huevos-y-bacon / bash-array-add-items.sh
Created February 23, 2022 12:08
Bash Arrays - Add Elements
#!/usr/bin/env bash
array=(pluto pippo bob)
echo "array: ${array[*]}"
echo
addlist=(mike john)
echo "add list: ${addlist[*]}"
array+=(${addlist[*]})
echo "${array[@]}"
@huevos-y-bacon
huevos-y-bacon / bash-array-delete-items.sh
Created February 23, 2022 12:09
Bash Arrays - Delete Elements
#!/usr/bin/env bash
# see: https://stackoverflow.com/questions/16860877/remove-an-element-from-a-bash-array
array=(pluto pippo bob john 1 56)
echo "array: ${array[*]}"
echo
delete=(pippo 56)
echo "delete: ${delete[*]}"
for target in "${delete[@]}"; do
for i in "${!array[@]}"; do