Skip to content

Commit

Permalink
Don't fail plan if project,region,zone defaults cannot be retrieved
Browse files Browse the repository at this point in the history
The DefaultProviderProject, DefaultProviderRegion and
DefaultProviderZone funcs set respectively the project, region and zone
in a diff if one is provided, unless they fetch the defaults from config.
However, at times, these value may not be available during a plan, as
they are dynamically computed at apply time.
We should avoid throwing an error if this is the case, but rather set
an empty value in the diff.

Resolves hashicorp#16133
  • Loading branch information
Simon Aquino committed Oct 5, 2023
1 parent 2f5e816 commit 343d5ff
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions google/tpgresource/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -754,7 +754,7 @@ func DefaultProviderProject(_ context.Context, diff *schema.ResourceDiff, meta i
if project := diff.Get("project"); project != nil {
project, err := GetProjectFromDiff(diff, config)
if err != nil {
return fmt.Errorf("Failed to retrieve project, pid: %s, err: %s", project, err)
project = ""
}
err = diff.SetNew("project", project)
if err != nil {
Expand All @@ -771,7 +771,7 @@ func DefaultProviderRegion(_ context.Context, diff *schema.ResourceDiff, meta in
if region := diff.Get("region"); region != nil {
region, err := GetRegionFromDiff(diff, config)
if err != nil {
return fmt.Errorf("Failed to retrieve region, pid: %s, err: %s", region, err)
region = ""
}
err = diff.SetNew("region", region)
if err != nil {
Expand All @@ -789,7 +789,7 @@ func DefaultProviderZone(_ context.Context, diff *schema.ResourceDiff, meta inte
if zone := diff.Get("zone"); zone != nil {
zone, err := GetZoneFromDiff(diff, config)
if err != nil {
return fmt.Errorf("Failed to retrieve zone, pid: %s, err: %s", zone, err)
zone = ""
}
err = diff.SetNew("zone", zone)
if err != nil {
Expand Down

0 comments on commit 343d5ff

Please sign in to comment.