Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error creating InstanceGroupManager: googleapi: Error 400: Invalid value for field 'resource.versions[0].instanceTemplate #5252

Closed
judika03 opened this issue Dec 23, 2019 · 3 comments

Comments

@judika03
Copy link

Community Note

Error creating InstanceGroupManager: googleapi: Error 400: Invalid value for field 'resource.versions[0].instanceTemplate':
Unexpected resource collection 'instances'., invalid

Terraform Version

Terraform v0.12.0

provider.google v3.2.0
provider.google-beta v3.2.0
provider.template v2.1.2

Affected Resource(s)

  • google_compute_instance_template
  • google_compute_instance_from_template
  • google_compute_instance_group_manager

Terraform Configuration Files

resource "google_compute_instance_template" "redis-1" {
  project              = "${var.project}"
  name                 = "redis-7000-7002-${var.cluster_name}-${local.runid}-0"
  description          = "redis instance template"
  
  instance_description = "Redis Server"
  machine_type         = "${var.instance_type}"
  can_ip_forward       = false
  tags                 = ["redis"]
  labels = {
    template = "tf-redis"
    cluster_name = "${var.cluster_name}"
    node_type = "static"
  }
  metadata = {
    startup-script = "${data.template_file.startup1.rendered}"
  }
  disk {
    source_image = "debian-cloud/debian-9"
    disk_size_gb = "${var.disk_size_gb}"
    type         = "pd-standard"
  }
  
    network_interface {
    network = "default"
   
  }
  service_account {
    email  = "${var.service_account}@${var.project}.iam.gserviceaccount.com"
    scopes = ["cloud-platform"]

  }
  scheduling {
    automatic_restart   = true
    on_host_maintenance = "MIGRATE"
  }
  lifecycle {
    create_before_destroy = true
  }
}

resource "google_compute_instance_from_template" "tpl" {
  name = "instance-from-template"
    project              = "${var.project}"
   zone = "asia-southeast1-a"

  source_instance_template = google_compute_instance_template.redis-1.self_link

  // Override fields from instance template
  can_ip_forward = false
  labels = {
    my_key = "my_value"
  }
}
resource "google_compute_instance_group_manager" "redis1" {
  provider           = "google-beta"
  project            = "${var.project}"
  name               = "redis1-${var.cluster_name}"
  base_instance_name = "redis1-${var.cluster_name}"
  zone               = "${var.zone_a}"
  target_size        = 1
  version {
    name              = "v1"
    instance_template = "${google_compute_instance_from_template.tpl.self_link}"
  }
 

}

Debug Output

Error creating InstanceGroupManager: googleapi: Error 400: Invalid value for field 'resource.versions[0].instanceTemplate':
Unexpected resource collection 'instances'., invalid
--->

Expected Behavior

Actual Behavior

Steps to Reproduce

  1. terraform apply
@emilymye
Copy link
Contributor

It looks like your config sets instance_template to the instance-from-template self-link, not the actual redis-1 template resource self_link. I'm guessing this is just a typo since you named your instance (from-template) tpl.

i.e.

instance_template = "${google_compute_instance_from_template.tpl.self_link}"

should be
instance_template = "${google_compute_instance_template.redis-1.self_link}"

Both instance-from-template and IGMs depend on an instance template, not template <-- instance from template <-- IGM.

Please feel free to re-open if you have more questions!

@judika03
Copy link
Author

judika03 commented Dec 24, 2019

I'm already to testing google_compute_instance_from_template to adding rrdatas google_dns_record_set already done, but I want use google_compute_instance_from_template to create instance group. I have purpose to create template instance is google_compute_instance_group_manager, I want to create many instance to one group from template instance, Is it possible to google_compute_instance_from_template to google_compute_instance_group_manager. For example

resource "google_compute_instance_from_template" "tpl" {
  name = "instance-from-template"
    project              = "${var.project}"
   zone = "asia-southeast1-a"

  source_instance_template = google_compute_instance_template.redis-1.self_link

  // Override fields from instance template
  can_ip_forward = false
  labels = {
    my_key = "my_value"
  }
}
resource "google_compute_instance_group_manager" "redis1" {
  provider           = "google-beta"
  project            = "${var.project}"
  name               = "redis1-${var.cluster_name}"
  base_instance_name = "redis1-${var.cluster_name}"
  zone               = "${var.zone_a}"
  target_size        = 1
  version {
    name              = "v1"
    instance_template = "${google_compute_instance_from_template.tpl.self_link}"
  }
 

}

@ghost
Copy link

ghost commented Jan 23, 2020

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. If you feel I made an error 🤖 🙉 , please reach out to my human friends 👉 [email protected]. Thanks!

@ghost ghost locked and limited conversation to collaborators Jan 23, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants