Skip to content

Instantly share code, notes, and snippets.

@jayers99
jayers99 / tfJsonValidate.sh
Last active February 7, 2019 23:56
filter out policy json from tf file
awk '/policy = <<-EOF/{f=1; next}/^ EOF/{f=0}f' filename.tf | jq
@jayers99
jayers99 / terraform-sg-plan-filter.sh
Last active January 30, 2019 22:13
Filter out all the security groups that have not changed from terraform plan output
# getting close
cat ~/scripts/tfplan.sh
#!/usr/bin/env bash
planfile=$HOME/plans/${PWD##*/}_$(cat /dev/urandom | tr -cd 'a-f0-9' | head -c 8)
planfilepr=$planfile'PR.md'
terraform plan "$@" | tee $planfile
# build a PR
sed -i "s,\x1B\[[0-9;]*[a-zA-Z],,g" $planfile
echo '## Terraform Plan' > $planfilepr
@jayers99
jayers99 / vimFun.txt
Created January 18, 2019 00:42
vim tricks
to insert text at the beginning of a block of text
ctrl+v (visual block mode)
down arrow to block out lines
shift+i to insert
type desired text
esc
to append to the end of line
add a $ when blocking lines
shift+a to append
@jayers99
jayers99 / awsFlowLogSample.sh
Last active January 9, 2019 18:23
AWS Flow Log Sample
# column names
# https://docs.aws.amazon.com/vpc/latest/userguide/flow-logs.html
logGroupName=
logStreamName=
aws logs filter-log-events --start-time `date -d 2018-9-28T18:00:00Z +%s`000 --log-group-name $logGroupName --log-stream-names $logStreamName --filter-pattern REJECT
aws logs filter-log-events --start-time `date -d 2018-9-28T18:00:00Z +%s`000 --log-group-name $logGroupName --log-stream-names $logStreamName --filter-pattern REJECT | jq -r '.events[] | "\(.timestamp) \(.message)"' | cut -d ' ' -f1,5,6,7,8,14 | awk '{print system("date -d @" substr($0,1,10)) substr($0,14)}'
**/*~
**/.DS_STORE
**/.vscode
# terraform
**/.terraform
**/*.tfstate
**/*.tfstate.*
**/crash.log
**/override.tf
#export PS1="\e[0;32m[\\u@\h:\\W]\$ \e[m"
#export PS1="\e[1;32m\\u@\h\e[m:\e[1;34m\\W\e[m\$ "
#export PS1="\[\033[01;32m\]\u@\h\[\033[0m\]:\[\033[01;34m\]\W\[\033[0m\]\$ "
parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'
}
export PS1="\[\033[00;33m\]\u@\h\[\033[0m\]:\[\033[01;34m\]\w\[\033[00;32m\]\$(parse_git_branch)\[\033[0m\]\n\[\033[00;33m\]> $\[\033[0m\] "
export CLICOLOR=1
export LSCOLORS=ExFxBxDxCxegedabagacad
#------------------------------------------------------------------------------
# Alias
#------------------------------------------------------------------------------
alias la='ls -la'
alias ll='ls -l'
syntax on
colorscheme desert
set listchars=tab:>-,trail:~,extends:>,precedes:<
"set listchars=eol:$,tab:>-,trail:~,extends:>,precedes:<
set list
set noshowmatch
set iskeyword+=-
" persistent undo
set undodir=~/.vim/undodir
@jayers99
jayers99 / .bashrc
Last active February 9, 2019 17:45
# .bashrc
export PROMPT_COMMAND='history -a'
# Source global definitions
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi
# Uncomment the following line if you don't like systemctl's auto-paging feature:
# export SYSTEMD_PAGER=
# Terraform State Move - Refactoring Terraform Against Existing Infrastructure
# https://ryaneschinger.com/blog/terraform-state-move/
terraform state mv aws_security_group.old_name aws_security_group.new_name