Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(router): support for static routes #57

Merged
merged 3 commits into from
Jun 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
100 changes: 48 additions & 52 deletions aws/components/gateway/setup.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,15 @@
[#if !legacyIGW ]
[#local IGWId = gwResources["internetGateway"].Id ]
[#local IGWName = gwResources["internetGateway"].Name ]
[#local IGWAttachementId = gwResources["internetGatewayAttachement"].Id ]
[#local IGWAttachmentId = gwResources["internetGatewayAttachment"].Id ]

[#if deploymentSubsetRequired(NETWORK_GATEWAY_COMPONENT_TYPE, true)]
[@createIGW
id=IGWId
name=IGWName
/]
[@createIGWAttachment
id=IGWAttachementId
id=IGWAttachmentId
vpcId=vpcId
igwId=IGWId
/]
Expand All @@ -116,15 +116,16 @@
[#local transitGateway = ""]
[#local transitGatewayRouteTable = ""]

[#local localRouter = true]
[#local routerFound = false]

[#local attachementSubnets = [] ]
[#local attachmentSubnets = [] ]
[#list networkResources["subnets"][gwCore.Tier.Id] as zone,resources]
[#local attachementSubnets += [ resources["subnet"].Id ] ]
[#local attachmentSubnets += [ resources["subnet"].Id ] ]
[/#list]

[#local transitGatewayAttachementId = gwResources["transitGatewayAttachement"].Id ]
[#local transitGatewayAttachementName = gwResources["transitGatewayAttachement"].Name ]
[#local transitGatewayAttachmentId = gwResources["transitGatewayAttachment"].Id ]
[#local transitGatewayAttachmentName = gwResources["transitGatewayAttachment"].Name ]
[#local transitGatewayRoutePropogationId = gwResources["routePropogation"].Id ]
[#local routeTableAssociationId = gwResources["routeAssociation"].Id ]
[#break]
Expand Down Expand Up @@ -206,16 +207,8 @@

[#switch linkTargetCore.Type]

[#case EXTERNALNETWORK_CONNECTION_COMPONENT_TYPE ]
[#if gwSolution.Engine == "private" ]

[/#if]

[#break]

[#case NETWORK_ROUTER_COMPONENT_TYPE]
[#if gwSolution.Engine == "router" ]

[#if routerFound ]
[@fatal
message="Multiple routers found, only one per gateway is supported"
Expand All @@ -234,16 +227,15 @@
[#case EXTERNALSERVICE_COMPONENT_TYPE]
[#if gwSolution.Engine == "router" ]
[#local transitGateway = linkTargetAttributes["TRANSIT_GATEWAY_ID"]!"" ]
[#local transitGatewayRouteTable = linkTargetAttributes["ROUTE_TABLE_ID"]!"" ]

[#if transitGateway?has_content && transitGatewayRouteTable?has_content ]
[#local routerFound = true ]
[#if transitGateway?has_content ]
[#local routerFound = true ]
[#local localRouter = false ]
[#else]
[@fatal
message="Could not find Attributes for external Transit Gateway or multiple gateways set"
context={
"TRANSIT_GATEWAY_ID" : linkTargetAttributes["TRANSIT_GATEWAY_ID"]!"",
"ROUTE_TABLE_ID" : linkTargetAttributes["ROUTE_TABLE_ID"]!""
"TRANSIT_GATEWAY_ID" : linkTargetAttributes["TRANSIT_GATEWAY_ID"]!""
}
/]
[#continue]
Expand All @@ -266,33 +258,35 @@

[#if deploymentSubsetRequired(NETWORK_GATEWAY_COMPONENT_TYPE, true)]
[@createTransitGatewayAttachment
id=transitGatewayAttachementId
name=transitGatewayAttachementName
id=transitGatewayAttachmentId
name=transitGatewayAttachmentName
transitGateway=transitGateway
subnets=getReferences(attachementSubnets)
subnets=getReferences(attachmentSubnets)
vpc=getReference(vpcId)
/]

[@createTransitGatewayRouteTableAssociation
id=routeTableAssociationId
transitGatewayAttachment=getReference(transitGatewayAttachementId)
transitGatewayRouteTable=transitGatewayRouteTable
/]

[#list sourceCidrs as souceCidr ]
[#local vpcRouteId = formatResourceId(
AWS_TRANSITGATEWAY_ROUTE_RESOURCE_TYPE,
gwCore.Id,
souceCidr?index
)]

[@createTransitGatewayRoute
id=vpcRouteId
transitGatewayRouteTable=transitGatewayRouteTable
transitGatewayAttachment=getReference(transitGatewayAttachementId)
destinationCidr=souceCidr
[#if localRouter ]
[@createTransitGatewayRouteTableAssociation
id=routeTableAssociationId
transitGatewayAttachment=getReference(transitGatewayAttachmentId)
transitGatewayRouteTable=transitGatewayRouteTable
/]
[/#list]

[#list sourceCidrs as souceCidr ]
[#local vpcRouteId = formatResourceId(
AWS_TRANSITGATEWAY_ROUTE_RESOURCE_TYPE,
gwCore.Id,
souceCidr?index
)]

[@createTransitGatewayRoute
id=vpcRouteId
transitGatewayRouteTable=transitGatewayRouteTable
transitGatewayAttachment=getReference(transitGatewayAttachmentId)
destinationCidr=souceCidr
/]
[/#list]
[/#if]
[/#if]
[#break]
[/#switch]
Expand Down Expand Up @@ -451,7 +445,7 @@
destinationType="gateway"
destinationAttribute=getReference(IGWId)
destinationCidr=cidr
dependencies=IGWAttachementId
dependencies=IGWAttachmentId
/]
[/#list]
[#else]
Expand All @@ -464,16 +458,18 @@
[#break]

[#case "router"]
[#list cidrs as cidr ]
[@createRoute
id=formatRouteId(zoneRouteTableId, core.Id, cidr?index)
routeTableId=zoneRouteTableId
destinationType="transit"
destinationAttribute=transitGateway
destinationCidr=cidr
dependencies=transitGatewayAttachementId
/]
[/#list]
[#if localRouter ]
[#list cidrs as cidr ]
[@createRoute
id=formatRouteId(zoneRouteTableId, core.Id, cidr?index)
routeTableId=zoneRouteTableId
destinationType="transit"
destinationAttribute=transitGateway
destinationCidr=cidr
dependencies=transitGatewayAttachmentId
/]
[/#list]
[/#if]
[#break]

[#case "private" ]
Expand Down
23 changes: 15 additions & 8 deletions aws/components/gateway/state.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
[#local core = occurrence.Core]
[#local solution = occurrence.Configuration.Solution]
[#local engine = solution.Engine ]
[#local resources = {} ]
[#local resources = {}]
[#local attributes = {}]
[#local zoneResources = {}]

[#if multiAZ!false ]
Expand Down Expand Up @@ -65,7 +66,7 @@
"Name" : core.FullName,
"Type" : AWS_VPC_IGW_RESOURCE_TYPE
},
"internetGatewayAttachement" : {
"internetGatewayAttachment" : {
"Id" : formatId(AWS_VPC_IGW_ATTACHMENT_TYPE, core.Id),
"Type" : AWS_VPC_IGW_ATTACHMENT_TYPE
}
Expand All @@ -74,12 +75,15 @@
[#break]

[#case "router" ]
[#local resources += {
"transitGatewayAttachement" : {
"Id" : formatResourceId(

[#local transitGatewayAttachmentId = formatResourceId(
AWS_TRANSITGATEWAY_ATTACHMENT_RESOURCE_TYPE,
core.Id
),
)]

[#local resources += {
"transitGatewayAttachment" : {
"Id" : transitGatewayAttachmentId,
"Name" : core.FullName,
"Type" : AWS_TRANSITGATEWAY_ATTACHMENT_RESOURCE_TYPE
},
Expand All @@ -99,6 +103,10 @@
}

}]

[#local attributes += {
"TRANSIT_GATEWAY_ATTACHMENT" : getExistingReference(transitGatewayAttachmentId)
}]
[#break]

[#case "vpcendpoint"]
Expand Down Expand Up @@ -195,8 +203,7 @@
{
"Zones" : zoneResources
},
"Attributes" : {
},
"Attributes" : attributes,
"Roles" : {
"Inbound" : {},
"Outbound" : {}
Expand Down
11 changes: 11 additions & 0 deletions aws/components/router/id.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,14 @@
AWS_RESOURCE_ACCESS_SERVICE
]
/]

[@addResourceGroupInformation
type=NETWORK_ROUTER_STATIC_ROUTE_COMPONENT_TYPE
attributes=[]
provider=AWS_PROVIDER
resourceGroup=DEFAULT_RESOURCE_GROUP
services=
[
AWS_TRANSIT_GATEWAY_SERVICE
]
/]
88 changes: 88 additions & 0 deletions aws/components/router/setup.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,92 @@
/]
[/#if]
[/#if]

[#list occurrence.Occurrences![] as subOccurrence]

[#local core = subOccurrence.Core ]
[#local solution = subOccurrence.Configuration.Solution ]
[#local resources = subOccurrence.State.Resources ]

[#local destinationCidrs = getGroupCIDRs(solution.IPAddressGroups, true, occurrence)]

[#switch solution.Action ]
[#case "forward" ]
[#list solution.Links?values as link]
[#if link?is_hash]

[#local linkTarget = getLinkTarget(occurrence, link) ]

[@debug message="Link Target" context=linkTarget enabled=false /]

[#if !linkTarget?has_content]
[#continue]
[/#if]

[#local linkTargetCore = linkTarget.Core ]
[#local linkTargetConfiguration = linkTarget.Configuration ]
[#local linkTargetResources = linkTarget.State.Resources ]
[#local linkTargetAttributes = linkTarget.State.Attributes ]

[#switch linkTargetCore.Type]
[#case EXTERNALSERVICE_COMPONENT_TYPE ]

[#local transitGatewayAttachment = (linkTargetAttributes["TRANSIT_GATEWAY_ATTACHMENT"])!""]

[#if ! transitGatewayAttachment?has_content ]
[#if deploymentSubsetRequired(NETWORK_ROUTER_COMPONENT_TYPE, true)]
[@fatal
message="Could not find transit Gateway Attachment Id"
detail="Add setting TRANSIT_GATEWAY_ATTACHMENT as the transit gateawy attachment for the route"
enabled=false
/]
[/#if]
[/#if]

[#local routeTableAssociationId = resources["routeAssociations"][linkTargetCore.Id].Id]

[#if deploymentSubsetRequired(NETWORK_ROUTER_COMPONENT_TYPE, true)]
[@createTransitGatewayRouteTableAssociation
id=routeTableAssociationId
transitGatewayAttachment=transitGatewayAttachment
transitGatewayRouteTable=getReference(routeTableId)
/]
[/#if]

[#list destinationCidrs as destinationCidr ]
[#local destinationCidrId = replaceAlphaNumericOnly(destinationCidr)]
[#local routeId = resources["routes"][linkTargetCore.Id][destinationCidrId].Id ]

[#if deploymentSubsetRequired(NETWORK_ROUTER_COMPONENT_TYPE, true)]
[@createTransitGatewayRoute
id=routeId
transitGatewayRouteTable=getReference(routeTableId)
transitGatewayAttachment=transitGatewayAttachment
destinationCidr=destinationCidr
/]
[/#if]
[/#list]
[#break]
[/#switch]
[/#if]
[/#list]
[#break]

[#case "blackhole" ]
[#list destinationCidrs as destinationCidr ]
[#local destinationCidrId = replaceAlphaNumericOnly(destinationCidr)]
[#local routeId = resources["routes"][destinationCidrId].Id ]

[#if deploymentSubsetRequired(NETWORK_ROUTER_COMPONENT_TYPE, true)]
[@createTransitGatewayRoute
id=routeId
transitGatewayRouteTable=getReference(routeTableId)
blackhole=true
destinationCidr=destinationCidr
/]
[/#if]
[/#list]
[#break]
[/#switch]
[/#list]
[/#macro]