From 20e9b7c9eb197d08a45c48d664e2a2f2d8d552d9 Mon Sep 17 00:00:00 2001 From: Tom Date: Sat, 12 May 2018 13:32:35 +1000 Subject: [PATCH 1/3] Added scaffolding for aws using cfn --- scaffolds/aws/cfn/bootstrap.sh | 4 + scaffolds/aws/cfn/parameters.yml | 10 + scaffolds/aws/cfn/readme.md | 41 +++ scaffolds/aws/cfn/teardown.sh | 4 + scaffolds/aws/cfn/template.yml | 495 +++++++++++++++++++++++++++++++ 5 files changed, 554 insertions(+) create mode 100755 scaffolds/aws/cfn/bootstrap.sh create mode 100644 scaffolds/aws/cfn/parameters.yml create mode 100644 scaffolds/aws/cfn/readme.md create mode 100755 scaffolds/aws/cfn/teardown.sh create mode 100644 scaffolds/aws/cfn/template.yml diff --git a/scaffolds/aws/cfn/bootstrap.sh b/scaffolds/aws/cfn/bootstrap.sh new file mode 100755 index 00000000..def3e193 --- /dev/null +++ b/scaffolds/aws/cfn/bootstrap.sh @@ -0,0 +1,4 @@ +#!/bin/sh + +echo "Starting bootstrap of network!" +stackup vibrato-network up -t template.yml -p parameters.yml \ No newline at end of file diff --git a/scaffolds/aws/cfn/parameters.yml b/scaffolds/aws/cfn/parameters.yml new file mode 100644 index 00000000..86efaf56 --- /dev/null +++ b/scaffolds/aws/cfn/parameters.yml @@ -0,0 +1,10 @@ +VpcCidr: 10.89.32.0/19 +PublicSubnetAz1: 10.89.32.0/23 +PublicSubnetAz2: 10.89.34.0/23 +PublicSubnetAz3: 10.89.36.0/23 +DataSubnetAz1: 10.89.40.0/23 +DataSubnetAz2: 10.89.42.0/23 +DataSubnetAz3: 10.89.44.0/23 +PrivateSubnetAz1: 10.89.48.0/22 +PrivateSubnetAz2: 10.89.52.0/22 +PrivateSubnetAz3: 10.89.56.0/22 \ No newline at end of file diff --git a/scaffolds/aws/cfn/readme.md b/scaffolds/aws/cfn/readme.md new file mode 100644 index 00000000..fdd67534 --- /dev/null +++ b/scaffolds/aws/cfn/readme.md @@ -0,0 +1,41 @@ +# AWS CloudFormation scaffolding + +This scaffold will deploy the network layer in AWS using cloudformation. + +## Requirements + +stackup - https://github.com/realestate-com-au/stackup + +## Instructions + +Set up AWS credentials environment variables. e.g. AWS_PROFILE + +Run `bootstrap.sh` from the scaffolding directory + +To remove run `teardown.sh` from the scaffolding directory + +## What will be deployed + +A VPC with networking, routing and nats. + +The VPC is laid out with 3 layers, public, private, and data. + +> The template assumes 3 AZs, so if you are deploying somewhere with less it will need to be updated. + +### Exports + +* vibrato-network-VpcId +* vibrato-network-VpcCidr +* vibrato-network-SubnetPublicAz1 +* vibrato-network-SubnetPublicAz2 +* vibrato-network-SubnetPublicAz3 +* vibrato-network-SubnetPrivateAz1 +* vibrato-network-SubnetPrivateAz2 +* vibrato-network-SubnetPrivateAz3 +* vibrato-network-SubnetDataAz1 +* vibrato-network-SubnetDataAz2 +* vibrato-network-SubnetDataAz3 + +## Tested on + +* MacOs \ No newline at end of file diff --git a/scaffolds/aws/cfn/teardown.sh b/scaffolds/aws/cfn/teardown.sh new file mode 100755 index 00000000..d6fb90f0 --- /dev/null +++ b/scaffolds/aws/cfn/teardown.sh @@ -0,0 +1,4 @@ +#!/bin/sh + +echo "Starting bootstrap of network!" +stackup vibrato-network down \ No newline at end of file diff --git a/scaffolds/aws/cfn/template.yml b/scaffolds/aws/cfn/template.yml new file mode 100644 index 00000000..2ef6eed6 --- /dev/null +++ b/scaffolds/aws/cfn/template.yml @@ -0,0 +1,495 @@ +--- +Description: Network Layout for Environment + +Parameters: + + # CIDR inputs are limited to between /16-/28 as those are the AWS limits + VpcCidr: + Description: CIDR range for whole VPC. e.g. 10.89.0.0/19 + Type: String + AllowedPattern: ((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\/((1[6-9])|(2[0-8])) + + PublicSubnetAz1: + Description: CIDR range for public subnet in AZ1. e.g. 10.89.0.0/23 + Type: String + AllowedPattern: ((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\/((1[6-9])|(2[0-8])) + + PublicSubnetAz2: + Description: CIDR range for public subnet in AZ2. e.g. 10.89.2.0/23 + Type: String + AllowedPattern: ((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\/((1[6-9])|(2[0-8])) + + PublicSubnetAz3: + Description: CIDR range for public subnet in AZ3. e.g 10.89.4.0/23 + Type: String + AllowedPattern: ((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\/((1[6-9])|(2[0-8])) + + DataSubnetAz1: + Description: CIDR range for data subnet in AZ1. e.g. 10.89.8.0/23 + Type: String + AllowedPattern: ((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\/((1[6-9])|(2[0-8])) + + DataSubnetAz2: + Description: CIDR range for data subnet in AZ2. e.g. 10.89.10.0/23 + Type: String + AllowedPattern: ((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\/((1[6-9])|(2[0-8])) + + DataSubnetAz3: + Description: CIRD range for data subnet in AZ3. e.g. 10.89.12.0/23 + Type: String + AllowedPattern: ((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\/((1[6-9])|(2[0-8])) + + PrivateSubnetAz1: + Description: CIDR range for private subnet in AZ1. e.g. 10.89.16.0/22 + Type: String + AllowedPattern: ((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\/((1[6-9])|(2[0-8])) + + PrivateSubnetAz2: + Description: CIDR range for private subnet in AZ2. e.g. 10.89.20.0/22 + Type: String + AllowedPattern: ((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\/((1[6-9])|(2[0-8])) + + PrivateSubnetAz3: + Description: CIDR range for private subnet in AZ3. e.g. 10.89.24.0/22 + Type: String + AllowedPattern: ((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\/((1[6-9])|(2[0-8])) + +Resources: + VPC: + Type: AWS::EC2::VPC + Properties: + CidrBlock: !Ref VpcCidr + EnableDnsSupport: true + EnableDnsHostnames: true + Tags: + - Key: Name + Value: !Sub "${AWS::StackName}-vpc" + + InternetGateway: + Type: AWS::EC2::InternetGateway + Properties: + Tags: + - Key: Name + Value: !Sub "${AWS::StackName}-igw" + + InternetGatewayAttachment: + Type: AWS::EC2::VPCGatewayAttachment + Properties: + InternetGatewayId: !Ref InternetGateway + VpcId: !Ref VPC + + DHCPOptions: + Type: AWS::EC2::DHCPOptions + Properties: + DomainNameServers: + - AmazonProvidedDNS + Tags: + - Key: Name + Value: !Sub "${AWS::StackName}-dhcpoptions" + + S3Endpoint: + Type: AWS::EC2::VPCEndpoint + Properties: + VpcId: !Ref VPC + ServiceName: !Sub com.amazonaws.${AWS::Region}.s3 + + ############################################################################# + # Nat Gateways: DO NOT MODIFY + ############################################################################# + + NatGateway1EIP: + Type: AWS::EC2::EIP + Properties: + Domain: vpc + + NatGateway2EIP: + Type: AWS::EC2::EIP + Properties: + Domain: vpc + + NatGateway3EIP: + Type: AWS::EC2::EIP + Properties: + Domain: vpc + + NATGateway1: + Type: AWS::EC2::NatGateway + Properties: + AllocationId: !GetAtt NatGateway1EIP.AllocationId + SubnetId: !Ref PublicSubnet1 + + NATGateway2: + Type: AWS::EC2::NatGateway + Properties: + AllocationId: !GetAtt NatGateway2EIP.AllocationId + SubnetId: !Ref PublicSubnet2 + + NATGateway3: + Type: AWS::EC2::NatGateway + Properties: + AllocationId: !GetAtt NatGateway3EIP.AllocationId + SubnetId: !Ref PublicSubnet3 + + ############################################################################# + # Routes: DO NOT MODIFY + ############################################################################# + + # Public Routes + + PublicRouteTable: + Type: AWS::EC2::RouteTable + Properties: + VpcId: !Ref VPC + Tags: + - Key: Name + Value: !Sub "${AWS::StackName}-public" + + PublicRoute: + Type: AWS::EC2::Route + Properties: + RouteTableId: !Ref PublicRouteTable + DestinationCidrBlock: 0.0.0.0/0 + GatewayId: !Ref InternetGateway + + PublicSubnetRouteTableAssociation1: + Type: AWS::EC2::SubnetRouteTableAssociation + Properties: + SubnetId: !Ref PublicSubnet1 + RouteTableId: !Ref PublicRouteTable + + PublicSubnetRouteTableAssociation2: + Type: AWS::EC2::SubnetRouteTableAssociation + Properties: + SubnetId: !Ref PublicSubnet2 + RouteTableId: !Ref PublicRouteTable + + PublicSubnetRouteTableAssociation3: + Type: AWS::EC2::SubnetRouteTableAssociation + Properties: + SubnetId: !Ref PublicSubnet3 + RouteTableId: !Ref PublicRouteTable + + # Private Routes + + PrivateRouteTable1: + Type: AWS::EC2::RouteTable + Properties: + VpcId: !Ref VPC + Tags: + - Key: Name + Value: !Sub "${AWS::StackName}-privateroute-az1" + + PrivateRouteTable2: + Type: AWS::EC2::RouteTable + Properties: + VpcId: !Ref VPC + Tags: + - Key: Name + Value: !Sub "${AWS::StackName}-privateroute-az1" + + PrivateRouteTable3: + Type: AWS::EC2::RouteTable + Properties: + VpcId: !Ref VPC + Tags: + - Key: Name + Value: !Sub "${AWS::StackName}-privateroute-az3" + + PrivateRoute1: + Type: AWS::EC2::Route + Properties: + RouteTableId: !Ref PrivateRouteTable1 + DestinationCidrBlock: 0.0.0.0/0 + NatGatewayId: !Ref NATGateway1 + + PrivateRoute2: + Type: AWS::EC2::Route + Properties: + RouteTableId: !Ref PrivateRouteTable2 + DestinationCidrBlock: 0.0.0.0/0 + NatGatewayId: !Ref NATGateway2 + + PrivateRoute3: + Type: AWS::EC2::Route + Properties: + RouteTableId: !Ref PrivateRouteTable3 + DestinationCidrBlock: 0.0.0.0/0 + NatGatewayId: !Ref NATGateway3 + + PrivateSubnetRouteTableAssociation1: + Type: AWS::EC2::SubnetRouteTableAssociation + Properties: + SubnetId: !Ref PrivateSubnet1 + RouteTableId: !Ref PrivateRouteTable1 + + PrivateSubnetRouteTableAssociation2: + Type: AWS::EC2::SubnetRouteTableAssociation + Properties: + SubnetId: !Ref PrivateSubnet2 + RouteTableId: !Ref PrivateRouteTable2 + + PrivateSubnetRouteTableAssociation3: + Type: AWS::EC2::SubnetRouteTableAssociation + Properties: + SubnetId: !Ref PrivateSubnet3 + RouteTableId: !Ref PrivateRouteTable3 + + # Data Routes + + DataRouteTable1: + Type: AWS::EC2::RouteTable + Properties: + VpcId: !Ref VPC + Tags: + - Key: Name + Value: !Sub "${AWS::StackName}-dataroutes-az1" + + DataRouteTable2: + Type: AWS::EC2::RouteTable + Properties: + VpcId: !Ref VPC + Tags: + - Key: Name + Value: !Sub "${AWS::StackName}-dataroutes-az2" + + DataRouteTable3: + Type: AWS::EC2::RouteTable + Properties: + VpcId: !Ref VPC + Tags: + - Key: Name + Value: !Sub "${AWS::StackName}-dataroutes-az3" + + DataRoute1: + Type: AWS::EC2::Route + Properties: + RouteTableId: !Ref DataRouteTable1 + DestinationCidrBlock: 0.0.0.0/0 + NatGatewayId: !Ref NATGateway1 + + DataRoute2: + Type: AWS::EC2::Route + Properties: + RouteTableId: !Ref DataRouteTable2 + DestinationCidrBlock: 0.0.0.0/0 + NatGatewayId: !Ref NATGateway2 + + DataRoute3: + Type: AWS::EC2::Route + Properties: + RouteTableId: !Ref DataRouteTable3 + DestinationCidrBlock: 0.0.0.0/0 + NatGatewayId: !Ref NATGateway3 + + DataSubnetRouteTableAssociation1: + Type: AWS::EC2::SubnetRouteTableAssociation + Properties: + SubnetId: !Ref DataSubnet1 + RouteTableId: !Ref DataRouteTable1 + + DataSubnetRouteTableAssociation2: + Type: AWS::EC2::SubnetRouteTableAssociation + Properties: + SubnetId: !Ref DataSubnet2 + RouteTableId: !Ref DataRouteTable2 + + DataSubnetRouteTableAssociation3: + Type: AWS::EC2::SubnetRouteTableAssociation + Properties: + SubnetId: !Ref DataSubnet3 + RouteTableId: !Ref DataRouteTable3 + + ############################################################################# + # Subnets: DO NOT MODIFY + ############################################################################# + + # Public Subnets + + PublicSubnet1: + Type: AWS::EC2::Subnet + Properties: + VpcId: !Ref VPC + AvailabilityZone: !Select + - 0 + - !GetAZs "" + CidrBlock: !Ref PublicSubnetAz1 + MapPublicIpOnLaunch: true + Tags: + - Key: Name + Value: !Sub "${AWS::StackName}-public-subnet-az1" + + PublicSubnet2: + Type: AWS::EC2::Subnet + Properties: + VpcId: !Ref VPC + AvailabilityZone: !Select + - 1 + - !GetAZs "" + CidrBlock: !Ref PublicSubnetAz2 + MapPublicIpOnLaunch: true + Tags: + - Key: Name + Value: !Sub "${AWS::StackName}-public-subnet-az2" + + PublicSubnet3: + Type: AWS::EC2::Subnet + Properties: + VpcId: !Ref VPC + AvailabilityZone: !Select + - 2 + - !GetAZs "" + CidrBlock: !Ref PublicSubnetAz3 + MapPublicIpOnLaunch: true + Tags: + - Key: Name + Value: !Sub "${AWS::StackName}-public-subnet-az3" + + # Private Subnets + + PrivateSubnet1: + Type: AWS::EC2::Subnet + Properties: + VpcId: !Ref VPC + AvailabilityZone: !Select + - 0 + - !GetAZs "" + CidrBlock: !Ref PrivateSubnetAz1 + MapPublicIpOnLaunch: false + Tags: + - Key: Name + Value: !Sub "${AWS::StackName}-private-subnet-az1" + + PrivateSubnet2: + Type: AWS::EC2::Subnet + Properties: + VpcId: !Ref VPC + AvailabilityZone: !Select + - 1 + - !GetAZs "" + CidrBlock: !Ref PrivateSubnetAz2 + MapPublicIpOnLaunch: false + Tags: + - Key: Name + Value: !Sub "${AWS::StackName}-private-subnet-az2" + + PrivateSubnet3: + Type: AWS::EC2::Subnet + Properties: + VpcId: !Ref VPC + AvailabilityZone: !Select + - 2 + - !GetAZs "" + CidrBlock: !Ref PrivateSubnetAz3 + MapPublicIpOnLaunch: false + Tags: + - Key: Name + Value: !Sub "${AWS::StackName}-private-subnet-az3" + + # Data Subnets + + DataSubnet1: + Type: AWS::EC2::Subnet + Properties: + VpcId: !Ref VPC + AvailabilityZone: !Select + - 0 + - !GetAZs "" + CidrBlock: !Ref DataSubnetAz1 + MapPublicIpOnLaunch: false + Tags: + - Key: Name + Value: !Sub "${AWS::StackName}-data-subnet-az1" + + DataSubnet2: + Type: AWS::EC2::Subnet + Properties: + VpcId: !Ref VPC + AvailabilityZone: !Select + - 1 + - !GetAZs "" + CidrBlock: !Ref DataSubnetAz2 + MapPublicIpOnLaunch: false + Tags: + - Key: Name + Value: !Sub "${AWS::StackName}-data-subnet-az2" + + DataSubnet3: + Type: AWS::EC2::Subnet + Properties: + VpcId: !Ref VPC + AvailabilityZone: !Select + - 2 + - !GetAZs "" + CidrBlock: !Ref DataSubnetAz3 + MapPublicIpOnLaunch: false + Tags: + - Key: Name + Value: !Sub "${AWS::StackName}-data-subnet-az3" + +Outputs: + + VpcId: + Description: A reference to the created VPC + Value: !Ref VPC + Export: + Name: !Sub "${AWS::StackName}-VpcId" + + VpcCidr: + Description: A reference to the created VPC + Value: !GetAtt VPC.CidrBlock + Export: + Name: !Sub "${AWS::StackName}-VpcCidr" + + SubnetPublicAz1: + Description: A reference to the created public subnet in az1 + Value: !Ref PublicSubnet1 + Export: + Name: !Sub "${AWS::StackName}-SubnetPublicAz1" + + SubnetPublicAz2: + Description: A reference to the created public subnet in az2 + Value: !Ref PublicSubnet2 + Export: + Name: !Sub "${AWS::StackName}-SubnetPublicAz2" + + SubnetPublicAz3: + Description: A reference to the created public subnet in az3 + Value: !Ref PublicSubnet3 + Export: + Name: !Sub "${AWS::StackName}-SubnetPublicAz3" + + SubnetPrivateAz1: + Description: A reference to the created private subnet in az1 + Value: !Ref PrivateSubnet1 + Export: + Name: !Sub "${AWS::StackName}-SubnetPrivateAz1" + + SubnetPrivateAz2: + Description: A reference to the created private subnet in az2 + Value: !Ref PrivateSubnet2 + Export: + Name: !Sub "${AWS::StackName}-SubnetPrivateAz2" + + SubnetPrivateAz3: + Description: A reference to the created private subnet in az3 + Value: !Ref PrivateSubnet3 + Export: + Name: !Sub "${AWS::StackName}-SubnetPrivateAz3" + + SubnetDataAz1: + Description: A reference to the created data subnet in az1 + Value: !Ref DataSubnet1 + Export: + Name: !Sub "${AWS::StackName}-SubnetDataAz1" + + SubnetDataAz2: + Description: A reference to the created data subnet in az2 + Value: !Ref DataSubnet2 + Export: + Name: !Sub "${AWS::StackName}-SubnetDataAz2" + + SubnetDataAz3: + Description: A reference to the created data subnet in az3 + Value: !Ref DataSubnet3 + Export: + Name: !Sub "${AWS::StackName}-SubnetDataAz3" \ No newline at end of file From e4e4a2fa4046899e29145a67e5b9b3790f5e8f2f Mon Sep 17 00:00:00 2001 From: Tom Date: Sat, 12 May 2018 13:37:22 +1000 Subject: [PATCH 2/3] added scaffolding artefact to circleci --- .circleci/config.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.circleci/config.yml b/.circleci/config.yml index 60adfdf6..a901591f 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -137,6 +137,10 @@ jobs: zip -r "output/TechTestApp_${version}_win32.zip" dist/* + - run: + name: Package up scaffolding + command: | + zip -r "output/scaffolds_${version}.zip" scaffolds - run: name: Release if new version From b3230f97177c9987c3fadce7e4f16bc6d3be3cbb Mon Sep 17 00:00:00 2001 From: Tom Date: Sat, 12 May 2018 13:39:09 +1000 Subject: [PATCH 3/3] version bump to trigger release --- cmd/version.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/version.go b/cmd/version.go index a6cc5002..8dbbdfa1 100644 --- a/cmd/version.go +++ b/cmd/version.go @@ -32,7 +32,7 @@ var versionCmd = &cobra.Command{ Short: "Displays the current version", Long: `Displays the current version of the application`, Run: func(cmd *cobra.Command, args []string) { - fmt.Println("Version: 0.2.1-pre-release") + fmt.Println("Version: 0.2.2-pre-release") }, }