Skip to content

Commit 225cc91

Browse files
add iam workload identity federation (#4071) (#2623)
Signed-off-by: Modular Magician <[email protected]>
1 parent 7c6f446 commit 225cc91

11 files changed

+1049
-2
lines changed

.changelog/4071.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:new-resource
2+
`google_iam_workload_identity_pool`
3+
```

google-beta/config.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ type Config struct {
118118
FirestoreBasePath string
119119
GameServicesBasePath string
120120
HealthcareBasePath string
121+
IAMBetaBasePath string
121122
IapBasePath string
122123
IdentityPlatformBasePath string
123124
KMSBasePath string
@@ -202,6 +203,7 @@ var FirebaseDefaultBasePath = "https://firebase.googleapis.com/v1beta1/"
202203
var FirestoreDefaultBasePath = "https://firestore.googleapis.com/v1/"
203204
var GameServicesDefaultBasePath = "https://gameservices.googleapis.com/v1beta/"
204205
var HealthcareDefaultBasePath = "https://healthcare.googleapis.com/v1beta1/"
206+
var IAMBetaDefaultBasePath = "https://iam.googleapis.com/v1beta/"
205207
var IapDefaultBasePath = "https://iap.googleapis.com/v1/"
206208
var IdentityPlatformDefaultBasePath = "https://identitytoolkit.googleapis.com/v2/"
207209
var KMSDefaultBasePath = "https://cloudkms.googleapis.com/v1/"
@@ -996,6 +998,7 @@ func ConfigureBasePaths(c *Config) {
996998
c.FirestoreBasePath = FirestoreDefaultBasePath
997999
c.GameServicesBasePath = GameServicesDefaultBasePath
9981000
c.HealthcareBasePath = HealthcareDefaultBasePath
1001+
c.IAMBetaBasePath = IAMBetaDefaultBasePath
9991002
c.IapBasePath = IapDefaultBasePath
10001003
c.IdentityPlatformBasePath = IdentityPlatformDefaultBasePath
10011004
c.KMSBasePath = KMSDefaultBasePath

google-beta/iam_beta_operation.go

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
// ----------------------------------------------------------------------------
2+
//
3+
// *** AUTO GENERATED CODE *** AUTO GENERATED CODE ***
4+
//
5+
// ----------------------------------------------------------------------------
6+
//
7+
// This file is automatically generated by Magic Modules and manual
8+
// changes will be clobbered when the file is regenerated.
9+
//
10+
// Please read more about how to change this file in
11+
// .github/CONTRIBUTING.md.
12+
//
13+
// ----------------------------------------------------------------------------
14+
package google
15+
16+
import (
17+
"fmt"
18+
"time"
19+
)
20+
21+
type IAMBetaOperationWaiter struct {
22+
Config *Config
23+
UserAgent string
24+
Project string
25+
CommonOperationWaiter
26+
}
27+
28+
func (w *IAMBetaOperationWaiter) QueryOp() (interface{}, error) {
29+
if w == nil {
30+
return nil, fmt.Errorf("Cannot query operation, it's unset or nil.")
31+
}
32+
// Returns the proper get.
33+
url := fmt.Sprintf("https://iam.googleapis.com/v1beta/%s", w.CommonOperationWaiter.Op.Name)
34+
35+
return sendRequest(w.Config, "GET", w.Project, url, w.UserAgent, nil)
36+
}
37+
38+
func createIAMBetaWaiter(config *Config, op map[string]interface{}, project, activity, userAgent string) (*IAMBetaOperationWaiter, error) {
39+
if val, ok := op["name"]; !ok || val == "" {
40+
// This was a synchronous call - there is no operation to wait for.
41+
return nil, nil
42+
}
43+
w := &IAMBetaOperationWaiter{
44+
Config: config,
45+
UserAgent: userAgent,
46+
Project: project,
47+
}
48+
if err := w.CommonOperationWaiter.SetOp(op); err != nil {
49+
return nil, err
50+
}
51+
return w, nil
52+
}
53+
54+
func iAMBetaOperationWaitTime(config *Config, op map[string]interface{}, project, activity, userAgent string, timeout time.Duration) error {
55+
w, err := createIAMBetaWaiter(config, op, project, activity, userAgent)
56+
if err != nil || w == nil {
57+
// If w is nil, the op was synchronous.
58+
return err
59+
}
60+
return OperationWait(w, activity, timeout, config.PollInterval)
61+
}

google-beta/provider.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,14 @@ func Provider() *schema.Provider {
415415
"GOOGLE_HEALTHCARE_CUSTOM_ENDPOINT",
416416
}, HealthcareDefaultBasePath),
417417
},
418+
"iam_beta_custom_endpoint": {
419+
Type: schema.TypeString,
420+
Optional: true,
421+
ValidateFunc: validateCustomEndpoint,
422+
DefaultFunc: schema.MultiEnvDefaultFunc([]string{
423+
"GOOGLE_IAM_BETA_CUSTOM_ENDPOINT",
424+
}, IAMBetaDefaultBasePath),
425+
},
418426
"iap_custom_endpoint": {
419427
Type: schema.TypeString,
420428
Optional: true,
@@ -749,9 +757,9 @@ func Provider() *schema.Provider {
749757
return provider
750758
}
751759

752-
// Generated resources: 193
760+
// Generated resources: 194
753761
// Generated IAM resources: 81
754-
// Total generated resources: 274
762+
// Total generated resources: 275
755763
func ResourceMap() map[string]*schema.Resource {
756764
resourceMap, _ := ResourceMapWithErrors()
757765
return resourceMap
@@ -933,6 +941,7 @@ func ResourceMapWithErrors() (map[string]*schema.Resource, error) {
933941
"google_healthcare_dicom_store": resourceHealthcareDicomStore(),
934942
"google_healthcare_fhir_store": resourceHealthcareFhirStore(),
935943
"google_healthcare_hl7_v2_store": resourceHealthcareHl7V2Store(),
944+
"google_iam_workload_identity_pool": resourceIAMBetaWorkloadIdentityPool(),
936945
"google_iap_web_iam_binding": ResourceIamBinding(IapWebIamSchema, IapWebIamUpdaterProducer, IapWebIdParseFunc),
937946
"google_iap_web_iam_member": ResourceIamMember(IapWebIamSchema, IapWebIamUpdaterProducer, IapWebIdParseFunc),
938947
"google_iap_web_iam_policy": ResourceIamPolicy(IapWebIamSchema, IapWebIamUpdaterProducer, IapWebIdParseFunc),
@@ -1255,6 +1264,7 @@ func providerConfigure(ctx context.Context, d *schema.ResourceData, p *schema.Pr
12551264
config.FirestoreBasePath = d.Get("firestore_custom_endpoint").(string)
12561265
config.GameServicesBasePath = d.Get("game_services_custom_endpoint").(string)
12571266
config.HealthcareBasePath = d.Get("healthcare_custom_endpoint").(string)
1267+
config.IAMBetaBasePath = d.Get("iam_beta_custom_endpoint").(string)
12581268
config.IapBasePath = d.Get("iap_custom_endpoint").(string)
12591269
config.IdentityPlatformBasePath = d.Get("identity_platform_custom_endpoint").(string)
12601270
config.KMSBasePath = d.Get("kms_custom_endpoint").(string)
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package google
2+
3+
import (
4+
"strings"
5+
"testing"
6+
)
7+
8+
func TestValidateIAMBetaWorkloadIdentityPoolId(t *testing.T) {
9+
x := []StringValidationTestCase{
10+
// No errors
11+
{TestName: "basic", Value: "foobar"},
12+
{TestName: "with numbers", Value: "foobar123"},
13+
{TestName: "short", Value: "foos"},
14+
{TestName: "long", Value: "12345678901234567890123456789012"},
15+
{TestName: "has a hyphen", Value: "foo-bar"},
16+
17+
// With errors
18+
{TestName: "empty", Value: "", ExpectError: true},
19+
{TestName: "starts with a gcp-", Value: "gcp-foobar", ExpectError: true},
20+
{TestName: "with uppercase", Value: "fooBar", ExpectError: true},
21+
{TestName: "has an slash", Value: "foo/bar", ExpectError: true},
22+
{TestName: "has an backslash", Value: "foo\bar", ExpectError: true},
23+
{TestName: "too short", Value: "foo", ExpectError: true},
24+
{TestName: "too long", Value: strings.Repeat("f", 33), ExpectError: true},
25+
}
26+
27+
es := testStringValidationCases(x, validateWorkloadIdentityPoolId)
28+
if len(es) > 0 {
29+
t.Errorf("Failed to validate WorkloadIdentityPool names: %v", es)
30+
}
31+
}

0 commit comments

Comments
 (0)