Skip to content

Commit dafddd2

Browse files
Promote workload identity federation data sources to ga (#12899) (#21408)
[upstream:49eabe66bfbb062663622d972c5081851faa415e] Signed-off-by: Modular Magician <[email protected]>
1 parent df614c2 commit dafddd2

10 files changed

+684
-0
lines changed

.changelog/12899.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note: enhancement
2+
iambeta: Promoted data sources `google_iam_workload_identity_pool` and `google_iam_workload_identity_pool_provider` to GA
3+
```

google/provider/provider_mmv1_resources.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,8 @@ var handwrittenDatasources = map[string]*schema.Resource{
260260
"google_iam_policy": resourcemanager.DataSourceGoogleIamPolicy(),
261261
"google_iam_role": resourcemanager.DataSourceGoogleIamRole(),
262262
"google_iam_testable_permissions": resourcemanager.DataSourceGoogleIamTestablePermissions(),
263+
"google_iam_workload_identity_pool": iambeta.DataSourceIAMBetaWorkloadIdentityPool(),
264+
"google_iam_workload_identity_pool_provider": iambeta.DataSourceIAMBetaWorkloadIdentityPoolProvider(),
263265
"google_iap_client": iap.DataSourceGoogleIapClient(),
264266
"google_kms_crypto_key": kms.DataSourceGoogleKmsCryptoKey(),
265267
"google_kms_crypto_keys": kms.DataSourceGoogleKmsCryptoKeys(),
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,44 @@
11
// Copyright (c) HashiCorp, Inc.
22
// SPDX-License-Identifier: MPL-2.0
33
package iambeta
4+
5+
import (
6+
"fmt"
7+
8+
"github.com/hashicorp/terraform-provider-google/google/tpgresource"
9+
transport_tpg "github.com/hashicorp/terraform-provider-google/google/transport"
10+
11+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
12+
)
13+
14+
func DataSourceIAMBetaWorkloadIdentityPool() *schema.Resource {
15+
16+
dsSchema := tpgresource.DatasourceSchemaFromResourceSchema(ResourceIAMBetaWorkloadIdentityPool().Schema)
17+
tpgresource.AddRequiredFieldsToSchema(dsSchema, "workload_identity_pool_id")
18+
tpgresource.AddOptionalFieldsToSchema(dsSchema, "project")
19+
20+
return &schema.Resource{
21+
Read: dataSourceIAMBetaWorkloadIdentityPoolRead,
22+
Schema: dsSchema,
23+
}
24+
}
25+
26+
func dataSourceIAMBetaWorkloadIdentityPoolRead(d *schema.ResourceData, meta interface{}) error {
27+
config := meta.(*transport_tpg.Config)
28+
29+
id, err := tpgresource.ReplaceVars(d, config, "projects/{{project}}/locations/global/workloadIdentityPools/{{workload_identity_pool_id}}")
30+
if err != nil {
31+
return fmt.Errorf("Error constructing id: %s", err)
32+
}
33+
d.SetId(id)
34+
err = resourceIAMBetaWorkloadIdentityPoolRead(d, meta)
35+
if err != nil {
36+
return err
37+
}
38+
39+
if d.Id() == "" {
40+
return fmt.Errorf("%s not found", id)
41+
}
42+
43+
return nil
44+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,45 @@
11
// Copyright (c) HashiCorp, Inc.
22
// SPDX-License-Identifier: MPL-2.0
33
package iambeta
4+
5+
import (
6+
"fmt"
7+
8+
"github.com/hashicorp/terraform-provider-google/google/tpgresource"
9+
transport_tpg "github.com/hashicorp/terraform-provider-google/google/transport"
10+
11+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
12+
)
13+
14+
func DataSourceIAMBetaWorkloadIdentityPoolProvider() *schema.Resource {
15+
16+
dsSchema := tpgresource.DatasourceSchemaFromResourceSchema(ResourceIAMBetaWorkloadIdentityPoolProvider().Schema)
17+
tpgresource.AddRequiredFieldsToSchema(dsSchema, "workload_identity_pool_id")
18+
tpgresource.AddRequiredFieldsToSchema(dsSchema, "workload_identity_pool_provider_id")
19+
tpgresource.AddOptionalFieldsToSchema(dsSchema, "project")
20+
21+
return &schema.Resource{
22+
Read: dataSourceIAMBetaWorkloadIdentityPoolProviderRead,
23+
Schema: dsSchema,
24+
}
25+
}
26+
27+
func dataSourceIAMBetaWorkloadIdentityPoolProviderRead(d *schema.ResourceData, meta interface{}) error {
28+
config := meta.(*transport_tpg.Config)
29+
30+
id, err := tpgresource.ReplaceVars(d, config, "projects/{{project}}/locations/global/workloadIdentityPools/{{workload_identity_pool_id}}/providers/{{workload_identity_pool_provider_id}}")
31+
if err != nil {
32+
return fmt.Errorf("Error constructing id: %s", err)
33+
}
34+
d.SetId(id)
35+
err = resourceIAMBetaWorkloadIdentityPoolProviderRead(d, meta)
36+
if err != nil {
37+
return err
38+
}
39+
40+
if d.Id() == "" {
41+
return fmt.Errorf("%s not found", id)
42+
}
43+
44+
return nil
45+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,61 @@
11
// Copyright (c) HashiCorp, Inc.
22
// SPDX-License-Identifier: MPL-2.0
33
package iambeta_test
4+
5+
import (
6+
"github.com/hashicorp/terraform-provider-google/google/acctest"
7+
"testing"
8+
9+
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
10+
)
11+
12+
func TestAccDataSourceIAMBetaWorkloadIdentityPoolProvider_basic(t *testing.T) {
13+
t.Parallel()
14+
15+
context := map[string]interface{}{
16+
"random_suffix": acctest.RandString(t, 10),
17+
}
18+
19+
acctest.VcrTest(t, resource.TestCase{
20+
PreCheck: func() { acctest.AccTestPreCheck(t) },
21+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
22+
CheckDestroy: testAccCheckIAMBetaWorkloadIdentityPoolProviderDestroyProducer(t),
23+
Steps: []resource.TestStep{
24+
{
25+
Config: testAccDataSourceIAMBetaWorkloadIdentityPoolProviderBasic(context),
26+
Check: resource.ComposeTestCheckFunc(
27+
acctest.CheckDataSourceStateMatchesResourceState("data.google_iam_workload_identity_pool_provider.foo", "google_iam_workload_identity_pool_provider.bar"),
28+
),
29+
},
30+
},
31+
})
32+
}
33+
34+
func testAccDataSourceIAMBetaWorkloadIdentityPoolProviderBasic(context map[string]interface{}) string {
35+
return acctest.Nprintf(`
36+
resource "google_iam_workload_identity_pool" "pool" {
37+
workload_identity_pool_id = "pool-%{random_suffix}"
38+
}
39+
40+
resource "google_iam_workload_identity_pool_provider" "bar" {
41+
workload_identity_pool_id = google_iam_workload_identity_pool.pool.workload_identity_pool_id
42+
workload_identity_pool_provider_id = "bar-provider-%{random_suffix}"
43+
display_name = "Name of provider"
44+
description = "OIDC identity pool provider for automated test"
45+
disabled = true
46+
attribute_condition = "\"e968c2ef-047c-498d-8d79-16ca1b61e77e\" in assertion.groups"
47+
attribute_mapping = {
48+
"google.subject" = "assertion.sub"
49+
}
50+
oidc {
51+
allowed_audiences = ["https://example.com/gcp-oidc-federation"]
52+
issuer_uri = "https://sts.windows.net/azure-tenant-id"
53+
}
54+
}
55+
56+
data "google_iam_workload_identity_pool_provider" "foo" {
57+
workload_identity_pool_id = google_iam_workload_identity_pool.pool.workload_identity_pool_id
58+
workload_identity_pool_provider_id = google_iam_workload_identity_pool_provider.bar.workload_identity_pool_provider_id
59+
}
60+
`, context)
61+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,47 @@
11
// Copyright (c) HashiCorp, Inc.
22
// SPDX-License-Identifier: MPL-2.0
33
package iambeta_test
4+
5+
import (
6+
"github.com/hashicorp/terraform-provider-google/google/acctest"
7+
"testing"
8+
9+
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
10+
)
11+
12+
func TestAccDataSourceIAMBetaWorkloadIdentityPool_basic(t *testing.T) {
13+
t.Parallel()
14+
15+
context := map[string]interface{}{
16+
"random_suffix": acctest.RandString(t, 10),
17+
}
18+
19+
acctest.VcrTest(t, resource.TestCase{
20+
PreCheck: func() { acctest.AccTestPreCheck(t) },
21+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
22+
CheckDestroy: testAccCheckIAMBetaWorkloadIdentityPoolDestroyProducer(t),
23+
Steps: []resource.TestStep{
24+
{
25+
Config: testAccDataSourceIAMBetaWorkloadIdentityPoolBasic(context),
26+
Check: resource.ComposeTestCheckFunc(
27+
acctest.CheckDataSourceStateMatchesResourceState("data.google_iam_workload_identity_pool.foo", "google_iam_workload_identity_pool.bar"),
28+
),
29+
},
30+
},
31+
})
32+
}
33+
34+
func testAccDataSourceIAMBetaWorkloadIdentityPoolBasic(context map[string]interface{}) string {
35+
return acctest.Nprintf(`
36+
resource "google_iam_workload_identity_pool" "bar" {
37+
workload_identity_pool_id = "bar-pool-%{random_suffix}"
38+
display_name = "Name of pool"
39+
description = "Identity pool for automated test"
40+
disabled = true
41+
}
42+
43+
data "google_iam_workload_identity_pool" "foo" {
44+
workload_identity_pool_id = google_iam_workload_identity_pool.bar.workload_identity_pool_id
45+
}
46+
`, context)
47+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,36 @@
11
// Copyright (c) HashiCorp, Inc.
22
// SPDX-License-Identifier: MPL-2.0
33
package iambeta_test
4+
5+
import (
6+
"strings"
7+
"testing"
8+
9+
"github.com/hashicorp/terraform-provider-google/google/services/iambeta"
10+
"github.com/hashicorp/terraform-provider-google/google/verify"
11+
)
12+
13+
func TestValidateIAMBetaWorkloadIdentityPoolId(t *testing.T) {
14+
x := []verify.StringValidationTestCase{
15+
// No errors
16+
{TestName: "basic", Value: "foobar"},
17+
{TestName: "with numbers", Value: "foobar123"},
18+
{TestName: "short", Value: "foos"},
19+
{TestName: "long", Value: "12345678901234567890123456789012"},
20+
{TestName: "has a hyphen", Value: "foo-bar"},
21+
22+
// With errors
23+
{TestName: "empty", Value: "", ExpectError: true},
24+
{TestName: "starts with a gcp-", Value: "gcp-foobar", ExpectError: true},
25+
{TestName: "with uppercase", Value: "fooBar", ExpectError: true},
26+
{TestName: "has an slash", Value: "foo/bar", ExpectError: true},
27+
{TestName: "has an backslash", Value: "foo\bar", ExpectError: true},
28+
{TestName: "too short", Value: "foo", ExpectError: true},
29+
{TestName: "too long", Value: strings.Repeat("f", 33), ExpectError: true},
30+
}
31+
32+
es := verify.TestStringValidationCases(x, iambeta.ValidateWorkloadIdentityPoolId)
33+
if len(es) > 0 {
34+
t.Errorf("Failed to validate WorkloadIdentityPool names: %v", es)
35+
}
36+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,36 @@
11
// Copyright (c) HashiCorp, Inc.
22
// SPDX-License-Identifier: MPL-2.0
33
package iambeta_test
4+
5+
import (
6+
"strings"
7+
"testing"
8+
9+
"github.com/hashicorp/terraform-provider-google/google/services/iambeta"
10+
"github.com/hashicorp/terraform-provider-google/google/verify"
11+
)
12+
13+
func TestValidateIAMBetaWorkloadIdentityPoolProviderId(t *testing.T) {
14+
x := []verify.StringValidationTestCase{
15+
// No errors
16+
{TestName: "basic", Value: "foobar"},
17+
{TestName: "with numbers", Value: "foobar123"},
18+
{TestName: "short", Value: "foos"},
19+
{TestName: "long", Value: "12345678901234567890123456789012"},
20+
{TestName: "has a hyphen", Value: "foo-bar"},
21+
22+
// With errors
23+
{TestName: "empty", Value: "", ExpectError: true},
24+
{TestName: "starts with a gcp-", Value: "gcp-foobar", ExpectError: true},
25+
{TestName: "with uppercase", Value: "fooBar", ExpectError: true},
26+
{TestName: "has an slash", Value: "foo/bar", ExpectError: true},
27+
{TestName: "has an backslash", Value: "foo\bar", ExpectError: true},
28+
{TestName: "too short", Value: "foo", ExpectError: true},
29+
{TestName: "too long", Value: strings.Repeat("f", 33), ExpectError: true},
30+
}
31+
32+
es := verify.TestStringValidationCases(x, iambeta.ValidateWorkloadIdentityPoolProviderId)
33+
if len(es) > 0 {
34+
t.Errorf("Failed to validate WorkloadIdentityPoolProvider names: %v", es)
35+
}
36+
}

0 commit comments

Comments
 (0)