terraform-google-modules / terraform-google-lb-http

Creates a global HTTP load balancer for Compute Engine by using forwarding rules
https://registry.terraform.io/modules/terraform-google-modules/lb-http/google
Apache License 2.0
312 stars 356 forks source link

Creating a load balancer for a storage bucket #198

Open chubibest opened 3 years ago

chubibest commented 3 years ago

I want to spin up a load balancer with an ip for a storage bucket, but I run into this error whenever I run 'terraform apply'

Screenshot 2021-08-11 at 16 08 24

This is my config file

resource "google_compute_backend_bucket" "storage_bucket_backend" {
  name        = "storage-bucket-backend"
  description = "${var.project} storage bucket"
  bucket_name = google_storage_bucket.storage_bucket.name
  enable_cdn  = true
  project       = var.project
}

resource "google_storage_bucket" "storage_bucket" {
  name     = "storage-bucket"
}

resource "google_storage_bucket_access_control" "public_rule" {
  bucket = google_storage_bucket.storage_bucket.name
  role   = "READER"
  entity = "allUsers"
}

module "cdn-lb-http" {
  source            = "GoogleCloudPlatform/lb-http/google"
  version = "~> 4.4"
  project           = var.project
  name              = "storage-bucket-backend-load-balancer"
  backends = {
    default = {

      affinity_cookie_ttl_sec         = null
      connection_draining_timeout_sec = null
      custom_request_headers          = null
      custom_response_headers         = null
      description                     = null
      enable_cdn                      = true

            protocol                        = "HTTP"
      port                            = 80
      port_name                       = "http"
      timeout_sec                     = 10
      connection_draining_timeout_sec = null
      enable_cdn                      = false
      security_policy                 = null
      session_affinity                = null
        health_check = {
        check_interval_sec  = null
        timeout_sec         = null
        healthy_threshold   = null
        unhealthy_threshold = null
        request_path        = "/"
        port                = null
        host                = null
        logging             = null
      }
      log_config = {
        enable = true
        sample_rate = 1.0
      }

      groups = [
        {
          # Each node pool instance group should be added to the backend.
          group = google_compute_backend_bucket.storage_bucket_backend.id
          balancing_mode               = null
          capacity_scaler              = null
          description                  = null
          max_connections              = null
          max_connections_per_instance = null
          max_connections_per_endpoint = null
          max_rate                     = null
          max_rate_per_instance        = null
          max_rate_per_endpoint        = null
          max_utilization              = null
        },
      ]

      iap_config = {
        enable               = false
        oauth2_client_id     = null
        oauth2_client_secret = null
      }
    }
  }

  cdn = true
  create_address = true
  https_redirect = true
  managed_ssl_certificate_domains = tolist(["cdn.${var.domain}"])
  ssl = true
  use_ssl_certificates = false
}

output "ip" {
  value = module.cdn-lb-http.external_ip
}

Little help please.

craigafinch commented 2 years ago

@chubibest The immediate cause of the error message is that you haven't specified a port for the load balancer health check, so the module can't create a firewall rule to allow the health check. However, once you get past that hurdle, you'll find that it won't accept a google_compute_backend_bucket as a group. I don't think it's possible to use this module to create load balancers with backend buckets. If you look at Google's own module examples, they actually don't use the module to create the load balancer that uses the backend bucket: https://github.com/terraform-google-modules/terraform-google-lb-http/blob/1d3ad9ee0690fbd29ddb853d21b65b9b581ac678/examples/multi-backend-multi-mig-bucket-https-lb/main.tf#L338

I think supporting a static backend bucket would be a great feature to add to this module-perhaps as a submodule.

chubibest commented 2 years ago

Thank you, @craigafinch

tguvdamm commented 2 years ago

An example of just a LoadBalancer with a static backend bucket would indeed be greatly appreciated.

craigafinch commented 2 years ago

@chubibest @tguvdamm I posted an example of using a Cloud Storage bucket as a backend hosting for static files behind an HTTP/S load balancer.

tguvdamm commented 2 years ago

Thanks!

chubibest commented 2 years ago

Bookmarking that!

github-actions[bot] commented 2 years ago

This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 7 days

red8888 commented 1 year ago

This is kinda weird right? I came here because I found no example on this page: https://registry.terraform.io/modules/GoogleCloudPlatform/lb-http/google/latest

Its like the simplest thing to do. Maybe thats why the module doesn't support it? Like its so simple that using a module would be overkill?

Just curious if this was deliberate because that reasoning kind of makes sense to me.