-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for creating external resources associated with self-mana…
…ged certificates
- Loading branch information
Showing
12 changed files
with
195 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# Custom Domain with Self-managed Certificates on GCP | ||
|
||
This example sets up an Auth0 tenant with a custom domain that uses self-managed certificates. It also configures the appropriate resources in Google Cloud Platform to forward requests to Auth0 over HTTPS. | ||
|
||
To use this example, in addition to setting the usual Auth0 environment variables, you will also need to set `GOOGLE_PROJECT` and `GOOGLE_CREDENTIALS` (or equivalent; see [the provider reference](https://registry.terraform.io/providers/hashicorp/google/latest/docs/guides/provider_reference#authentication) for more information). | ||
|
||
Note that Google-managed certificates take some time to provision. If everything in the configuration looks right but you're getting TLS errors trying to load your custom domain, you should wait 5-10 minutes and then refresh the page. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
resource "google_compute_global_address" "lb_ipv4" { | ||
name = "auth0-ipv4" | ||
ip_version = "IPV4" | ||
} | ||
|
||
resource "google_compute_global_address" "lb_ipv6" { | ||
name = "auth0-ipv6" | ||
ip_version = "IPV6" | ||
} | ||
|
||
resource "google_dns_record_set" "lb_a" { | ||
name = "${var.domain}." | ||
managed_zone = var.managed_zone_name | ||
type = "A" | ||
ttl = 300 | ||
rrdatas = [ | ||
google_compute_global_address.lb_ipv4.address, | ||
] | ||
} | ||
|
||
resource "google_dns_record_set" "lb_aaaa" { | ||
name = "${var.domain}." | ||
managed_zone = var.managed_zone_name | ||
type = "AAAA" | ||
ttl = 300 | ||
rrdatas = [ | ||
google_compute_global_address.lb_ipv6.address, | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
provider "auth0" {} | ||
|
||
provider "google" {} | ||
|
||
resource "auth0_custom_domain" "my_domain" { | ||
domain = var.domain | ||
type = "self_managed_certs" | ||
} | ||
|
||
resource "google_dns_record_set" "my_domain_verification" { | ||
name = "${auth0_custom_domain.my_domain.verification[0].methods[0].domain}." | ||
managed_zone = var.managed_zone_name | ||
type = upper(auth0_custom_domain.my_domain.verification[0].methods[0].name) | ||
ttl = 300 | ||
rrdatas = [ | ||
"${auth0_custom_domain.my_domain.verification[0].methods[0].record}.", | ||
] | ||
} | ||
|
||
resource "auth0_custom_domain_verification" "my_domain" { | ||
custom_domain_id = auth0_custom_domain.my_domain.id | ||
|
||
depends_on = [ | ||
google_dns_record_set.my_domain_verification, | ||
] | ||
|
||
timeouts { | ||
create = "15m" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
resource "google_compute_global_network_endpoint_group" "proxy" { | ||
name = "auth0-proxy" | ||
network_endpoint_type = "INTERNET_FQDN_PORT" | ||
} | ||
|
||
resource "google_compute_global_network_endpoint" "proxy" { | ||
global_network_endpoint_group = google_compute_global_network_endpoint_group.proxy.name | ||
|
||
fqdn = auth0_custom_domain_verification.my_domain.origin_domain_name | ||
port = 443 | ||
} | ||
|
||
resource "google_compute_backend_service" "proxy" { | ||
name = "auth0-proxy" | ||
description = "Auth0 authentication proxy" | ||
|
||
backend { | ||
group = google_compute_global_network_endpoint_group.proxy.self_link | ||
} | ||
|
||
protocol = "HTTPS" | ||
enable_cdn = false | ||
|
||
log_config { | ||
enable = true | ||
} | ||
|
||
custom_request_headers = [ | ||
"host: ${auth0_custom_domain_verification.my_domain.origin_domain_name}", | ||
"cname-api-key: ${auth0_custom_domain_verification.my_domain.cname_api_key}", | ||
] | ||
} | ||
|
||
resource "google_compute_url_map" "proxy_https" { | ||
name = "auth0-proxy-https" | ||
description = "HTTPS endpoint for the Auth0 authentication proxy" | ||
|
||
default_service = google_compute_backend_service.proxy.self_link | ||
} | ||
|
||
resource "google_compute_managed_ssl_certificate" "proxy" { | ||
name = "auth0-proxy-https" | ||
|
||
managed { | ||
domains = [var.domain] | ||
} | ||
} | ||
|
||
resource "google_compute_target_https_proxy" "proxy" { | ||
name = "auth0-proxy-https" | ||
url_map = google_compute_url_map.proxy_https.self_link | ||
ssl_certificates = [ | ||
google_compute_managed_ssl_certificate.proxy.self_link, | ||
] | ||
} | ||
|
||
resource "google_compute_global_forwarding_rule" "proxy_https_ipv4" { | ||
name = "auth0-proxy-https-ipv4" | ||
load_balancing_scheme = "EXTERNAL" | ||
port_range = "443" | ||
|
||
ip_address = google_compute_global_address.lb_ipv4.address | ||
target = google_compute_target_https_proxy.proxy.self_link | ||
} | ||
|
||
resource "google_compute_global_forwarding_rule" "proxy_https_ipv6" { | ||
name = "auth0-proxy-https-ipv6" | ||
load_balancing_scheme = "EXTERNAL" | ||
port_range = "443" | ||
|
||
ip_address = google_compute_global_address.lb_ipv6.address | ||
target = google_compute_target_https_proxy.proxy.self_link | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
variable "domain" { | ||
description = "The name of the custom domain to provision" | ||
type = string | ||
} | ||
|
||
variable "managed_zone_name" { | ||
description = "The name of the Cloud DNS managed zone to create DNS records in" | ||
type = string | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
terraform { | ||
required_providers { | ||
auth0 = { | ||
source = "auth0/auth0" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters