diff --git a/infra/docs_bucket.tf b/infra/docs_bucket.tf index 3832338b145..f8c86530b59 100644 --- a/infra/docs_bucket.tf +++ b/infra/docs_bucket.tf @@ -16,6 +16,7 @@ module "daml_docs" { project = "${local.project}" region = "${local.region}" ssl_certificate = "${local.ssl_certificate}" + default_file = "docs" // We do not want to delete anything here, but Terraform composition is hard // so instead keep objects for 100 years. diff --git a/infra/modules/gcp_cdn_bucket/README.md b/infra/modules/gcp_cdn_bucket/README.md index 1b522314af2..64f831fdcb4 100644 --- a/infra/modules/gcp_cdn_bucket/README.md +++ b/infra/modules/gcp_cdn_bucket/README.md @@ -19,6 +19,7 @@ It also makes a few assumptions: | Name | Description | Type | Default | Required | |------|-------------|:----:|:-----:|:-----:| | cache\_retention\_days | The number of days to keep the objects around | string | n/a | yes | +| default\_file | The name of the file (from the files folder) to show for unknown paths. Currently one of cache or docs. | string | `"cache"` | no | | labels | Labels to apply on all the resources | map | `` | no | | name | Name prefix for all the resources | string | n/a | yes | | project | GCP project name | string | n/a | yes | @@ -32,4 +33,4 @@ It also makes a few assumptions: | bucket\_name | Name of the GCS bucket that will receive the objects. | | external\_ip | The external IP assigned to the global fowarding rule. | - \ No newline at end of file + diff --git a/infra/modules/gcp_cdn_bucket/files/index.html b/infra/modules/gcp_cdn_bucket/files/cache.html similarity index 100% rename from infra/modules/gcp_cdn_bucket/files/index.html rename to infra/modules/gcp_cdn_bucket/files/cache.html diff --git a/infra/modules/gcp_cdn_bucket/files/docs.html b/infra/modules/gcp_cdn_bucket/files/docs.html new file mode 100644 index 00000000000..133620229da --- /dev/null +++ b/infra/modules/gcp_cdn_bucket/files/docs.html @@ -0,0 +1,42 @@ + + + + + + + + + + + + + + + + + + + + + + + + + +
+

There is nothing here

+ Back to safety +
+ + diff --git a/infra/modules/gcp_cdn_bucket/google_storage.tf b/infra/modules/gcp_cdn_bucket/google_storage.tf index 2b98c8a0296..d056e899820 100644 --- a/infra/modules/gcp_cdn_bucket/google_storage.tf +++ b/infra/modules/gcp_cdn_bucket/google_storage.tf @@ -41,6 +41,7 @@ resource "google_storage_bucket" "default" { website { main_page_suffix = "index.html" + not_found_page = "${var.default_file == "docs" ? "not-found.html" : ""}" } force_destroy = true @@ -53,9 +54,19 @@ resource "google_storage_bucket_acl" "default" { } resource "google_storage_bucket_object" "default" { + count = "${var.default_file == "cache" ? 1 : 0}" name = "index.html" bucket = "${google_storage_bucket.default.name}" - content = "${file("${path.module}/files/index.html")}" + content = "${file("${path.module}/files/${var.default_file}.html")}" + content_type = "text/html" + depends_on = ["google_storage_bucket_acl.default"] +} + +resource "google_storage_bucket_object" "not_found" { + count = "${var.default_file == "docs" ? 1 : 0}" + name = "not-found.html" + bucket = "${google_storage_bucket.default.name}" + content = "${file("${path.module}/files/${var.default_file}.html")}" content_type = "text/html" depends_on = ["google_storage_bucket_acl.default"] } diff --git a/infra/modules/gcp_cdn_bucket/variables.tf b/infra/modules/gcp_cdn_bucket/variables.tf index 2c49cf88a56..60a9cf1f54d 100644 --- a/infra/modules/gcp_cdn_bucket/variables.tf +++ b/infra/modules/gcp_cdn_bucket/variables.tf @@ -26,3 +26,8 @@ variable "ssl_certificate" { variable "cache_retention_days" { description = "The number of days to keep the objects around" } + +variable "default_file" { + description = "The name of the file (from the files folder) to show for unknown paths. Currently one of cache or docs." + default = "cache" +}