Skip to content

Instantly share code, notes, and snippets.

@stark525
stark525 / sysadvent_blog.md
Last active December 15, 2017 18:36
Sysadvent Blog Post 2017

Infrastructure Testing: Sanity Checking VPC Routes

Testing Infrastructure is hard; testing VPCs is even harder

Infrastructure testing is hard. My entire career I've tried to bring traditional development testing practices into operations. Linters. Rspec. Mock objects. These tools provide semantic and syntax checking, as well as unit and integration level coverage for infrastructure as code. Ideally, we would also test the system after the code is deployed. End-to-end infrastructure testing has always been a stretch goal -- too time-consuming to implement from scratch. This is especially true of network level testing. I am not aware of any existing tools that provide self-contained, end-to-end tests to ensure VPCs, subnets, and route tables are properly configured. As a result, production network deployments can be incredibly anxiety-inducing. Recently, my coworkers and I set up an entire VPC (virtual private cloud) using infrastructure as code, but felt we need

def get_ip_of_peer_instances_and_write_to_settings_file(self):
'''
This is run on the source EC2 instance as part of UserData bootstrapping
1) Look at the peer(s)' VPC CloudFormation Stack's Outputs for a list of subnets, public or private as defined
in the constructor.
2) Find instances in those subnets created by this library
3) Get the Private IP address of target instances and write it to a local configuration file
'''
# Query for peer CloudFormation, get instances
#!/usr/bin/env python
import boto3
import json
import base64
def headers_to_go_style(headers):
retval = {}
for k, v in headers.items():
retval[k] = [v]
git clone https://<private-git>/codebattles
git checkout -b dstark
@stark525
stark525 / puppet.conf
Created December 3, 2014 02:45
If you want to link hiera.yaml to some other path, add this to your puppet.conf
hiera_config=/some/other/path/hiera.yaml
@stark525
stark525 / eyaml-encrypt
Created December 3, 2014 02:40
Dump the output of this into your app.eyaml file
eyaml encrypt -s 'secretpassword' -l 'parameter-lookup'
@stark525
stark525 / config.yaml
Created December 3, 2014 02:36
eyaml config file for ~/.eyaml/config.yaml
---
pkcs7_private_key: '/var/lib/puppet/keys/private_key.pkcs7.pem'
pkcs7_public_key: '/var/lib/puppet/keys/public_key.pkcs7.pem'
@stark525
stark525 / link-hiera.yaml
Created December 3, 2014 02:31
Link /etc/hiera.yaml to /etc/puppet/hiera.yaml
@stark525
stark525 / hiera.yaml
Created December 3, 2014 02:26
/etc/hiera.yaml
:backends:
- eyaml
- yaml
:yaml:
:datadir: '/etc/puppet/hieradata'
:eyaml:
:datadir: '/etc/puppet/hieradata'
# If using the pkcs7 encryptor (default)
@stark525
stark525 / key-perms
Created December 3, 2014 02:21
Create puppet directory for your keys and set permissions
chown -R puppet:puppet /var/lib/puppet/keys
chmod -R 0500 /var/lib/puppet/keys
chmod 0400 /var/lib/puppet/keys/*.pem