@@ -156,7 +156,7 @@ func getOrCreateServiceAccount(config *transport_tpg.Config, project, serviceAcc
156
156
157
157
sa, err := config.NewIamClient(config.UserAgent).Projects.ServiceAccounts.Get(name).Do()
158
158
if err != nil && !transport_tpg.IsGoogleApiErrorWithCode(err, 404) {
159
- return nil , err
159
+ return nil, fmt.Errorf("encountered a non-404 error when looking for bootstrapped service account %s: %w", name, err)
160
160
}
161
161
162
162
if sa == nil {
@@ -171,7 +171,7 @@ func getOrCreateServiceAccount(config *transport_tpg.Config, project, serviceAcc
171
171
}
172
172
sa, err = config.NewIamClient(config.UserAgent).Projects.ServiceAccounts.Create("projects/"+project, r).Do()
173
173
if err != nil {
174
- return nil , err
174
+ return nil, fmt.Errorf("error when creating bootstrapped service account %s: %w", name, err)
175
175
}
176
176
}
177
177
@@ -1231,13 +1231,13 @@ func SetupProjectsAndGetAccessToken(org, billing, pid, service string, config *t
1231
1231
Timeout: 5 * time.Minute,
1232
1232
})
1233
1233
if err != nil {
1234
- return "" , err
1234
+ return "", fmt.Errorf("error creating 'project-1' with project id %s: %w", pid, err)
1235
1235
}
1236
1236
1237
1237
// Wait for the operation to complete
1238
1238
opAsMap, err := tpgresource.ConvertToMap(op)
1239
1239
if err != nil {
1240
- return "" , err
1240
+ return "", fmt.Errorf("error in ConvertToMap while creating 'project-1' with project id %s: %w", pid, err)
1241
1241
}
1242
1242
1243
1243
waitErr := resourcemanager.ResourceManagerOperationWaitTime(config, opAsMap, "creating project", config.UserAgent, 5*time.Minute)
@@ -1250,7 +1250,7 @@ func SetupProjectsAndGetAccessToken(org, billing, pid, service string, config *t
1250
1250
}
1251
1251
_, err = config.NewBillingClient(config.UserAgent).Projects.UpdateBillingInfo(resourcemanager.PrefixedProject(pid), ba).Do()
1252
1252
if err != nil {
1253
- return "" , err
1253
+ return "", fmt.Errorf("error updating billing info for 'project-1' with project id %s: %w", pid, err)
1254
1254
}
1255
1255
1256
1256
p2 := fmt.Sprintf("%s-2", pid)
@@ -1265,7 +1265,7 @@ func SetupProjectsAndGetAccessToken(org, billing, pid, service string, config *t
1265
1265
Timeout: 5 * time.Minute,
1266
1266
})
1267
1267
if err != nil {
1268
- return "" , err
1268
+ return "", fmt.Errorf("error creating 'project-2' with project id %s: %w", p2, err)
1269
1269
}
1270
1270
1271
1271
// Wait for the operation to complete
@@ -1281,7 +1281,7 @@ func SetupProjectsAndGetAccessToken(org, billing, pid, service string, config *t
1281
1281
1282
1282
_, err = config.NewBillingClient(config.UserAgent).Projects.UpdateBillingInfo(resourcemanager.PrefixedProject(p2), ba).Do()
1283
1283
if err != nil {
1284
- return "" , err
1284
+ return "", fmt.Errorf("error updating billing info for 'project-2' with project id %s: %w", p2, err)
1285
1285
}
1286
1286
1287
1287
// Enable the appropriate service in project-2 only
@@ -1293,14 +1293,14 @@ func SetupProjectsAndGetAccessToken(org, billing, pid, service string, config *t
1293
1293
1294
1294
_, err = suService.Services.BatchEnable(fmt.Sprintf("projects/%s", p2), serviceReq).Do()
1295
1295
if err != nil {
1296
- return "" , err
1296
+ return "", fmt.Errorf("error batch enabling services in 'project-2' with project id %s: %w", p2, err)
1297
1297
}
1298
1298
1299
1299
// Enable the test runner to create service accounts and get an access token on behalf of
1300
1300
// the project 1 service account
1301
1301
curEmail, err := transport_tpg.GetCurrentUserEmail(config, config.UserAgent)
1302
1302
if err != nil {
1303
- return "" , err
1303
+ return "", fmt.Errorf("error getting current user email: %w", err)
1304
1304
}
1305
1305
1306
1306
proj1SATokenCreator := &cloudresourcemanager.Binding{
@@ -1322,7 +1322,7 @@ func SetupProjectsAndGetAccessToken(org, billing, pid, service string, config *t
1322
1322
},
1323
1323
}).Do()
1324
1324
if err != nil {
1325
- return "" , err
1325
+ return "", fmt.Errorf("error getting IAM policy for 'project-1' with project id %s: %w", pid, err)
1326
1326
}
1327
1327
1328
1328
p.Bindings = tpgiamresource.MergeBindings(append(p.Bindings, bindings...))
@@ -1332,15 +1332,18 @@ func SetupProjectsAndGetAccessToken(org, billing, pid, service string, config *t
1332
1332
UpdateMask: "bindings,etag,auditConfigs",
1333
1333
}).Do()
1334
1334
if err != nil {
1335
- return "" , err
1335
+ return "", fmt.Errorf("error setting IAM policy for 'project-1' with project id %s: %w", pid, err)
1336
1336
}
1337
1337
1338
1338
// Create a service account for project-1
1339
1339
serviceAccountEmail := serviceAccountPrefix + service
1340
1340
sa1, err := getOrCreateServiceAccount(config, pid, serviceAccountEmail)
1341
1341
if err != nil {
1342
- return "" , err
1342
+ return "", fmt.Errorf("error creating service account %s in 'project-1' with project id %s: %w", serviceAccountEmail, pid, err)
1343
1343
}
1344
+ // Setting IAM policies sometimes fails due to the service account not being created yet
1345
+ // Wait a minute to ensure we can use it.
1346
+ time.Sleep(1 * time.Minute)
1344
1347
1345
1348
// Add permissions to service accounts
1346
1349
@@ -1368,14 +1371,29 @@ func SetupProjectsAndGetAccessToken(org, billing, pid, service string, config *t
1368
1371
bindings = tpgiamresource.MergeBindings(append(bindings, proj2CryptoKeyBinding))
1369
1372
}
1370
1373
1374
+
1375
+ {{ if ne $.TargetVersionName `ga` -}}
1376
+ // For Firebase test only
1377
+ if service == "firebase" {
1378
+ // Additional permissions besides roles/serviceusage.serviceUsageConsumer and roles/firebase.admin are needed
1379
+ // https://firebase.google.com/docs/reference/firebase-management/rest/v1beta1/projects/addFirebase
1380
+ proj2ServiceUsageBinding := &cloudresourcemanager.Binding{
1381
+ Members: []string{fmt.Sprintf("serviceAccount:%s", sa1.Email)},
1382
+ Role: "roles/serviceusage.serviceUsageAdmin",
1383
+ }
1384
+
1385
+ bindings = tpgiamresource.MergeBindings(append(bindings, proj2ServiceUsageBinding))
1386
+ }
1387
+ {{- end }}
1388
+
1371
1389
p, err = rmService.Projects.GetIamPolicy(p2,
1372
1390
&cloudresourcemanager.GetIamPolicyRequest{
1373
1391
Options: &cloudresourcemanager.GetPolicyOptions{
1374
1392
RequestedPolicyVersion: tpgiamresource.IamPolicyVersion,
1375
1393
},
1376
1394
}).Do()
1377
1395
if err != nil {
1378
- return "" , err
1396
+ return "", fmt.Errorf("error getting IAM policy for 'project-2' with project id %s: %w", p2, err)
1379
1397
}
1380
1398
1381
1399
p.Bindings = tpgiamresource.MergeBindings(append(p.Bindings, bindings...))
@@ -1385,7 +1403,7 @@ func SetupProjectsAndGetAccessToken(org, billing, pid, service string, config *t
1385
1403
UpdateMask: "bindings,etag,auditConfigs",
1386
1404
}).Do()
1387
1405
if err != nil {
1388
- return "" , err
1406
+ return "", fmt.Errorf("error setting IAM policy for 'project-2' with project id %s: %w", p2, err)
1389
1407
}
1390
1408
1391
1409
// The token creator IAM API call returns success long before the policy is
@@ -1399,7 +1417,7 @@ func SetupProjectsAndGetAccessToken(org, billing, pid, service string, config *t
1399
1417
}
1400
1418
atResp, err := iamCredsService.Projects.ServiceAccounts.GenerateAccessToken(fmt.Sprintf("projects/-/serviceAccounts/%s", sa1.Email), tokenRequest).Do()
1401
1419
if err != nil {
1402
- return "" , err
1420
+ return "", fmt.Errorf("error generating access token for service account %s: %w", sa1.Email, err)
1403
1421
}
1404
1422
1405
1423
accessToken := atResp.AccessToken
0 commit comments