Skip to content

Commit 0502f22

Browse files
modular-magicianrileykarson
authored andcommitted
switch to use MultiEnvDefault (#7644) (#5441)
Signed-off-by: Modular Magician <[email protected]>
1 parent 2670f18 commit 0502f22

File tree

4 files changed

+53
-37
lines changed

4 files changed

+53
-37
lines changed

.changelog/7644.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:bug
2+
provider: fixed an issue where the `USER_PROJECT_OVERRIDE` environment variable was not being read
3+
```

google-beta/config.go

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -523,54 +523,62 @@ var DefaultClientScopes = []string{
523523
"https://www.googleapis.com/auth/userinfo.email",
524524
}
525525

526-
func HandleSDKDefaults(d *schema.ResourceData) {
526+
func HandleSDKDefaults(d *schema.ResourceData) error {
527527
if d.Get("impersonate_service_account") == "" {
528-
d.Set("impersonate_service_account", MultiEnvSearch([]string{
528+
d.Set("impersonate_service_account", MultiEnvDefault([]string{
529529
"GOOGLE_IMPERSONATE_SERVICE_ACCOUNT",
530-
}))
530+
}, nil))
531531
}
532532

533533
if d.Get("project") == "" {
534-
d.Set("project", MultiEnvSearch([]string{
534+
d.Set("project", MultiEnvDefault([]string{
535535
"GOOGLE_PROJECT",
536536
"GOOGLE_CLOUD_PROJECT",
537537
"GCLOUD_PROJECT",
538538
"CLOUDSDK_CORE_PROJECT",
539-
}))
539+
}, nil))
540540
}
541541

542542
if d.Get("billing_project") == "" {
543-
d.Set("billing_project", MultiEnvSearch([]string{
543+
d.Set("billing_project", MultiEnvDefault([]string{
544544
"GOOGLE_BILLING_PROJECT",
545-
}))
545+
}, nil))
546546
}
547547

548548
if d.Get("region") == "" {
549-
d.Set("region", MultiEnvSearch([]string{
549+
d.Set("region", MultiEnvDefault([]string{
550550
"GOOGLE_REGION",
551551
"GCLOUD_REGION",
552552
"CLOUDSDK_COMPUTE_REGION",
553-
}))
553+
}, nil))
554554
}
555555

556556
if d.Get("zone") == "" {
557-
d.Set("zone", MultiEnvSearch([]string{
557+
d.Set("zone", MultiEnvDefault([]string{
558558
"GOOGLE_ZONE",
559559
"GCLOUD_ZONE",
560560
"CLOUDSDK_COMPUTE_ZONE",
561-
}))
561+
}, nil))
562562
}
563563

564-
if d.Get("user_project_override") == "" {
565-
d.Set("user_project_override", MultiEnvSearch([]string{
564+
if _, ok := d.GetOkExists("user_project_override"); !ok {
565+
override := MultiEnvDefault([]string{
566566
"USER_PROJECT_OVERRIDE",
567-
}))
567+
}, nil)
568+
569+
if override != nil {
570+
b, err := strconv.ParseBool(override.(string))
571+
if err != nil {
572+
return err
573+
}
574+
d.Set("user_project_override", b)
575+
}
568576
}
569577

570578
if d.Get("request_reason") == "" {
571-
d.Set("request_reason", MultiEnvSearch([]string{
579+
d.Set("request_reason", MultiEnvDefault([]string{
572580
"CLOUDSDK_CORE_REQUEST_REASON",
573-
}))
581+
}, nil))
574582
}
575583

576584
// Generated Products
@@ -1136,6 +1144,8 @@ func HandleSDKDefaults(d *schema.ResourceData) {
11361144
"GOOGLE_CONTAINERAZURE_CUSTOM_ENDPOINT",
11371145
}, DefaultBasePaths[ContainerAzureBasePathKey]))
11381146
}
1147+
1148+
return nil
11391149
}
11401150

11411151
func (c *Config) LoadAndValidate(ctx context.Context) error {

google-beta/provider.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1474,7 +1474,10 @@ func ResourceMapWithErrors() (map[string]*schema.Resource, error) {
14741474
}
14751475

14761476
func providerConfigure(ctx context.Context, d *schema.ResourceData, p *schema.Provider) (interface{}, diag.Diagnostics) {
1477-
HandleSDKDefaults(d)
1477+
err := HandleSDKDefaults(d)
1478+
if err != nil {
1479+
return nil, diag.FromErr(err)
1480+
}
14781481
HandleDCLCustomEndpointDefaults(d)
14791482

14801483
config := Config{

google-beta/provider_dcl_endpoints.go

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -112,54 +112,54 @@ func ConfigureDCLProvider(provider *schema.Provider) {
112112

113113
func HandleDCLCustomEndpointDefaults(d *schema.ResourceData) {
114114
if d.Get(ApikeysEndpointEntryKey) == "" {
115-
d.Set(ApikeysEndpointEntryKey, MultiEnvSearch([]string{
115+
d.Set(ApikeysEndpointEntryKey, MultiEnvDefault([]string{
116116
"GOOGLE_APIKEYS_CUSTOM_ENDPOINT",
117-
}))
117+
}, ""))
118118
}
119119
if d.Get(AssuredWorkloadsEndpointEntryKey) == "" {
120-
d.Set(AssuredWorkloadsEndpointEntryKey, MultiEnvSearch([]string{
120+
d.Set(AssuredWorkloadsEndpointEntryKey, MultiEnvDefault([]string{
121121
"GOOGLE_ASSURED_WORKLOADS_CUSTOM_ENDPOINT",
122-
}))
122+
}, ""))
123123
}
124124
if d.Get(CloudBuildWorkerPoolEndpointEntryKey) == "" {
125-
d.Set(CloudBuildWorkerPoolEndpointEntryKey, MultiEnvSearch([]string{
125+
d.Set(CloudBuildWorkerPoolEndpointEntryKey, MultiEnvDefault([]string{
126126
"GOOGLE_CLOUD_BUILD_WORKER_POOL_CUSTOM_ENDPOINT",
127-
}))
127+
}, ""))
128128
}
129129
if d.Get(ClouddeployEndpointEntryKey) == "" {
130-
d.Set(ClouddeployEndpointEntryKey, MultiEnvSearch([]string{
130+
d.Set(ClouddeployEndpointEntryKey, MultiEnvDefault([]string{
131131
"GOOGLE_CLOUDDEPLOY_CUSTOM_ENDPOINT",
132-
}))
132+
}, ""))
133133
}
134134
if d.Get(CloudResourceManagerEndpointEntryKey) == "" {
135-
d.Set(CloudResourceManagerEndpointEntryKey, MultiEnvSearch([]string{
135+
d.Set(CloudResourceManagerEndpointEntryKey, MultiEnvDefault([]string{
136136
"GOOGLE_CLOUD_RESOURCE_MANAGER_CUSTOM_ENDPOINT",
137-
}))
137+
}, ""))
138138
}
139139
if d.Get(EventarcEndpointEntryKey) == "" {
140-
d.Set(EventarcEndpointEntryKey, MultiEnvSearch([]string{
140+
d.Set(EventarcEndpointEntryKey, MultiEnvDefault([]string{
141141
"GOOGLE_EVENTARC_CUSTOM_ENDPOINT",
142-
}))
142+
}, ""))
143143
}
144144
if d.Get(FirebaserulesEndpointEntryKey) == "" {
145-
d.Set(FirebaserulesEndpointEntryKey, MultiEnvSearch([]string{
145+
d.Set(FirebaserulesEndpointEntryKey, MultiEnvDefault([]string{
146146
"GOOGLE_FIREBASERULES_CUSTOM_ENDPOINT",
147-
}))
147+
}, ""))
148148
}
149149
if d.Get(GKEHubFeatureEndpointEntryKey) == "" {
150-
d.Set(GKEHubFeatureEndpointEntryKey, MultiEnvSearch([]string{
150+
d.Set(GKEHubFeatureEndpointEntryKey, MultiEnvDefault([]string{
151151
"GOOGLE_GKEHUB_FEATURE_CUSTOM_ENDPOINT",
152-
}))
152+
}, ""))
153153
}
154154
if d.Get(NetworkConnectivityEndpointEntryKey) == "" {
155-
d.Set(NetworkConnectivityEndpointEntryKey, MultiEnvSearch([]string{
155+
d.Set(NetworkConnectivityEndpointEntryKey, MultiEnvDefault([]string{
156156
"GOOGLE_NETWORK_CONNECTIVITY_CUSTOM_ENDPOINT",
157-
}))
157+
}, ""))
158158
}
159159
if d.Get(RecaptchaEnterpriseEndpointEntryKey) == "" {
160-
d.Set(RecaptchaEnterpriseEndpointEntryKey, MultiEnvSearch([]string{
160+
d.Set(RecaptchaEnterpriseEndpointEntryKey, MultiEnvDefault([]string{
161161
"GOOGLE_RECAPTCHA_ENTERPRISE_CUSTOM_ENDPOINT",
162-
}))
162+
}, ""))
163163
}
164164
}
165165

0 commit comments

Comments
 (0)