Skip to content

Instantly share code, notes, and snippets.

View tom-butler's full-sized avatar
🚵

tom-butler tom-butler

🚵
View GitHub Profile
@tom-butler
tom-butler / ec2_helper.rb
Last active March 5, 2018 19:52
Get Running Instance ID
require 'aws-sdk'
# Return only a single running instance with the Name tag specified
class EC2Helper
def self.GetIdFromName(name)
instances = Array.new
# Filter the ec2 instances for name and state pending or running
ec2 = Aws::EC2::Resource.new(region: ENV['AWS_DEFAULT_REGION'])
ec2.instances({filters: [
@tom-butler
tom-butler / reference.tf
Created January 31, 2017 00:43
Terraform to only reference the resource that exists
# Assuming either name_1 or name_2 exists (using a count = 0)
# The following can be used to pass an attribute from the resource that was created
"${coalesce(
join("", resource.name.*.id),
join("", resource.name_2.*.id)
)}"
@tom-butler
tom-butler / scout2.sh
Created February 27, 2017 21:41
scout2-pipeline
#!/bin/bash
#AWS keys should be set before this
echo "Installing Scout security auditor"
git clone https://github.com/nccgroup/Scout2
cd Scout2
pip3 install -r requirements.txt
python Scout2.py
@tom-butler
tom-butler / assumeRole.json
Last active June 20, 2017 03:24
Assume Role
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "",
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::<CentralMonitoringAccountId>:role/<CentralMonitoringRole>"
},
"Action": "sts:AssumeRole"
@tom-butler
tom-butler / InstanceProfile.json
Created June 20, 2017 03:29
Instance Profile
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "InstanceProfile",
"Effect": "Allow",
"Action": [
"sts:AssumeRole"
],
"Resource": [
@tom-butler
tom-butler / centralMonitoringRole.tf
Created June 20, 2017 04:30
Terraform: Central Monitoring Role
#==============================================================
# tom-butler / centralMonitoringRole.tf
#==============================================================
variable "central_logging_account_id" {}
# The Role itself
resource "aws_iam_role" "monitor_access_role" {
name = "central-logging-monitor"
path = "/"
@tom-butler
tom-butler / AddAllOrgAccountsToPolicy.py
Created June 20, 2017 04:49
Boto3: Add All Org Accounts To IAM Policy
#!/usr/bin/env python3
import boto3
import json
central_logging = '<insert your central logging account id here>'
# Variables for the grafana monitoring server
role_name = 'monitoring_prodcloudwatch_access_role'
policy_arn = 'arn:aws:iam::<insert your central logging account id here>:policy/monitor-assumerole'
@tom-butler
tom-butler / asg_time_delay.tf
Created August 2, 2017 00:30
ASG Time Delay
# Get the time in UTC 15 minutes from now
data "external" "date" {
# use date to get the time 15 mins from now
program = ["bash", "${path.module}/date.sh"]
}
# Wait 15 minutes before scaling instances.
resource "aws_autoscaling_schedule" "delaystart" {
scheduled_action_name = "delaystart"
min_size = 2
@tom-butler
tom-butler / crontab
Created August 20, 2017 23:59
goss implementation
*/5 * * * * cd /opt/healthz && /bin/echo "`date +'\%Y-\%m-\%dT\%H:\%M:\%SZ'` `/usr/local/bin/goss validate -f nagios_verbose`" >> healthz.log
@tom-butler
tom-butler / remote-state-provisioner.tf
Created August 21, 2017 00:27
Terraform remote-state-provisioner
#==============================================================
# remote-state.tf
#==============================================================
# This file is used to set variables that are passed to sub
# modules to build our stack
#--------------------------------------------------------------
# Global Config
#--------------------------------------------------------------