skip to Main Content

I’m using Terraform with GCP … I have the groups variable that I have not been able to get to work. Here’s the definitions:

resource "google_compute_instance_group" "vm_group" {
  name      = "vm-group"
  zone      = "us-central1-c"
  project   = "myproject-dev"
  instances = [google_compute_instance.east_vm.id, google_compute_instance.west_vm.id]
  named_port {
    name = "http"
    port = "8080"
  }

  named_port {
    name = "https"
    port = "8443"
  }

  lifecycle {
    create_before_destroy = true
  }
}

data "google_compute_image" "debian_image" {
  family  = "debian-9"
  project = "debian-cloud"
}

resource "google_compute_instance" "west_vm" {
  name         = "west-vm"
  project      = "myproject-dev"
  machine_type = "e2-micro"
  zone         = "us-central1-c"
  boot_disk {
    initialize_params {
      image = data.google_compute_image.debian_image.self_link
    }
  }
   network_interface {
    network = "default"
  }
  }

resource "google_compute_instance" "east_vm" {
  name         = "east-vm"
  project      = "myproject-dev"
  machine_type = "e2-micro"
  zone         = "us-central1-c"
  boot_disk {
    initialize_params {
      image = data.google_compute_image.debian_image.self_link
    }
  }
   network_interface {
    network = "default"
  }
  }

And here are the variables:

http_forward = true
https_redirect = true
create_address = true
project = "myproject-dev"
backends = {
    "yobaby" = {
             description = "my app"
         enable_cdn = false
         security_policy = ""
         custom_request_headers = null
         custom_response_headers = null
         iap_config = {
             enable = false
                 oauth2_client_id     = ""
                 oauth2_client_secret = ""
         }
          log_config = {
             enable = false
         sample_rate = 0
         }
     groups = [{group = "google_compute_instance_group.vm_group.id"}]

}
}

… this is my latest attempt to get a group value that works, but this one won’t work for me either; I still get

Error 400: Invalid value for field ‘resource.backends[0].group’: ‘google_compute_instance_group.vm_group.id’. The URL is malformed., invalid

I’ve tried this with DNS FQDNs and variations on the syntax above; still no go.

Thanks much for any advice whatsoever!

2

Answers


  1. Chosen as BEST ANSWER

    I gave up on Terraform and used gcloud scripts to do what I needed to do, based on this posting.


  2. There are couple clues that can lead in this direction based from the error message reported by Terraform Error 400: Invalid value for field 'resource.backends[0].group': 'google_compute_instance_group.vm_group.id'. The URL is malformed., invalid:

    1. Error code 400 means the request was actually sent to the server, who rejected it as malformed (HTTP error code 400 is for client-side errors); this implies that Terraform itself has no problem with the syntax, i.e., the configuration file is correct and actionable from TF’s PoV

    2. Value of field resource.backends[0].group is reported as being literally ‘google_compute_instance_group.vm_group.id’ which strongly suggests that a variable substitution did not take place.

    The quotes around the code block makes it into a literal value instead of a variable reference. The solution is to change this:

    groups = [{group = "google_compute_instance_group.vm_group.id"}]

    To this:

    groups = [{group = google_compute_instance_group.vm_group.id}]

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search