Skip to content

Commit

Permalink
feat: cdn aliases (#789)
Browse files Browse the repository at this point in the history
* feat(cdn): add support for multiple aliases

- Adds support for setting multiple aliases on CloudFront

* feat(lb): add ec2 based links on ports

- Adds support for link based ec2 instances on ports
  • Loading branch information
roleyfoley authored Nov 16, 2023
1 parent de835de commit 81eac9d
Show file tree
Hide file tree
Showing 3 changed files with 111 additions and 8 deletions.
9 changes: 9 additions & 0 deletions aws/components/cdn/setup.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,15 @@
[#local aliases += [ formatDomainName(hostName, domain.Name) ] ]
[/#list]

[#list solution.Aliases as id, alias ]
[#local aliasCertificateObject = getCertificateObject(alias.Hostname) ]
[#local aliasHostName = getHostName(aliasCertificateObject, occurrence) ]

[#list aliasCertificateObject.Domains as aliasDomain ]
[#local aliases += [ formatDomainName(aliasHostName, aliasDomain)]]
[/#list]
[/#list]

[#local origins = []]
[#local cacheBehaviours = []]
[#local defaultCacheBehaviour = []]
Expand Down
28 changes: 20 additions & 8 deletions aws/components/lb/setup.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -1005,14 +1005,26 @@

[#case EC2_COMPONENT_TYPE]
[#list linkTargetResources["Zones"] as zone, resources ]
[#if getExistingReference(resources["ec2ENI"].Id, IP_ADDRESS_ATTRIBUTE_TYPE)?has_content ]
[#local staticTargets +=
getTargetGroupTarget(
"ip",
getExistingReference(resources["ec2ENI"].Id, IP_ADDRESS_ATTRIBUTE_TYPE),
destinationPort.Port,
false
)]
[#if solution.Forward.TargetType == "ip" ]
[#if getExistingReference(resources["ec2ENI"].Id, IP_ADDRESS_ATTRIBUTE_TYPE)?has_content ]
[#local staticTargets +=
getTargetGroupTarget(
"ip",
getExistingReference(resources["ec2ENI"].Id, IP_ADDRESS_ATTRIBUTE_TYPE),
destinationPort.Port,
false
)]
[/#if]
[#elseif solution.Forward.TargetType == "instance" ]
[#if getExistingReference(resources["ec2Instance"].Id)?has_content ]
[#local staticTargets +=
getTargetGroupTarget(
"instance",
getExistingReference(resources["ec2Instance"].Id),
destinationPort.Port,
false
)]
[/#if]
[/#if]
[/#list]
[#break]
Expand Down
82 changes: 82 additions & 0 deletions awstest/modules/cdn/module.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -536,4 +536,86 @@
}
]
/]

[#-- Aliases --]
[@loadModule
blueprint={
"Tiers" : {
"web" : {
"Components" : {
"cdnaliases": {
"Type": "cdn",
"deployment:Unit": "aws-cdn",
"Hostname" : {},
"Aliases": {
"env": {
"Hostname" : {
"IncludeInDomain" : {
"Environment" : true
},
"IncludeInHost" : {
"Environment" : false,
"Component": false,
"Host": true
},
"Host": "alias"
}
}
},
"Routes" : {
"default" : {
"PathPattern" : "_default",
"OriginSource" : "Placeholder",
"RedirectAliases" : {
"Enabled": false
}
}
},
"Profiles" : {
"Testing" : [ "cdnaliases" ]
}
}
}
}
},
"TestCases" : {
"cdnaliases" : {
"OutputSuffix" : "template.json",
"Structural" : {
"CFN" : {
"Resource" : {
"cfXwebXcdnaliases" : {
"Name" : "cfXwebXcdnaliases",
"Type" : "AWS::CloudFront::Distribution"
}
},
"Output" : [
"cfXwebXcdnaliasesXdns",
"cfXwebXcdnaliases"
]
},
"JSON" : {
"Match" : {
"Aliases" : {
"Path" : "Resources.cfXwebXcdnaliases.Properties.DistributionConfig.Aliases",
"Value" : ["cdnaliases-integration.mock.local", "alias.integration.mock.local"]
}
}
}
}
}
},
"TestProfiles" : {
"cdnaliases" : {
"cdn" : {
"TestCases" : [ "cdnaliases" ]
},
"*" : {
"TestCases" : [ "_cfn-lint" ]
}
}
}
}

/]
[/#macro]

0 comments on commit 81eac9d

Please sign in to comment.