Skip to content

Instantly share code, notes, and snippets.

View maishsk's full-sized avatar

Maish Saidel-Keesing maishsk

View GitHub Profile
@maishsk
maishsk / vpc_cloudformation_template.yml
Created July 1, 2018 14:18
Create VPC - with cloudformation
Description:
This template deploys a VPC, with a pair of public and private subnets spread
across two Availability Zones. It deploys an Internet Gateway, with a default
route on the public subnets. It deploys a pair of NAT Gateways (one in each AZ),
and default routes for them in the private subnets.
The Availability zone information is hard-coded (on purpose)
Parameters:
EnvironmentName:
@maishsk
maishsk / Terraform results
Created June 21, 2018 08:59
Terraform results
root@maishsk-lin:/opt/git/playground/create-vpc/terraform# for i in {1..3}; do echo "starting run $i"; echo "create" ; time terraform apply -auto-approve ; echo "destroy" ; time terraform destroy -auto-approve; done
Starting run 1
Create
aws_vpc.testvpc: Creating...
assign_generated_ipv6_cidr_block: "" => "false"
cidr_block: "" => "192.168.90.0/24"
default_network_acl_id: "" => "<computed>"
default_route_table_id: "" => "<computed>"
@maishsk
maishsk / Ansible results
Created June 21, 2018 08:50
Ansible results
root@maishsk-lin:/opt/git/playground/create-vpc/ansible# for i in {1..3}; do echo "starting run $i"; echo "create"; time ansible-playbook create-vpc.yml ; echo "destroy"; time ansible-playbook remove-vpc.yml ; done
Starting run 1
Create
[WARNING]: Unable to parse /etc/ansible/hosts as an inventory source
[WARNING]: No inventory was parsed, only implicit localhost is available
[WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all'
PLAY [VPC creation playbook] *************************************************************************************************************************************************************************************************************
TASK [Create a VPC] **********************************************************************************************************************************************************************************************************************
@maishsk
maishsk / Cloudformation results
Created June 21, 2018 08:42
Cloudformation results
root@maishsk-lin:/opt/git/playground/create-vpc/cloudformation# for i in {1..3}; do echo "Starting run $i"; echo "Create"; aws cloudformation create-stack --stack-name testvpc --template-body file://vpc_cloudformation_template.yml; time aws cloudformation wait stack-create-complete --stack-name testvpc --no-paginate; echo "Destroy"; aws cloudformation delete-stack --stack-name testvpc; time aws cloudformation wait stack-delete-complete --stack-name testvpc; done
Starting run 1
Create
{
"StackId": "arn:aws:cloudformation:us-east-2:138XXXX92836:stack/testvpc/d185d5c0-7305-11e8-8f24-508410100a8d"
}
31.750
Destroy
@maishsk
maishsk / create-vpc.tf
Created June 21, 2018 08:08
Create VPC with Terraform
resource "aws_vpc" "testvpc" {
cidr_block = "${var.vpc_cidr}"
enable_dns_hostnames = true
tags {
Name = "${var.project_name}"
}
}
@maishsk
maishsk / create-vpc.yml
Created June 21, 2018 07:58
Create a VPC with Ansible
- name: VPC creation playbook
hosts: localhost
connection: local
gather_facts: no
vars_files:
- vars/vpc_vars.yml
tasks:
- name: Create a VPC
@maishsk
maishsk / vpc_cloudformation_template.yml
Created June 21, 2018 07:48
Create VPC - with cloudformation
Description:
This template deploys a VPC.
Parameters:
EnvironmentName:
Description: An environment name that will be prefixed to resource names
Type: String
Default: "testvpc"
VpcCIDR:
@maishsk
maishsk / create-vpc
Last active June 21, 2018 07:42
Create VPC with AWS CLI
aws ec2 create-vpc --cidr-block 192.168.90.0/24
@maishsk
maishsk / gist:4ffb281d386eaf6736978992fde54032
Created June 6, 2018 14:39
Encrypt-decrypt KMS and SSM
blob=`aws kms encrypt --key-id $keyid --plaintext "hello_world" --profile work --query CiphertextBlob --output text`
ssmblob=`aws ssm get-parameter --name "encrypted_password" --profile work --with-decryption | jq .Parameter.Value | tr -d '"'`
aws kms decrypt --ciphertext-blob fileb://<(echo $ssmblob | base64 -d) --output text --query Plaintext --profile work | base64 -d
@maishsk
maishsk / get_az_data.sh
Created January 10, 2018 14:56
Simple way to export all the az's in each region to a file
#!/bin/bash
## Script will get all AZ info from AWS through awscli
## Required: awscli and jq
AZINFO=$(for i in $(aws ec2 describe-regions | jq .Regions[].RegionName | tr -d '"')
do
aws ec2 describe-availability-zones --region $i | jq .AvailabilityZones[].ZoneName | tr -d '"'
done | sort)