title: Terraform keeps deleting and creating attached_disk associations in an endless loop
body: <p>So, I stumbled upon some funky behavior...</p>
  <p>I do <code>terraform plan</code> and it wants to delete 2 disks associations (attached disks) for my VM:</p>
  <pre><code>- attached_disk {
            - device_name = &quot;persistent-disk-1&quot; -&gt; null
            - mode        = &quot;READ_WRITE&quot; -&gt; null
            - source      = &quot;https://www.googleapis.com/compute/v1/projects/truthisstranger/zones/us-central1-a/disks/app-truthisstranger-production-010cc51d847b4862-docker&quot; -&gt; null
          }
        - attached_disk {
            - device_name = &quot;persistent-disk-2&quot; -&gt; null
            - mode        = &quot;READ_WRITE&quot; -&gt; null
            - source      = &quot;https://www.googleapis.com/compute/v1/projects/truthisstranger/zones/us-central1-a/disks/app-truthisstranger-production-010cc51d847b4862-docker-volumes&quot; -&gt; null
          }
  </code></pre>
  <p>I'm like, okay... <code>terraform apply</code> then, my VM no longer has those disks associated... I do <code>terraform plan</code> once more:</p>
  <pre><code>Terraform will perform the following actions:
  
    # google_compute_attached_disk.app_server_docker_disk will be created
    + resource &quot;google_compute_attached_disk&quot; &quot;app_server_docker_disk&quot; {
        + device_name = (known after apply)
        + disk        = &quot;projects/truthisstranger/zones/us-central1-a/disks/app-truthisstranger-production-010cc51d847b4862-docker&quot;
        + id          = (known after apply)
        + instance    = &quot;projects/truthisstranger/zones/us-central1-a/instances/app-truthisstranger-production-010cc51d847b4862&quot;
        + mode        = &quot;READ_WRITE&quot;
        + project     = (known after apply)
        + zone        = (known after apply)
      }
  
    # google_compute_attached_disk.app_server_docker_volume_disk will be created
    + resource &quot;google_compute_attached_disk&quot; &quot;app_server_docker_volume_disk&quot; {
        + device_name = (known after apply)
        + disk        = &quot;projects/truthisstranger/zones/us-central1-a/disks/app-truthisstranger-production-010cc51d847b4862-docker-volumes&quot;
        + id          = (known after apply)
        + instance    = &quot;projects/truthisstranger/zones/us-central1-a/instances/app-truthisstranger-production-010cc51d847b4862&quot;
        + mode        = &quot;READ_WRITE&quot;
        + project     = (known after apply)
        + zone        = (known after apply)
      }
  
  Plan: 2 to add, 0 to change, 0 to destroy.
  </code></pre>
  <p>And I'm like... okay, that makes sense although I didn't move anything, I do <code>terraform apply</code> once more, my disks are connected to the VM again, but then... without changing any code... <code>terraform plan</code>:</p>
  <pre><code>Terraform will perform the following actions:
  
    # google_compute_instance.app_server will be updated in-place
    ~ resource &quot;google_compute_instance&quot; &quot;app_server&quot; {
          id                        = &quot;projects/truthisstranger/zones/us-central1-a/instances/app-truthisstranger-production-010cc51d847b4862&quot;
          name                      = &quot;app-truthisstranger-production-010cc51d847b4862&quot;
          tags                      = [
              &quot;http-server&quot;,
              &quot;https-server&quot;,
          ]
          # (19 unchanged attributes hidden)
  
        - attached_disk {
            - device_name = &quot;persistent-disk-1&quot; -&gt; null
            - mode        = &quot;READ_WRITE&quot; -&gt; null
            - source      = &quot;https://www.googleapis.com/compute/v1/projects/truthisstranger/zones/us-central1-a/disks/app-truthisstranger-production-010cc51d847b4862-docker&quot; -&gt; null
          }
        - attached_disk {
            - device_name = &quot;persistent-disk-2&quot; -&gt; null
            - mode        = &quot;READ_WRITE&quot; -&gt; null
            - source      = &quot;https://www.googleapis.com/compute/v1/projects/truthisstranger/zones/us-central1-a/disks/app-truthisstranger-production-010cc51d847b4862-docker-volumes&quot; -&gt; null
          }
  
  
  
  
          # (4 unchanged blocks hidden)
      }
  
  Plan: 0 to add, 1 to change, 0 to destroy.
  
  </code></pre>
  <p>So it wants to remove the associations again, no code changes.... what the hell is going on?</p>
  <p>P.S.: Here is my terraform code</p>
  <pre><code>resource &quot;random_id&quot; &quot;instance_id&quot; {
      byte_length = 8
  }
  
  
  
  // A single Compute Engine instance
  resource &quot;google_compute_instance&quot; &quot;app_server&quot; {
      name         = &quot;app-${var.gcp_provider_project}-${var.app_server_environment}-${random_id.instance_id.hex}&quot;
      machine_type = var.app_server_machine_type
      zone         = var.gcp_provider_zone
  
      allow_stopping_for_update   = true
  
      boot_disk {
          initialize_params {
              image = var.app_server_image
          }
      }
  
      // Install Docker from official source
      metadata_startup_script = &lt;&lt;SCRIPT
          sudo apt-get update
          sudo apt-get install -y \
              ca-certificates \
              curl \
              gnupg \
              lsb-release
  
          curl -fsSL https://download.docker.com/linux/ubuntu/gpg \
              | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
  
          echo \
              &quot;deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu \
              $(lsb_release -cs) stable&quot; | sudo tee /etc/apt/sources.list.d/docker.list &gt; /dev/null
  
          sudo apt-get update
          sudo apt-get install -y \
              docker-ce \
              docker-ce-cli \
              containerd.io
      SCRIPT
  
      network_interface {
          network = &quot;default&quot;
  
          access_config {
              nat_ip = &quot;${google_compute_address.static_ip.address}&quot;
          }
      }
  
      lifecycle{
          ignore_changes = [
            metadata_startup_script
          ]
      }
  
      tags = [&quot;http-server&quot;,&quot;https-server&quot;]
  }
  
  //Docker daemon disk association
  resource &quot;google_compute_attached_disk&quot; &quot;app_server_docker_disk&quot;{
      disk        = google_compute_disk.docker_disk.id
      instance    = google_compute_instance.app_server.id
  }
  
  //Docker volume disk association
  resource &quot;google_compute_attached_disk&quot; &quot;app_server_docker_volume_disk&quot;{
      disk        = google_compute_disk.docker_volume_disk.id
      instance    = google_compute_instance.app_server.id
  }
  
  //Docker disk
  resource &quot;google_compute_disk&quot; &quot;docker_disk&quot; {
      name = &quot;${google_compute_instance.app_server.name}-docker&quot;
  
      type = var.app_server_docker_disk_type
      size = var.app_server_docker_disk_size
  }
  
  //Docker disk
  resource &quot;google_compute_disk&quot; &quot;docker_volume_disk&quot; {
      name = &quot;${google_compute_instance.app_server.name}-docker-volumes&quot;
  
      type = var.app_server_docker_volume_disk_type
      size = var.app_server_docker_volume_disk_size
  }
  </code></pre>
  <p>Update: This behavior was documented as a bug, but it still doesn't seem right andafter adding the <code>lifecycle</code> <code>ignore_changes</code> <code>attached_disks</code> it seems it will now always display this:</p>
  <pre><code>Note: Objects have changed outside of Terraform
  
  Terraform detected the following changes made outside of Terraform since the last &quot;terraform apply&quot;:
  
    # google_compute_instance.app_server has changed
    ~ resource &quot;google_compute_instance&quot; &quot;app_server&quot; {
          id                        = &quot;projects/truthisstranger/zones/us-central1-a/instances/app-truthisstranger-production-010cc51d847b4862&quot;
          name                      = &quot;app-truthisstranger-production-010cc51d847b4862&quot;
          tags                      = [
              &quot;http-server&quot;,
              &quot;https-server&quot;,
          ]
          # (19 unchanged attributes hidden)
  
        + attached_disk {
            + device_name = &quot;persistent-disk-1&quot;
            + mode        = &quot;READ_WRITE&quot;
            + source      = &quot;https://www.googleapis.com/compute/v1/projects/truthisstranger/zones/us-central1-a/disks/app-truthisstranger-production-010cc51d847b4862-docker&quot;
          }
        + attached_disk {
            + device_name = &quot;persistent-disk-2&quot;
            + mode        = &quot;READ_WRITE&quot;
            + source      = &quot;https://www.googleapis.com/compute/v1/projects/truthisstranger/zones/us-central1-a/disks/app-truthisstranger-production-010cc51d847b4862-docker-volumes&quot;
          }
  
  
  
  
          # (4 unchanged blocks hidden)
      }
  
  
  Unless you have made equivalent changes to your configuration, or ignored the relevant attributes using ignore_changes, the following plan may include   
  actions to undo or respond to these changes.
  </code></pre>
  <p>Here is a link to the github issue: <a href="https://github.com/hashicorp/terraform-provider-google/issues/2098" rel="nofollow noreferrer">https://github.com/hashicorp/terraform-provider-google/issues/2098</a></p>