Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Retrieve project after detecting changes #3798

Merged
merged 1 commit into from
Jun 6, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 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
Expand Down