From af99ad7c0538ce5312f92f9f2efb8cbda4bde45f Mon Sep 17 00:00:00 2001 From: Chris Stephens Date: Thu, 6 Jun 2019 09:22:16 -0700 Subject: [PATCH] Retrieve project after detecting changes (#1887) Merged PR #1887. --- build/terraform | 2 +- build/terraform-beta | 2 +- .../resources/resource_compute_instance_template.go | 12 ++++++++---- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/build/terraform b/build/terraform index ebbef3f037e9..510cfc78ab07 160000 --- a/build/terraform +++ b/build/terraform @@ -1 +1 @@ -Subproject commit ebbef3f037e944fe54b6d4549814178653125a9f +Subproject commit 510cfc78ab0764fa608280523bb5e1cfd269bbd6 diff --git a/build/terraform-beta b/build/terraform-beta index 4a0731a85409..f3be91cf6f90 160000 --- a/build/terraform-beta +++ b/build/terraform-beta @@ -1 +1 @@ -Subproject commit 4a0731a85409433894a9390df50c10fffa021944 +Subproject commit f3be91cf6f903805961db9756f81ef1a3afaaeaf diff --git a/third_party/terraform/resources/resource_compute_instance_template.go b/third_party/terraform/resources/resource_compute_instance_template.go index 873e15968b11..215389766af4 100644 --- a/third_party/terraform/resources/resource_compute_instance_template.go +++ b/third_party/terraform/resources/resource_compute_instance_template.go @@ -477,14 +477,18 @@ func resourceComputeInstanceTemplate() *schema.Resource { func resourceComputeInstanceTemplateSourceImageCustomizeDiff(diff *schema.ResourceDiff, meta interface{}) error { config := meta.(*Config) - project, err := getProjectFromDiff(diff, config) - if err != nil { - return err - } + numDisks := diff.Get("disk.#").(int) for i := 0; i < numDisks; i++ { key := fmt.Sprintf("disk.%d.source_image", i) if diff.HasChange(key) { + // project must be retrieved once we know there is a diff to resolve, otherwise it will + // attempt to retrieve project during `plan` before all calculated fields are ready + // see https://github.com/terraform-providers/terraform-provider-google/issues/2878 + project, err := getProjectFromDiff(diff, config) + if err != nil { + return err + } old, new := diff.GetChange(key) if old == "" || new == "" { // no sense in resolving empty strings