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

Running the plan with google_compute_instance_template results in an error #2067

Closed
HirokiSakonju opened this issue Sep 18, 2018 · 4 comments · Fixed by #2153
Closed

Running the plan with google_compute_instance_template results in an error #2067

HirokiSakonju opened this issue Sep 18, 2018 · 4 comments · Fixed by #2153
Labels
Milestone

Comments

@HirokiSakonju
Copy link

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or "me too" comments, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment
  • If an issue is assigned to the "modular-magician" user, it is either in the process of being autogenerated, or is planned to be autogenerated soon. If an issue is assigned to a user, that user is claiming responsibility for the issue. If an issue is assigned to "hashibot", a community member has claimed the issue already.

Terraform Version

$ terraform -v
Terraform v0.11.8
+ provider.google v1.18.0

Affected Resource(s)

google_compute_instance_template

Terraform Configuration Files

resource "google_compute_instance_template" "instance-01" {
  name           = "instance-01"
  description    = "instance-01"
  can_ip_forward = true
  machine_type   = "n1-standard-1"

  scheduling {
    automatic_restart   = true
    on_host_maintenance = "MIGRATE"
  }

  // Create a new boot disk from an image
  disk {
    source_image = "instance01"
    auto_delete  = true
    boot         = true
    disk_size_gb = 10
  }

  network_interface {
    subnetwork = "${google_compute_subnetwork.intra-network.name}"

    access_config {
      nat_ip = "${google_compute_address.instance-01.address}"
    }
  }

  service_account {
    scopes = [
      "https://www.googleapis.com/auth/cloud-platform",
    ]
  }
}

Expected Behavior

I did not change it.

Actual Behavior

terraform plan

* google_compute_instance_template.instance-01: 1 error(s) occurred:

* google_compute_instance_template.instance-01: google_compute_instance_template.instance-01: error flattening disks: Error getting relative path for source image: String was not a self link: global/images/instance01

Important Factoids

The image specified by source_image is an image of an image created by another project.
It is not an image existing by default in GCP.

Also, this google_compute_instance_template is a resource you have already created.

References

This correction seems to have caused this problem.

@marrau
Copy link

marrau commented Sep 18, 2018

This also applies to my configurations with a custom image. I tried to get a self_link using data.google_compute_image (which actually resolves it correctly), but i´m still getting the error as mentioned.

@caarlos0
Copy link

also happens with:

resource "google_compute_instance_template" "foo_1" {
  machine_type   = "n1-standard-2"
  region         = "${var.gcp_region}"
  tags           = ["${var.gcp_network_private_tag}", "fooo"]
  can_ip_forward = false
  disk {
    source_image = "ubuntu-os-cloud/ubuntu-1404-lts"
    disk_size_gb = "60"
    auto_delete  = true
    boot         = true
  }
  disk {
    auto_delete  = true
    boot         = false
    disk_size_gb = "100"
    disk_type    = "pd-ssd"
  }
  metadata {
    block-project-ssh-keys = false
  }
  network_interface {
    subnetwork = "${google_compute_subnetwork.subnet_private.name}"
  }
  lifecycle {
    create_before_destroy = true
  }
}

@qwo
Copy link

qwo commented Sep 20, 2018

I ran into this issue and found a resolution. Two prong approach

  1. referencing the source_image using a source link using https://www.terraform.io/docs/providers/google/d/datasource_compute_image.html

  2. running a terraform apply -refresh=false ...

These two combinations allowed me to resolve my initial error of flattening disks and allowed my tf.state to resolve.

I think I got into this erroneous state by being allowed to create my instance templates using string references to images but requiring refresh of state subsequently to have a self_link

Fix: disallow source_image to take a string?

@paddycarver paddycarver added this to the 1.19.0 milestone Sep 30, 2018
paddycarver added a commit that referenced this issue Oct 2, 2018
Fix Dana's comments, one of which exposed a bug: we weren't actually
fixing the diff. Because resolveImage can return multiple formats, and
only returns a self_link if a self_link is passed in, it was diffing
more often than not against a self_link supplied in the config. We just
had a bug in our CustomizeDiff function that concealed this.

I added the resolvedImageSelfLink helper function to turn the output
from resolveImage into a self_link, which fixes the problem. It also has
the knock-on effect of fixing #2067 at the same time, which is nice. I
decided to add another function instead of just modifying resolveImage
to always return a self_link because I don't want to deal with the
backwards compatibility problems of changing how we're storing a bunch
of things in state this close to 1.19.0. And honestly, we should
probably just be storing the self_link always, _anyways_.
@ghost
Copy link

ghost commented Nov 16, 2018

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 Nov 16, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants