1

My terraform file looks like this.

resource "google_compute_disk" "sqlserversecondary" {
    name = "sql-server-secondary"
    type = "pd-ssd"
    zone = "us-central1-a"
    size = "512"
}

resource "google_compute_instance" "sqlserver2016rc2" {
    name = "sqlserver2016rc2"
    machine_type = "n1-highmem-8"

    tags = ["database", "sqlserver2016rc2"]
    zone = "us-central1-a"

    disk {
        image = "sqlserver2016"
        size = "120"
    }

    disk {
        image = "sql-server-secondary"
    }

    network_interface {
        network = "default"
        access_config {
            // Ephemeral IP
        }
    }

    service_account {
        scopes = ["userinfo-email", "compute-ro", "storage-ro"]
    }
}

The second disk exists in GCE, but in this particular situation I keep getting the following error.

Error applying plan:

1 error(s) occurred:

* google_compute_instance.sqlserver2016rc2: Error creating instance: googleapi: Error 400: Invalid value for field 'resource.disks[1].initializeParams': ''. Cannot specify initializeParams for non-boot persistent disks., invalid

1 Answer 1

4

For your second disk, you want to use disk = "sql-server-secondary" instead of image as the identifier. Also, it's best to reference the second disk using Terraform's interpolation syntax (e.g. ${...}) to ensure your resources are created and managed in the appropriate order.

resource "google_compute_disk" "sqlserversecondary" {
  name = "sql-server-secondary"
  type = "pd-ssd"
  zone = "us-central1-a"
  size = "512"
}

resource "google_compute_instance" "sqlserver2016rc2" {
  name         = "sqlserver2016rc2"
  machine_type = "n1-highmem-8"

  tags = ["database", "sqlserver2016rc2"]
  zone = "us-central1-a"

  disk {
    image = "ubuntu-1404-trusty-v20160114e"
    size  = "120"
  }

  disk {
    disk = "${google_compute_disk.sqlserversecondary.name}" // s/image/disk
  }

  network_interface {
    network = "default"

    access_config {
      // Ephemeral IP
    }
  }

  service_account {
    scopes = ["userinfo-email", "compute-ro", "storage-ro"]
  }
}

Terraform sets InitializeParams for disks that are from pre-existing images (code) which is causing the error you received. It seems there may be a bug in this scenario, attaching a non-boot disk from an existing image, but I'm still digging into that.

Hope this helps!

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .