Skip to content

fix(log): support HTTPS health check logging #497

@gioannidis

Description

@gioannidis

TL;DR

Background: HTTPS health support was added in #170, whereas health logging was added in #283 for HTTP health checks and TCP health checks.

Nevertheless, logging for HTTPS health checks has not been integrated. As a result, the following logging configuration has no effect:

  health_check = {
    type                = "https"
    # ...
    enable_logging      = true
  }

Expected behavior

Logging should be enabled:

$ terraform show | grep log_config -A 2
    log_config {
        enable = true
    }

Observed behavior

Logging is disabled:

$ terraform show | grep log_config -A 2
    log_config {
        enable = false
    }

Terraform Configuration

// Source: https://github.com/terraform-google-modules/terraform-google-vm/blob/main/examples/mig/healthcheck/main.tf
/**
 * Copyright 2018 Google LLC
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/** Providers **/

provider "google" {
  project = var.project_id
  region  = var.region
}

provider "google-beta" {
  project = var.project_id
  region  = var.region
}

resource "random_string" "suffix" {
  length  = 4
  special = "false"
  upper   = "false"
}

/** Network **/

resource "google_compute_network" "main" {
  project                 = var.project_id
  name                    = "cft-vm-test-${random_string.suffix.result}"
  auto_create_subnetworks = "false"
}

resource "google_compute_subnetwork" "main" {
  project       = var.project_id
  region        = var.region
  name          = "cft-vm-test-${random_string.suffix.result}"
  ip_cidr_range = "10.128.0.0/20"
  network       = google_compute_network.main.self_link
}

/** Instance Template **/

module "instance_template" {
  source  = "terraform-google-modules/vm/google//modules/instance_template"
  version = "~> 13.0"

  project_id      = var.project_id
  region          = var.region
  subnetwork      = google_compute_subnetwork.main.name
  service_account = var.service_account
}

/** Instance Group within autoscale and health check **/

module "mig" {
  source  = "terraform-google-modules/vm/google//modules/mig"
  version = "~> 13.0"

  project_id          = var.project_id
  instance_template   = module.instance_template.self_link
  region              = var.region
  autoscaling_enabled = true
  min_replicas        = 2
  autoscaler_name     = "mig-as"
  hostname            = "mig-as"

  autoscaling_cpu = [
    {
      target            = 0.4
      predictive_method = null # use default of NONE
    },
  ]

  health_check_name = "mig-https-hc"
  health_check = {
    type                = "https"
    initial_delay_sec   = 120
    check_interval_sec  = 5
    healthy_threshold   = 2
    timeout_sec         = 5
    unhealthy_threshold = 2
    response            = ""
    proxy_header        = "NONE"
    port                = 443
    request             = ""
    request_path        = "/"
    host                = "localhost"
    enable_logging      = true  // changed from original example
  }
}

Terraform Version

Terraform v1.11.3

Terraform Provider Versions

Providers required by configuration:
.
├── provider[registry.terraform.io/hashicorp/google-beta]
├── provider[registry.terraform.io/hashicorp/google]
├── provider[registry.terraform.io/hashicorp/random]
├── module.instance_template
│   └── provider[registry.terraform.io/hashicorp/google-beta] >= 5.36.0, < 7.0.0
└── module.mig
    ├── provider[registry.terraform.io/hashicorp/google] >= 4.48.0, < 7.0.0
    └── provider[registry.terraform.io/hashicorp/google-beta] >= 4.48.0, < 7.0.0

Additional information

Marked as "bug" because the feature has already been developed, but is not behaving as expected.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions