Skip to content

Commit

Permalink
Retrieve project after detecting changes
Browse files Browse the repository at this point in the history
Signed-off-by: Modular Magician <[email protected]>
  • Loading branch information
chrisst authored and modular-magician committed Jun 5, 2019
1 parent 354a995 commit 91415b5
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions google/resource_compute_instance_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 retrived 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
Expand Down

0 comments on commit 91415b5

Please sign in to comment.