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

Deploy custom domain with Terraform #1232

Merged
merged 3 commits into from
May 30, 2018
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
2 changes: 2 additions & 0 deletions environment
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ DSS_ES_DOMAIN="dss-index-$DSS_DEPLOYMENT_STAGE"
DSS_ES_INSTANCE_TYPE="m4.large.elasticsearch"
DSS_ES_VOLUME_SIZE="35"
DSS_ES_INSTANCE_COUNT="1"
DSS_CERTIFICATE_DOMAIN="*.dev.data.humancellatlas.org"
DSS_ZONE_NAME="dev.data.humancellatlas.org."
PYTHONWARNINGS=ignore:ResourceWarning,ignore::UserWarning:zipfile:
DSS_SECRETS_STORE="dcp/dss"
EVENT_RELAY_AWS_USERNAME="dss-event-relay-${DSS_DEPLOYMENT_STAGE}"
Expand Down
2 changes: 1 addition & 1 deletion infra/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ destroy: init
cd $(COMPONENT); terraform destroy

init:
rm -rf $(COMPONENT)/.terraform
rm -rf $(COMPONENT)/.terraform/*.tfstate
./build_deploy_config.py $(COMPONENT)
cd $(COMPONENT); terraform init;

Expand Down
3 changes: 3 additions & 0 deletions infra/build_deploy_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@
"DSS_GS_BUCKET_REGION",
"DSS_GS_BUCKET_TEST_REGION",
"DSS_GS_BUCKET_TEST_FIXTURES_REGION",
"API_DOMAIN_NAME",
"DSS_CERTIFICATE_DOMAIN",
"DSS_ZONE_NAME",
]

terraform_variable_info = {'variable': dict()}
Expand Down
40 changes: 40 additions & 0 deletions infra/domain/create_regional_domain_name.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/usr/bin/env python

"""
This script configures a regional domain name for API Gateway, based on an existing
certificate, and Route 53 zone. The certificate must be in the same region as the regional
domain.
"""

import os
import sys
import json
import boto3
import argparse

parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("--domain-name", required=True)
parser.add_argument("--certificate-arn", required=True)
parser.add_argument("--zone-id", required=True)
args = parser.parse_args()

resp = boto3.client("apigateway").create_domain_name(
domainName=args.domain_name,
regionalCertificateArn=args.certificate_arn,
endpointConfiguration={'types': ["REGIONAL"]}
)

boto3.client("route53").change_resource_record_sets(
HostedZoneId=args.zone_id,
ChangeBatch={
'Changes': [{
'Action': 'CREATE',
'ResourceRecordSet': {
'Name': f"{args.domain_name}.",
'Type': 'CNAME',
'ResourceRecords': [ {'Value': resp['regionalDomainName']} ],
'TTL': 300,
}
}]
}
)
18 changes: 18 additions & 0 deletions infra/domain/domain.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
data aws_caller_identity current {}

data aws_route53_zone dss_route53_zone {
name = "${var.DSS_ZONE_NAME}"
}

data aws_acm_certificate dss_domain_cert {
domain = "${var.DSS_CERTIFICATE_DOMAIN}"
}

# TODO: Configure regional domain name with Terraform
# Terraform does not currently support regional API Gateway endpoints:
# https://github.com/terraform-providers/terraform-provider-aws/issues/2195
resource null_resource dss_domain {
provisioner "local-exec" {
command = "./create_regional_domain_name.py --domain-name ${var.API_DOMAIN_NAME} --certificate-arn ${data.aws_acm_certificate.dss_domain_cert.arn} --zone-id ${data.aws_route53_zone.dss_route53_zone.zone_id}"
}
}