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

Create ALIAS records for each exposed process #1005

Merged
merged 2 commits into from
Oct 8, 2016
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
**Features**

* The extended Procfile format now allows you to attach a load balancer to any process in the Procfile. [#800](https://github.com/remind101/empire/pull/800)
* An ALIAS record is now created for `<process>.<app>.<zone>` [#1005](https://github.com/remind101/empire/pull/1005)

**Improvements**

Expand Down
29 changes: 28 additions & 1 deletion scheduler/cloudformation/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,11 @@ func (t *EmpireTemplate) addService(tmpl *troposphere.Template, app *scheduler.A

loadBalancerType := loadBalancerType(app, p)

var loadBalancer troposphere.NamedResource
var (
loadBalancer troposphere.NamedResource
canonicalHostedZoneId interface{}
)

switch loadBalancerType {
case applicationLoadBalancer:
loadBalancer = troposphere.NamedResource{
Expand All @@ -421,6 +425,7 @@ func (t *EmpireTemplate) addService(tmpl *troposphere.Template, app *scheduler.A
},
},
}
canonicalHostedZoneId = GetAtt(loadBalancer, "CanonicalHostedZoneID")

tmpl.AddResource(loadBalancer)

Expand Down Expand Up @@ -527,6 +532,7 @@ func (t *EmpireTemplate) addService(tmpl *troposphere.Template, app *scheduler.A
loadBalancer = troposphere.NamedResource{
Name: fmt.Sprintf("%sLoadBalancer", key),
}
canonicalHostedZoneId = GetAtt(loadBalancer, "CanonicalHostedZoneNameID")

listeners := []map[string]interface{}{}

Expand Down Expand Up @@ -633,6 +639,27 @@ func (t *EmpireTemplate) addService(tmpl *troposphere.Template, app *scheduler.A
})
}

alias := troposphere.NamedResource{
Name: fmt.Sprintf("%sAlias", key),
Resource: troposphere.Resource{
Type: "AWS::Route53::RecordSet",
Condition: "DNSCondition",
Properties: map[string]interface{}{
"HostedZoneId": *t.HostedZone.Id,
"Name": fmt.Sprintf("%s.%s.%s", p.Type, app.Name, *t.HostedZone.Name),
"Type": "A",
"AliasTarget": map[string]interface{}{
"DNSName": GetAtt(loadBalancer, "DNSName"),
"EvaluateTargetHealth": "true",
"HostedZoneId": canonicalHostedZoneId,
},
},
},
}
tmpl.AddResource(alias)

// DEPRECATED: This was used in the world where only the "web"
// process could be exposed.
if p.Type == "web" {
tmpl.Resources["CNAME"] = troposphere.Resource{
Type: "AWS::Route53::RecordSet",
Expand Down
24 changes: 24 additions & 0 deletions scheduler/cloudformation/templates/basic-alb.json
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,30 @@
},
"Type": "AWS::Route53::RecordSet"
},
"webAlias": {
"Condition": "DNSCondition",
"Properties": {
"AliasTarget": {
"DNSName": {
"Fn::GetAtt": [
"webApplicationLoadBalancer",
"DNSName"
]
},
"EvaluateTargetHealth": "true",
"HostedZoneId": {
"Fn::GetAtt": [
"webApplicationLoadBalancer",
"CanonicalHostedZoneID"
]
}
},
"HostedZoneId": "Z3DG6IL3SJCGPX",
"Name": "web.acme-inc.empire",
"Type": "A"
},
"Type": "AWS::Route53::RecordSet"
},
"webApplicationLoadBalancer": {
"Properties": {
"Scheme": "internal",
Expand Down
24 changes: 24 additions & 0 deletions scheduler/cloudformation/templates/basic.json
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,30 @@
"Type": "Custom::InstancePort",
"Version": "1.0"
},
"webAlias": {
"Condition": "DNSCondition",
"Properties": {
"AliasTarget": {
"DNSName": {
"Fn::GetAtt": [
"webLoadBalancer",
"DNSName"
]
},
"EvaluateTargetHealth": "true",
"HostedZoneId": {
"Fn::GetAtt": [
"webLoadBalancer",
"CanonicalHostedZoneNameID"
]
}
},
"HostedZoneId": "Z3DG6IL3SJCGPX",
"Name": "web.acme-inc.empire",
"Type": "A"
},
"Type": "AWS::Route53::RecordSet"
},
"webLoadBalancer": {
"Properties": {
"ConnectionDrainingPolicy": {
Expand Down
24 changes: 24 additions & 0 deletions scheduler/cloudformation/templates/custom.json
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,30 @@
"Type": "Custom::InstancePort",
"Version": "1.0"
},
"webAlias": {
"Condition": "DNSCondition",
"Properties": {
"AliasTarget": {
"DNSName": {
"Fn::GetAtt": [
"webLoadBalancer",
"DNSName"
]
},
"EvaluateTargetHealth": "true",
"HostedZoneId": {
"Fn::GetAtt": [
"webLoadBalancer",
"CanonicalHostedZoneNameID"
]
}
},
"HostedZoneId": "Z3DG6IL3SJCGPX",
"Name": "web.acme-inc.empire",
"Type": "A"
},
"Type": "AWS::Route53::RecordSet"
},
"webEnvironment": {
"Properties": {
"Environment": [
Expand Down
48 changes: 48 additions & 0 deletions scheduler/cloudformation/templates/https-alb.json
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,30 @@
},
"Type": "AWS::Route53::RecordSet"
},
"apiAlias": {
"Condition": "DNSCondition",
"Properties": {
"AliasTarget": {
"DNSName": {
"Fn::GetAtt": [
"apiApplicationLoadBalancer",
"DNSName"
]
},
"EvaluateTargetHealth": "true",
"HostedZoneId": {
"Fn::GetAtt": [
"apiApplicationLoadBalancer",
"CanonicalHostedZoneID"
]
}
},
"HostedZoneId": "Z3DG6IL3SJCGPX",
"Name": "api.acme-inc.empire",
"Type": "A"
},
"Type": "AWS::Route53::RecordSet"
},
"apiApplicationLoadBalancer": {
"Properties": {
"Scheme": "internal",
Expand Down Expand Up @@ -270,6 +294,30 @@
},
"Type": "AWS::ECS::TaskDefinition"
},
"webAlias": {
"Condition": "DNSCondition",
"Properties": {
"AliasTarget": {
"DNSName": {
"Fn::GetAtt": [
"webApplicationLoadBalancer",
"DNSName"
]
},
"EvaluateTargetHealth": "true",
"HostedZoneId": {
"Fn::GetAtt": [
"webApplicationLoadBalancer",
"CanonicalHostedZoneID"
]
}
},
"HostedZoneId": "Z3DG6IL3SJCGPX",
"Name": "web.acme-inc.empire",
"Type": "A"
},
"Type": "AWS::Route53::RecordSet"
},
"webApplicationLoadBalancer": {
"Properties": {
"Scheme": "internal",
Expand Down
48 changes: 48 additions & 0 deletions scheduler/cloudformation/templates/https.json
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,30 @@
"Type": "Custom::InstancePort",
"Version": "1.0"
},
"apiAlias": {
"Condition": "DNSCondition",
"Properties": {
"AliasTarget": {
"DNSName": {
"Fn::GetAtt": [
"apiLoadBalancer",
"DNSName"
]
},
"EvaluateTargetHealth": "true",
"HostedZoneId": {
"Fn::GetAtt": [
"apiLoadBalancer",
"CanonicalHostedZoneNameID"
]
}
},
"HostedZoneId": "Z3DG6IL3SJCGPX",
"Name": "api.acme-inc.empire",
"Type": "A"
},
"Type": "AWS::Route53::RecordSet"
},
"apiLoadBalancer": {
"Properties": {
"ConnectionDrainingPolicy": {
Expand Down Expand Up @@ -262,6 +286,30 @@
"Type": "Custom::InstancePort",
"Version": "1.0"
},
"webAlias": {
"Condition": "DNSCondition",
"Properties": {
"AliasTarget": {
"DNSName": {
"Fn::GetAtt": [
"webLoadBalancer",
"DNSName"
]
},
"EvaluateTargetHealth": "true",
"HostedZoneId": {
"Fn::GetAtt": [
"webLoadBalancer",
"CanonicalHostedZoneNameID"
]
}
},
"HostedZoneId": "Z3DG6IL3SJCGPX",
"Name": "web.acme-inc.empire",
"Type": "A"
},
"Type": "AWS::Route53::RecordSet"
},
"webLoadBalancer": {
"Properties": {
"ConnectionDrainingPolicy": {
Expand Down