Skip to content

broadinstitute/terraform-google-redirect

Repository files navigation

terraform-google-redirect

Terraform module to build http/https redirects totally using GCP load balancer components.

Compatibility

This module is meant for use with Terraform 1.3+ and tested using Terraform 1.12. If you find incompatibilities using Terraform >=1.11, please open an issue.

Usage

module "http_redirects" {
  source   = "github.com/broadinstitute/terraform-google-redirect//modules/http_redirects"

  default_destination_host       = var.default_destination_host
  default_destination_path       = var.default_destination_path
  default_redirect_response_code = var.default_redirect_response_code
  hostnames                      = var.hostnames
  name                           = var.name
  project                        = google_project.default.project_id
  redirects                      = var.redirects
  ssl_policy                     = google_compute_ssl_policy.default.self_link
}
  • default_destination_host: The domain/hostname where any non-matching requests should go.
  • default_destination_path: The path under default_destination_host where any non-matching requests should go.
  • hostnames: A map of lists where each map is a certificate to be created, with the value being the list of hostnames that should be in the certificate.
  • redirects: A list of maps with any path-level redirects that should happen under the provided hostnames. This field can be left blank (i.e. []) which will effectively redirect all the provided hostnames to the default host and path. The fields within the map are:
    • destination_host: The host portion of the URL for the redirect
    • destination_path: The path portion of the URL for the redirect`
    • redirect_response_code: The HTTP code that should be used when doing a redirect.
    • source_paths: The list of paths under the source hostnames that should trigger a redirect. __Note: If you want to redirect a path ending with a slash (/) as well as one without a slash, you will need to make sure both paths are in the list.

Terraform docs

Terraform Docs created by running the following from the root of the repository:

podman run --rm -u $(id -u) \
    --volume "$(pwd):/terraform-docs" \
    -w /terraform-docs \
    quay.io/terraform-docs/terraform-docs:latest \
    --output-file ../../docs/README.md \
    --output-mode inject /terraform-docs/modules/http_redirects

Requirements

Name Version
terraform >= 1.10
google >= 6, < 7

Providers

Name Version
google >= 6, < 7

Modules

Name Source Version
certificates ../certificates n/a

Resources

Name Type
google_compute_global_address.public_address resource
google_compute_global_forwarding_rule.global_forwarding_http_rule resource
google_compute_global_forwarding_rule.global_forwarding_https_rule resource
google_compute_target_http_proxy.http_proxy resource
google_compute_target_https_proxy.https_proxy resource
google_compute_url_map.http_to_https_redirect resource
google_compute_url_map.https_url_map resource

Inputs

Name Description Type Default Required
default_destination_host The default host to redirect to if no paths are matched. string n/a yes
default_destination_path The default path to redirect to if no paths are matched. string n/a yes
hostnames A map of certificates to create, with the value being the list of hostnames map(list(string)) n/a yes
project The GCP project ID string n/a yes
redirects The map of redirects to apply to the path under the hostname.
list(object({
destination_host = string
destination_path = string
redirect_response_code = string
source_paths = list(string)
}))
n/a yes
default_redirect_response_code The default response code to use for redirects. string "MOVED_PERMANENTLY_DEFAULT" no
name The name to use for all resources created. string null no
ssl_policy The SSL policy to use for the redirects. string null no

Outputs

Name Description
load_balancer_ip_address IP address of the HTTP Cloud Load Balancer

About

Terraform module to create HTTP redirects using GCP components

Resources

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages