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

'google_compute_instance' adding 'google_compute_disk' forces new resource #33

Closed
hashibot opened this issue Jun 13, 2017 · 2 comments · Fixed by #636
Closed

'google_compute_instance' adding 'google_compute_disk' forces new resource #33

hashibot opened this issue Jun 13, 2017 · 2 comments · Fixed by #636
Assignees

Comments

@hashibot
Copy link

This issue was originally opened by @advanderveer as hashicorp/terraform#6678. It was migrated here as part of the provider split. The original body of the issue is below.


Hey, i've encountered unexpected behaviour while updating a google_compute_instance resource by adding a new disk {}.

Terraform Version

Terraform v0.6.16

Affected Resource(s)

  • google_compute_instance
  • google_compute_disk

Terraform Configuration Files

Consider starting out with the following configuration:

variable "gce_ssh_user" {}
variable "gce_ssh_pub_key_file" {}
variable "gce_service_account" {}
variable "gce_project_id" {}
variable "gce_image" {}
variable "gce_region" {
  default = "europe-west1"
}

variable "gce_network" {}
variable "gce_subnetwork" {}

provider "google" {
  credentials = "${file(var.gce_service_account)}"
  project     = "${var.gce_project_id}"
  region      = "${var.gce_region}"
}

resource "google_compute_disk" "default" {
  name  = "test-disk"
  type  = "pd-ssd"
  zone = "${var.gce_region}-b"
  size = 10
}

resource "google_compute_instance" "remove-me" {
  name       = "disk-test"
  machine_type         = "n1-standard-1"
  can_ip_forward       = false
  zone = "${var.gce_region}-b"

  disk {
    image = "ubuntu-1604-xenial-v20160429"
  }

  network_interface {
    subnetwork = "${var.gce_subnetwork}"
    access_config {
      // Ephemeral IP
    }
  }

  service_account {
    scopes = ["compute-rw"] 
  }

  metadata {
    sshKeys = "${var.gce_ssh_user}:${file(var.gce_ssh_pub_key_file)}"
  }
}

When using the gce interface I would now be able to add the disk 'test-disk' to the instance 'remove-me' without recreating it (or even rebooting). I would expect terraform to behave the same when changing the resource configuration to the following:

variable "gce_ssh_user" {}
variable "gce_ssh_pub_key_file" {}
variable "gce_service_account" {}
variable "gce_project_id" {}
variable "gce_image" {}
variable "gce_region" {
  default = "europe-west1"
}

variable "gce_network" {}
variable "gce_subnetwork" {}

provider "google" {
  credentials = "${file(var.gce_service_account)}"
  project     = "${var.gce_project_id}"
  region      = "${var.gce_region}"
}

resource "google_compute_disk" "default" {
  name  = "test-disk"
  type  = "pd-ssd"
  zone = "${var.gce_region}-b"
  size = 10
}

resource "google_compute_instance" "remove-me" {
  name       = "disk-test"
  machine_type         = "n1-standard-1"
  can_ip_forward       = false
  zone = "${var.gce_region}-b"

  disk {
    image = "ubuntu-1604-xenial-v20160429"
  }

  #DISK ADDED HERE (using .name attribute instead of self_link yields the same result)
  disk {
    disk = "${google_compute_disk.default.self_link}"
  }

  network_interface {
    subnetwork = "${var.gce_subnetwork}"
    access_config {
      // Ephemeral IP
    }
  }

  service_account {
    scopes = ["compute-rw"] //this grands our filesystemd to modify itself
  }

  metadata {
    sshKeys = "${var.gce_ssh_user}:${file(var.gce_ssh_pub_key_file)}"
  }
}

Debug Output

https://gist.github.com/advanderveer/fc9e8ef73f1f0b0b8578fedf9140307e

Panic Output

No panic is produced

Expected Behavior

I would expect the the 'google_compute_instance' not to be recreated

Actual Behavior

It get destroyed, i.e terraform plan shows multiple "forces new resource":

-/+ google_compute_instance.remove-me
    can_ip_forward:                                      "false" => "false"
    disk.#:                                              "1" => "2" **(forces new resource)**
    disk.0.auto_delete:                                  "true" => "true"
    disk.0.image:                                        "ubuntu-1604-xenial-v20160429" => "ubuntu-1604-xenial-v20160429"
    disk.1.auto_delete:                                  "" => "true" **(forces new resource)**
    disk.1.disk:                                         "" => "https://www.googleapis.com/compute/v1/projects/microfactory-test/zones/europe-west1-b/disks/test-disk" (forces new resource)
    machine_type:                                        "n1-standard-1" => "n1-standard-1"
    metadata.#:                                          "1" => "1"
    metadata.sshKeys:                                    "<my public ssh key>"
    metadata_fingerprint:                                "Mq9VPCUvh-E=" => "<computed>"
    name:                                                "disk-test" => "disk-test"
    network_interface.#:                                 "1" => "1"
    network_interface.0.access_config.#:                 "1" => "1"
    network_interface.0.access_config.0.assigned_nat_ip: "146.148.15.98" => "<computed>"
    network_interface.0.address:                         "10.0.0.3" => "<computed>"
    network_interface.0.name:                            "nic0" => "<computed>"
    network_interface.0.subnetwork:                      "microfactory-subnetwork" => "microfactory-subnetwork"
    self_link:                                           "https://www.googleapis.com/compute/v1/projects/microfactory-test/zones/europe-west1-b/instances/disk-test" => "<computed>"
    service_account.#:                                   "1" => "1"
    service_account.0.email:                             "[email protected]" => "<computed>"
    service_account.0.scopes.#:                          "1" => "1"
    service_account.0.scopes.299962681:                  "https://www.googleapis.com/auth/compute" => "https://www.googleapis.com/auth/compute"
    tags_fingerprint:                                    "42WmSpB8rSM=" => "<computed>"
    zone:                                                "europe-west1-b" => "europe-west1-b"

Steps to Reproduce

Please list the steps required to reproduce the issue, for example:

  1. terraform plan
  2. terraform apply

Important Factoids

Not that i'm aware of

References

I couldn't find any maybe hashicorp/terraform#5241 is related

@danawillow
Copy link
Contributor

Update here- the changes to add boot/scratch disk have been submitted, and disk has been deprecated. The next release will include #329, which adds a state migration so people can upgrade Terraform without changing their configurations. After that, there are a few more steps as detailed in #122.

@ghost
Copy link

ghost commented Mar 30, 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 Mar 30, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants