Skip to content

Instantly share code, notes, and snippets.

@downspot
downspot / terraform_remote_state.tf
Created February 11, 2018 19:02
terraform_remote_state
data "terraform_remote_state" "network" {
backend = "s3"
workspace = "${terraform.workspace}"
config {
bucket = "bucket-name"
key = "terraform.tfstate"
region = "${var.region}"
}
}
@downspot
downspot / aws_cloudwatch_metric_alarm_recover.tf
Created February 11, 2018 19:08
aws_cloudwatch_metric_alarm recover
resource "aws_cloudwatch_metric_alarm" "example_host_alarm" {
alarm_name = "${aws_instance.example_host_alarm.id}"
comparison_operator = "GreaterThanOrEqualToThreshold"
evaluation_periods = "2"
metric_name = "StatusCheckFailed_System"
namespace = "AWS/EC2"
period = "60"
statistic = "Maximum"
threshold = "1.0"
alarm_description = "Created from EC2 Console"
@downspot
downspot / runtest_function.sh
Created February 11, 2018 19:10
runtest function
#!/bin/sh
email="[email protected]"
function runtest {
"$@"
local status=$?
if [ $status -ne 0 ]; then
echo "Script failed with error from '$@'" | mail -s "Script failure!" $email
exit 0
@downspot
downspot / ubuntu_find_java_home.sh
Created February 11, 2018 19:12
Ubuntu find java home
#!/bin/bash
# Find the absolute path of the java executable
# follow all symlinks (to cover /etc/alternatives/java ...)
jpath=$(readlink -e $(which java))
if [[ "$jpath" != "" ]]; then
while [[ "$jpath" != "/" ]]; do
jpath=$(dirname $jpath)
@downspot
downspot / terraform_cycle.tf
Created February 11, 2018 19:21
terraform cycle through instances, useful for adding alarms/names
resource "aws_cloudwatch_metric_alarm" "cpu_credits" {
count = 2
...
dimensions { InstanceId = "${element(list("i-07656896d6947814c", "i-042e664331a74e385"), count.index)}" }
dimensions { InstanceId = "${element(aws_instance.my_instance.*.id, count.index)}" }
}
@downspot
downspot / ECS_policy.json
Created February 11, 2018 21:37
policy for ECS access
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "ECSAccess",
"Effect": "Allow",
"Action": [
"ecs:Poll",
"ecs:StartTask",
@downspot
downspot / EC2_AMI_retention.sh
Last active April 22, 2018 19:55
EC2 AMI retention
#!/bin/sh
date=`date +%Y-%m-%d -d "30 day ago"`
for region in us-east-1 us-west-2 ; do
aws ec2 describe-images --region $region --owners self --output text --filters 'Name=name,Values=IMAGE-NAME-*' --query 'Images[?CreationDate<=`'${date}'`][ImageId]' | grep -v `aws ec2 describe-instances --region $region --output text --filters 'Name=tag:Name,Values=IGNORE-STRING-*' --query 'Reservations[*].Instances[*].[ImageId]' | sed -n 1p` > remove_ami-$region.txt
for remove in `cat remove_ami-$region.txt` ; do
aws ec2 deregister-image --region $region --image-id $remove
@downspot
downspot / subnet_hack.txt
Created April 16, 2019 19:33
terraform bad subnet removal hack
"${element(split(",", replace(replace(replace(replace(join(",", data.aws_subnet_ids.private.ids), "/subnet-ca201abd,/", ""), "/subnet-fc0870c1,/", ""), "/subnet-6630da5b/", ""), "/subnet-3f35c402,/", "")), count.index)}"
#!/bin/sh
VERSION=${VERSION:-1.6.1}
URL=https://github.com/prometheus/node_exporter/releases/download/v${VERSION}/node_exporter-${VERSION}.linux-amd64.tar.gz
FILENAME=${URL##*/}
ROOT_PATH=$PWD/opt/pkg
APP_ROOT_PATH=$ROOT_PATH/opt/node_exporter
ITERATION=${ITERATION:-1}
mkdir -p $APP_ROOT_PATH/script
curl -sLO $URL
@downspot
downspot / dse.txt
Last active November 26, 2023 22:05
DataStax Cassandra
- disable nodesync
nodesync disable
- run repair
nodetool repair --full
(optional nodetool repair -j ‘max 4 threads’ -pr to reduce
pressure on cluster full repair, run one node at a time)