Skip to content

Instantly share code, notes, and snippets.

View nitrocode's full-sized avatar
🚀
Thinking and typing

RB nitrocode

🚀
Thinking and typing
View GitHub Profile
@nitrocode
nitrocode / table-WithRequired.md
Last active March 2, 2021 13:28
Test markdown anchor for terraform-docs

Usage:

Example of 'foo_bar' module in foo_bar.tf.

  • list item 1
  • list item 2

Even inline formatting in here is possible.
and some link

@nitrocode
nitrocode / copy_tags.py
Created February 25, 2021 16:25 — forked from nadirollo/copy_tags.py
python script to copy tags from a packer build into different accounts
#!/usr/bin/env python
import boto3
import os
import json
script_dir = os.path.dirname(os.path.realpath(__file__))
owner_account = 'xxxxxxxxxxx'
@nitrocode
nitrocode / ultimate_terraform_backend_creator.sh
Created October 30, 2020 21:04
Create the most awesome s3 backend.tf file
# provide the s3 bucket as the first param
export s3Bucket=${1:-bananananananana}
# get repo name
export repoName=$(git config --get remote.origin.url | cut -d '/' -f2 | cut -d '.' -f1)
# get current directory
export repoDir=$(git rev-parse --show-prefix | rev | cut -c 2- | rev)
# create backend
cat <<EOF > backend.tf
terraform {
required_version = ">=0.12"
@nitrocode
nitrocode / update-ssm-tags.py
Last active October 1, 2020 23:33 — forked from pjaudiomv/update-ssm-tags.sh
Tags instances with detected platform_version
#!/usr/bin/env python
# Original: https://gist.github.com/pjaudiomv/ff5efca41cdb7244ef4416c6097f6a7a
import boto3
import pdb
TAG_PLATFORM_VERSION = 'platform_version'
def get_ssm_by_platform_versions(ssm_res):
@nitrocode
nitrocode / README.md
Last active September 23, 2020 00:21
Tag S3 buckets with their bucket name for cost analysis

Tag S3 Buckets with their name

The AWS Cost Explorer tool cannot separate the S3 bucket resource expenditures by name so we can tag them with their own bucket name.

TODO: If possible, convert to a cloud custodian policy.

wget https://gist.githubusercontent.com/nitrocode/b6da03f103f3a0b42220c6fd057102f6/raw/tag-buckets.sh
chmod +x tag-buckets.sh
./tag-buckets.sh
@nitrocode
nitrocode / catovpn_restart.scpt
Last active May 18, 2022 21:30
Restart Cato on a schedule using an applescript and launchd
#!/usr/bin/osascript
(*
author: nitrocode
source: https://gist.github.com/nitrocode/559f1717ee5d610c3548b3e056b84e5e
Leave this commented block in case this file is ever updated or forked so it will be easier to update and audit in the future.
*)
tell application "System Events"
(* kill cato *)
set theID to (unix id of processes whose name is "CatoClient")
@nitrocode
nitrocode / terraform-import-mv-guesser.py
Last active April 29, 2020 14:48
Guesses terraform imports based on outputted plan
#!/usr/bin/env python3
# Currently works for 0.12.x
#
# TODO:
# - use json output instead of stdout
#
# Usage:
# terraform plan > plan.out
# python terraform-import-statement-guesser.py plan.out
import sys
@nitrocode
nitrocode / README.md
Last active April 27, 2020 20:18
Policy reordering

Find Terraform Changes in JSON

Currently only finds terraform plan changes

terraform plan -out=terraform.tfplan
terraform show -no-color -json terraform.tfplan > terraform.tfplan.json
python find-tf-changes.py terraform.tfplan.json

Would be nice to bake this directly into Terraform or into Landscape

@nitrocode
nitrocode / README.md
Last active January 16, 2020 22:49
Mimic sqs message json from cloud custodian's c7n-mailer

sqs-message-json.py

Usage

Create SQS message JSON by feeding in the policy yml, giving the policy name if there are multiple policies, and giving it the location of the output directory so it can read the resources.json file.

python sqs-message-json.py \
  policies/ebs-garbage-collect.yml \
  --policy ebs-mark-unattached-deletion \
  --output-dir out > sqs-ebs-garbage-collect.json
@nitrocode
nitrocode / README.md
Last active December 30, 2022 23:43
Cloud custodian iam policy and role generated from code and outputted to terraform

CloudCustodian IAM Policy

Extracts perms from cloud-custodian repo, sanitizes extracted data, and transforms into terraform.

How it works

The code will

  1. search for permissions = (get this data) over multiline
  2. print only the captured group