Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/env zsh
# aws-multi-role.zsh
# Usage: ./aws-multi-role.zsh <env>
# Example: ./aws-multi-role.zsh preprod
set -euo pipefail
# --- 1. prerequisites --------------------------------------------------------
# verify jq is installed (for JSON parsing)
if ! command -v jq >/dev/null; then
###########################
# VARIABLES
###########################
variable "source_account_id" {
description = "Account ID of the VPC owner (lz351prod)"
type = string
default = "913016797819"
}
We couldn’t find that file to show.
We couldn’t find that file to show.
1. Basic Syntax
• Comments:
Use # for single-line comments and triple quotes ("""...""" or '''...''') for multi-line strings or docstrings.
# This is a single-line comment
"""
This is a multi-line comment or docstring.
Useful for module or function documentation.
"""
fields @timestamp, @message
| parse @message " * * * * * * * * * * * * * * *" as version, account_id, interface_id, srcAddr, dstAddr, srcPort, dstPort, protocol, packets, bytes, start_time, end_time, action, log_status
| limit 10
fields @message
| parse @message " * * * * * * * * * * * * * * *" as version, account_id, interface_id, srcAddr, dstAddr, srcPort, dstPort, protocol, packets, bytes, start_time, end_time, action, log_status
| filter dstPort = 25 or dstPort = 465
| filter dstAddr in ["10.39.132.10", "10.39.133.138", "10.39.132.97", "10.39.133.151"]
| limit 10000
@huynhbaoan
huynhbaoan / tfw
Last active March 1, 2025 12:32
Tfw
DIR_PATH=$(pwd | sed 's%^.*account-build%account-build%g')
AWS_SHORT_ACCOUNT_ID=$(echo ${DIR_PATH} | /bin/awk -F "/" '{print $2}')
APPACC_ID=$( cat account-variables.tf | tr '\n' ' ' | sed -e 's/.*variable[ \t]*"account-id"[ \t]*{[ \t]*default = "\([0-9]*\)"[ \t]*}.*/\1/g' )
STACKNAME=$(basename "${DIR_PATH}")
AWS_ACCOUNT_NUMBER=$(aws sts get-caller-identity --query 'Account' --output text)
S3_CF_BUCKET="${AWS_ACCOUNT_NUMBER}-config"
CORRECT_ACC_FLAG="false"
ACCOUNT_TYPE=$( cat account-variables.tf | grep account-type | awk -F '"' '{print tolower($4)}' )
ROLE_NAME=$(aws sts get-caller-identity | jq '.Arn' | awk -F "/" '{ print $2 }')
APPACC_NAME=$(cat account-variables.tf | grep account-shortname | awk -F '"' '{print tolower($4)}')
We couldn’t find that file to show.
We couldn’t find that file to show.