Skip to content

Commit

Permalink
Merge pull request #15 from theonestack/custom_routes_with_ref
Browse files Browse the repository at this point in the history
allows custom routes to use a ref
  • Loading branch information
aaronwalker committed Feb 24, 2023
2 parents 3f61210 + 43ca093 commit 98a3aac
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 42 deletions.
23 changes: 3 additions & 20 deletions .github/workflows/rspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,6 @@ name: cftest
on: [push, pull_request]

jobs:
test:
name: test
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: set up ruby 2.7
uses: actions/setup-ruby@v1
with:
ruby-version: 2.7.x
- name: install gems
run: gem install cfhighlander rspec
- name: set cfndsl spec
run: cfndsl -u
- name: cftest
run: rspec
env:
AWS_ACCESS_KEY: ${{ secrets.AWS_ACCESS_KEY }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_REGION: ap-southeast-2
rspec:
uses: theonestack/shared-workflows/.github/workflows/rspec.yaml@main
secrets: inherit
18 changes: 18 additions & 0 deletions spec/custom_routes_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,22 @@

end

context 'Resource CustomRoute05' do

let(:properties) { template["Resources"]["CustomRoute05"]["Properties"] }

it 'has property RouteTableId' do
expect(properties["RouteTableId"]).to eq({"Ref"=>"RouteTablePrivate0"})
end

it 'has property DestinationCidrBlock' do
expect(properties["DestinationCidrBlock"]).to eq("192.168.65.0/22")
end

it 'has property TransitGatewayId' do
expect(properties["TransitGatewayId"]).to eq({"Ref" => "TransitGateway"})
end

end

end
7 changes: 7 additions & 0 deletions tests/custom_routes.test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ test_metadata:
name: custom_routes
description: custom routes in code

test_parameters:
TransitGateway: tgw-0a9c82d1928fce121

tags:
Application: MyApp
CreatedBy: theonestack
Expand All @@ -15,3 +18,7 @@ custom_routes:
10.9.0.0/16: tgw-0a9c82d1928fce121
10.10.0.0/16: tgw-0a9c82d1928fce121
192.168.64.0/22: tgw-0a9c82d1928fce121
192.168.65.0/22:
type: tgw
value:
Ref: TransitGateway
57 changes: 35 additions & 22 deletions vpc-v2.cfndsl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -112,33 +112,40 @@
##
if custom_routes.length > 0
custom_routes.each_with_index do |(key,value),index|
routeType = value.split('-').first

if value.is_a?(String)
routeType = value.split('-').first
routeValue = value
else
routeType = value['type']
routeValue = value['value']
end

EC2_Route("CustomRoutePublic#{index}") {
DependsOn ['AttachGateway']
RouteTableId Ref(:RouteTablePublic)
DestinationCidrBlock key
case routeType
when "tgw"
TransitGatewayId value
TransitGatewayId routeValue
when "eigw"
EgressOnlyInternetGatewayId value
EgressOnlyInternetGatewayId routeValue
when "vpce"
VpcEndpointId value
VpcEndpointId routeValue
when "vgw"
GatewayId value
GatewayId routeValue
when "igw"
GatewayId value
GatewayId routeValue
when "nat"
NatGatewayId value
NatGatewayId routeValue
when "i"
InstanceId value
InstanceId routeValue
when "eni"
NetworkInterfaceId value
NetworkInterfaceId routeValue
when "pcx"
VpcPeeringConnectionId value
VpcPeeringConnectionId routeValue
when "lgw"
LocalGatewayId value
LocalGatewayId routeValue
end
}

Expand Down Expand Up @@ -364,32 +371,38 @@
##
if custom_routes.length > 0
custom_routes.each_with_index do |(key,value),index|
routeType = value.split('-').first
if value.is_a?(String)
routeType = value.split('-').first
routeValue = value
else
routeType = value['type']
routeValue = value['value']
end

EC2_Route("CustomRoute#{az}#{index}") {
RouteTableId Ref("RouteTablePrivate#{az}")
DestinationCidrBlock key
case routeType
when "tgw"
TransitGatewayId value
TransitGatewayId routeValue
when "eigw"
EgressOnlyInternetGatewayId value
EgressOnlyInternetGatewayId routeValue
when "vpce"
VpcEndpointId value
VpcEndpointId routeValue
when "vgw"
GatewayId value
GatewayId routeValue
when "igw"
GatewayId value
GatewayId routeValue
when "nat"
NatGatewayId value
NatGatewayId routeValue
when "i"
InstanceId value
InstanceId routeValue
when "eni"
NetworkInterfaceId value
NetworkInterfaceId routeValue
when "pcx"
VpcPeeringConnectionId value
VpcPeeringConnectionId routeValue
when "lgw"
LocalGatewayId value
LocalGatewayId routeValue
end
}

Expand Down

0 comments on commit 98a3aac

Please sign in to comment.