Skip to content

Commit 7c84475

Browse files
adding data source for identity pool provider (#4181)
Co-authored-by: Scott Suarez <ScottSuarez@google.com>
1 parent 816763a commit 7c84475

File tree

5 files changed

+137
-1
lines changed

5 files changed

+137
-1
lines changed

third_party/terraform/data_sources/data_source_iam_beta_workload_identity_pool.go.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88

99
func dataSourceIAMBetaWorkloadIdentityPool() *schema.Resource {
1010

11-
dsSchema := (resourceIAMBetaWorkloadIdentityPool().Schema)
11+
dsSchema := datasourceSchemaFromResourceSchema(resourceIAMBetaWorkloadIdentityPool().Schema)
1212
addRequiredFieldsToSchema(dsSchema, "workload_identity_pool_id")
1313
addOptionalFieldsToSchema(dsSchema, "project")
1414

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<% autogen_exception -%>
2+
package google
3+
4+
<% unless version == 'ga' -%>
5+
import (
6+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
7+
)
8+
9+
func dataSourceIAMBetaWorkloadIdentityPoolProvider() *schema.Resource {
10+
11+
dsSchema := datasourceSchemaFromResourceSchema(resourceIAMBetaWorkloadIdentityPoolProvider().Schema)
12+
addRequiredFieldsToSchema(dsSchema, "workload_identity_pool_id")
13+
addRequiredFieldsToSchema(dsSchema, "workload_identity_pool_provider_id")
14+
addOptionalFieldsToSchema(dsSchema, "project")
15+
16+
return &schema.Resource{
17+
Read: dataSourceIAMBetaWorkloadIdentityPoolProviderRead,
18+
Schema: dsSchema,
19+
}
20+
}
21+
22+
func dataSourceIAMBetaWorkloadIdentityPoolProviderRead(d *schema.ResourceData, meta interface{}) error {
23+
config := meta.(*Config)
24+
25+
id, err := replaceVars(d, config, "projects/{{project}}/locations/global/workloadIdentityPools/{{workload_identity_pool_id}}/providers/{{workload_identity_pool_provider_id}}")
26+
if err != nil {
27+
return fmt.Errorf("Error constructing id: %s", err)
28+
}
29+
d.SetId(id)
30+
return resourceIAMBetaWorkloadIdentityPoolProviderRead(d, meta)
31+
32+
}
33+
<% end -%>
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<% autogen_exception -%>
2+
package google
3+
4+
<% unless version == 'ga' -%>
5+
import (
6+
"testing"
7+
8+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
9+
)
10+
11+
func TestAccDataSourceIAMBetaWorkloadIdentityPoolProvider_basic(t *testing.T) {
12+
t.Parallel()
13+
14+
context := map[string]interface{}{
15+
"random_suffix": randString(t, 10),
16+
}
17+
18+
vcrTest(t, resource.TestCase{
19+
PreCheck: func() { testAccPreCheck(t) },
20+
Providers: testAccProviders,
21+
CheckDestroy: testAccCheckIAMBetaWorkloadIdentityPoolProviderDestroyProducer(t),
22+
Steps: []resource.TestStep{
23+
{
24+
Config: testAccDataSourceIAMBetaWorkloadIdentityPoolProviderBasic(context),
25+
Check: resource.ComposeTestCheckFunc(
26+
checkDataSourceStateMatchesResourceState("data.google_iam_workload_identity_pool_provider.foo", "google_iam_workload_identity_pool_provider.bar"),
27+
),
28+
},
29+
},
30+
})
31+
}
32+
33+
func testAccDataSourceIAMBetaWorkloadIdentityPoolProviderBasic(context map[string]interface{}) string {
34+
return Nprintf(`
35+
resource "google_iam_workload_identity_pool" "pool" {
36+
workload_identity_pool_id = "pool-%{random_suffix}"
37+
}
38+
39+
resource "google_iam_workload_identity_pool_provider" "bar" {
40+
workload_identity_pool_id = google_iam_workload_identity_pool.pool.workload_identity_pool_id
41+
workload_identity_pool_provider_id = "bar-provider-%{random_suffix}"
42+
display_name = "Name of provider"
43+
description = "OIDC identity pool provider for automated test"
44+
disabled = true
45+
attribute_condition = "\"e968c2ef-047c-498d-8d79-16ca1b61e77e\" in assertion.groups"
46+
attribute_mapping = {
47+
"google.subject" = "assertion.sub"
48+
}
49+
oidc {
50+
allowed_audiences = ["https://example.com/gcp-oidc-federation"]
51+
issuer_uri = "https://sts.windows.net/azure-tenant-id"
52+
}
53+
}
54+
55+
data "google_iam_workload_identity_pool_provider" "foo" {
56+
workload_identity_pool_id = google_iam_workload_identity_pool.pool.workload_identity_pool_id
57+
workload_identity_pool_provider_id = google_iam_workload_identity_pool_provider.bar.workload_identity_pool_provider_id
58+
}
59+
`, context)
60+
}
61+
<% end -%>

third_party/terraform/utils/provider.go.erb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,7 @@ func Provider() *schema.Provider {
225225
"google_iam_testable_permissions": dataSourceGoogleIamTestablePermissions(),
226226
<% unless version == 'ga' -%>
227227
"google_iam_workload_identity_pool": dataSourceIAMBetaWorkloadIdentityPool(),
228+
"google_iam_workload_identity_pool_provider": dataSourceIAMBetaWorkloadIdentityPoolProvider(),
228229
<% end -%>
229230
"google_kms_crypto_key": dataSourceGoogleKmsCryptoKey(),
230231
"google_kms_crypto_key_version": dataSourceGoogleKmsCryptoKeyVersion(),
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
---
2+
subcategory: "Cloud IAM"
3+
layout: "google"
4+
page_title: "Google: google_iam_workload_identity_pool_provider"
5+
sidebar_current: "docs-google-datasource-iam-workload-identity-pool-provider"
6+
description: |-
7+
Get a IAM workload identity pool provider from Google Cloud
8+
---
9+
10+
# google\_iam\_workload_\identity\_pool\_provider
11+
12+
Get a IAM workload identity provider from Google Cloud by its id.
13+
14+
~> **Warning:** This resource is in beta, and should be used with the terraform-provider-google-beta provider.
15+
See [Provider Versions](https://terraform.io/docs/providers/google/guides/provider_versions.html) for more details on beta resources.
16+
17+
## Example Usage
18+
19+
```tf
20+
data "google_iam_workload_identity_pool_provider" "foo" {
21+
workload_identity_pool_id = "foo-pool"
22+
workload_identity_pool_provider_id = "bar-provider"
23+
}
24+
```
25+
26+
## Argument Reference
27+
28+
The following arguments are supported:
29+
30+
* `workload_identity_pool_id` - (Required) The id of the pool which is the
31+
final component of the pool resource name.
32+
* `workload_identity_pool_provider_id` - (Required) The id of the provider which is the
33+
final component of the resource name.
34+
35+
- - -
36+
37+
* `project` - (Optional) The project in which the resource belongs. If it
38+
is not provided, the provider project is used.
39+
40+
## Attributes Reference
41+
See [google_iam_workload_identity_pool_provider](https://www.terraform.io/docs/providers/google/r/iam_workload_identity_pool_provider.html) resource for details of all the available attributes.

0 commit comments

Comments
 (0)