pulumi / pulumi-gcp

A Google Cloud Platform (GCP) Pulumi resource package, providing multi-language access to GCP
Apache License 2.0
178 stars 52 forks source link

Attached disk prevents Instance from being replaced #73

Open synhershko opened 5 years ago

synhershko commented 5 years ago

The following program launches an instance with an attached disk:

let i = 0;
    let d = new gcp.compute.Disk(runName + "-esdata" + i, {size: dataDiskSize, type: "pd-ssd", zone});
    elasticsearchInstances.push(
        new gcp.compute.Instance(runName + "-elasticsearch-data" + i, {
                machineType: "n1-standard-1",
                zone,
                metadata: {"ssh-keys": sshKey},
                metadataStartupScript: esDataNodeStartupScript,
                bootDisk: {initializeParams: {image: machineImage}},
                attachedDisks: [{source: d}],
                networkInterfaces: [{
                    network: computeNetwork.id,
                    accessConfigs: [{}],
                }],
                scheduling: {automaticRestart: false, preemptible: isPreemptible},
                serviceAccount: {
                    scopes: ["https://www.googleapis.com/auth/cloud-platform", "compute-rw"],
                },
                tags: [clusterName, runName],
            }
        )
    );

Running pulumi up completes fine, but updating some instance parameters (e.g. startup script) requires replacing the machine when running pulumi update. However, the following error is received:

error: Plan apply failed: Error creating instance: googleapi: Error 400: The disk resource 'esdata0-86abfa9' is already being used by 'elasticsearch-data0-5df5543', resourceInUseByAnotherResource

We should be able to replace an instance by detaching the disk from existing instance, and attaching it to the new launched instance.

cowwoc commented 3 years ago

2 years later, any progress on this? Alternatively, is there a workaround?

leezen commented 3 years ago

In this particular case, does deleteBeforeReplace work as a workaround? Right now, what's happening is upon replacement (create new then delete old), the new instance attempts to attach to the disk, which is already in use. By using the deleteBeforeReplace option, the instance should be deleted first, which should allow the disk to be attached to the new replacement.

wpietri commented 5 months ago

It's wild to me that a simple use case like this has not worked for more than 5 years. I'm just trying out Pulumi and it's making me question whether it's the right choice for us.

zbuchheit commented 4 months ago

deleteBeforeReplace was able to resolve this for me, but interestingly enough this behavior didn't seem to happen when using yaml. I only witnessed it while using typescript. I haven't tested in another besides typescript and yaml.