Skip to content

Commit

Permalink
feat: add api gateway
Browse files Browse the repository at this point in the history
  • Loading branch information
miguelpuiggarcia committed Sep 2, 2023
1 parent 466c400 commit c5f398a
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
19 changes: 19 additions & 0 deletions gcp/nandos-api-gateway/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,26 @@ resource "google_api_gateway_gateway" "nandos_api_gateway" {
region = var.project_region
}

# Create a managed SSL certificate
resource "google_compute_managed_ssl_certificate" "custom_ssl_cert" {
name = "custom-ssl-cert"
managed {
domains = [var.custom_domain]
}
}

# Update your API Gateway to use the custom domain and SSL certificate
# NOTE: This part depends on how your actual infrastructure is set up; the syntax might vary
resource "some_resource_to_attach_domain_and_ssl" "example" {
ssl_certificate = google_compute_managed_ssl_certificate.custom_ssl_cert.self_link
custom_domain = var.custom_domain
api_gateway_id = google_api_gateway_gateway.nandos_api_gateway.gateway_id
}

# Print the API Gateway URL
output "api_gateway_url_text" {
value = "Your API Gateway URL is: ${google_api_gateway_gateway.nandos_api_gateway.default_hostname}"
}
output "api_gateway_custom_domain_text" {
value = "Your API Gateway URL is: ${var.custom_domain}"
}
10 changes: 10 additions & 0 deletions gcp/nandos-api-gateway/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,13 @@ variable "openapi_spec_file_path" {
description = "The path to the OpenAPI spec file."
type = string
}

variable "custom_domain" {
description = "Nandos domain for the API Gateway."
type = string

validation {
condition = can(regex("^[a-zA-Z0-9-]+\\.nandos\\.dev$", var.custom_domain))
error_message = "The custom_domain must be a subdomain under nandos.dev. For example: myapi.nandos.dev."
}
}

0 comments on commit c5f398a

Please sign in to comment.