@@ -28,15 +28,23 @@ var (
2828 _ terraformResourceData = (* schema .ResourceDiff )(nil )
2929)
3030
31+ func ExtractRawConfigString (d terraformResourceData , field string ) (string , diag.Diagnostics ) {
32+ rawConfig , diags := d .GetRawConfigAt (cty .GetAttrPath (field ))
33+ if diags == nil && rawConfig .IsKnown () && ! rawConfig .IsNull () {
34+ if rawConfig .AsString () != "" {
35+ return rawConfig .AsString (), nil
36+ }
37+ }
38+ return "" , diags
39+ }
40+
3141// ExtractZone will try to guess the zone from the following:
3242// - zone field of the resource data
3343// - default zone from config
3444func ExtractZone (d terraformResourceData , m any ) (scw.Zone , error ) {
35- rawConfig , err := d .GetRawConfigAt (cty .GetAttrPath ("zone" ))
36- if err == nil && rawConfig .IsKnown () && ! rawConfig .IsNull () {
37- if rawConfig .AsString () != "" {
38- return scw .ParseZone (rawConfig .AsString ())
39- }
45+ rawConfigZone , diags := ExtractRawConfigString (d , "zone" )
46+ if diags == nil && rawConfigZone != "" {
47+ return scw .ParseZone (rawConfigZone )
4048 }
4149
4250 rawZone , exist := d .GetOk ("zone" )
@@ -56,11 +64,9 @@ func ExtractZone(d terraformResourceData, m any) (scw.Zone, error) {
5664// - region field of the resource data
5765// - default region from config
5866func ExtractRegion (d terraformResourceData , m any ) (scw.Region , error ) {
59- rawConfig , err := d .GetRawConfigAt (cty .GetAttrPath ("region" ))
60- if err == nil && rawConfig .IsKnown () && ! rawConfig .IsNull () {
61- if rawConfig .AsString () != "" {
62- return scw .ParseRegion (rawConfig .AsString ())
63- }
67+ rawConfigZone , diags := ExtractRawConfigString (d , "region" )
68+ if diags == nil && rawConfigZone != "" {
69+ return scw .ParseRegion (rawConfigZone )
6470 }
6571
6672 rawRegion , exist := d .GetOk ("region" )
@@ -81,11 +87,9 @@ func ExtractRegion(d terraformResourceData, m any) (scw.Region, error) {
8187// - default region given in argument
8288// - default region from config
8389func ExtractRegionWithDefault (d terraformResourceData , m any , defaultRegion scw.Region ) (scw.Region , error ) {
84- rawConfig , err := d .GetRawConfigAt (cty .GetAttrPath ("region" ))
85- if err == nil && rawConfig .IsKnown () && ! rawConfig .IsNull () {
86- if rawConfig .AsString () != "" {
87- return scw .ParseRegion (rawConfig .AsString ())
88- }
90+ rawConfigZone , diags := ExtractRawConfigString (d , "region" )
91+ if diags == nil && rawConfigZone != "" {
92+ return scw .ParseRegion (rawConfigZone )
8993 }
9094
9195 rawRegion , exist := d .GetOk ("region" )
0 commit comments