@@ -37,14 +37,40 @@ func Provider() *schema.Provider {
37
37
Type: schema.TypeString,
38
38
Optional: true,
39
39
ValidateFunc: ValidateCredentials,
40
- ConflictsWith: []string{"access_token"},
40
+ ConflictsWith: []string{"access_token", "external_credentials" },
41
41
},
42
42
43
43
"access_token": {
44
44
Type: schema.TypeString,
45
45
Optional: true,
46
46
ValidateFunc: ValidateEmptyStrings,
47
- ConflictsWith: []string{"credentials"},
47
+ ConflictsWith: []string{"credentials", "external_credentials"},
48
+ },
49
+
50
+ "external_credentials": {
51
+ Type: schema.TypeList,
52
+ MaxItems: 1,
53
+ Optional: true,
54
+ ConflictsWith: []string{"credentials", "access_token"},
55
+ Elem: &schema.Resource{
56
+ Schema: map[string]*schema.Schema{
57
+ "audience": {
58
+ Type: schema.TypeString,
59
+ Required: true,
60
+ ValidateFunc: ValidateEmptyStrings,
61
+ },
62
+ "service_account_email": {
63
+ Type: schema.TypeString,
64
+ Required: true,
65
+ ValidateFunc: ValidateServiceAccountEmail,
66
+ },
67
+ "identity_token": {
68
+ Type: schema.TypeString,
69
+ Required: true,
70
+ ValidateFunc: ValidateJWT,
71
+ },
72
+ },
73
+ },
48
74
},
49
75
50
76
"impersonate_service_account": {
@@ -257,19 +283,27 @@ func ProviderConfigure(ctx context.Context, d *schema.ResourceData, p *schema.Pr
257
283
config.RequestReason = v.(string)
258
284
}
259
285
260
- // Check for primary credentials in config. Note that if neither is set, ADCs
286
+ // Check for primary credentials in config. Note that if none of these values are set, ADCs
261
287
// will be used if available.
262
- if v, ok := d.GetOk("access_token"); ok {
263
- config.AccessToken = v.(string)
264
- }
288
+ if v, ok := d.GetOk("external_credentials"); ok {
289
+ external, err := transport_tpg.ExpandExternalCredentialsConfig(v)
290
+ if err != nil {
291
+ return nil, diag.FromErr(err)
292
+ }
293
+ config.ExternalCredentials = external
294
+ } else {
295
+ if v, ok := d.GetOk("access_token"); ok {
296
+ config.AccessToken = v.(string)
297
+ }
265
298
266
- if v, ok := d.GetOk("credentials"); ok {
267
- config.Credentials = v.(string)
299
+ if v, ok := d.GetOk("credentials"); ok {
300
+ config.Credentials = v.(string)
301
+ }
268
302
}
269
303
270
- // only check environment variables if neither value was set in config- this
304
+ // only check environment variables if none of these values are set in config- this
271
305
// means config beats env var in all cases.
272
- if config.AccessToken == "" && config.Credentials == "" {
306
+ if config.ExternalCredentials == nil && config. AccessToken == "" && config.Credentials == "" {
273
307
config.Credentials = transport_tpg.MultiEnvSearch([]string{
274
308
"GOOGLE_CREDENTIALS",
275
309
"GOOGLE_CLOUD_KEYFILE_JSON",
0 commit comments