Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding data source for identity pool provider #2688

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/4181.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:new-datasource
`google_iam_workload_identity_pool_provider`
```
2 changes: 1 addition & 1 deletion google-beta/data_source_iam_beta_workload_identity_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

func dataSourceIAMBetaWorkloadIdentityPool() *schema.Resource {

dsSchema := (resourceIAMBetaWorkloadIdentityPool().Schema)
dsSchema := datasourceSchemaFromResourceSchema(resourceIAMBetaWorkloadIdentityPool().Schema)
addRequiredFieldsToSchema(dsSchema, "workload_identity_pool_id")
addOptionalFieldsToSchema(dsSchema, "project")

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package google

import (
"fmt"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)

func dataSourceIAMBetaWorkloadIdentityPoolProvider() *schema.Resource {

dsSchema := datasourceSchemaFromResourceSchema(resourceIAMBetaWorkloadIdentityPoolProvider().Schema)
addRequiredFieldsToSchema(dsSchema, "workload_identity_pool_id")
addRequiredFieldsToSchema(dsSchema, "workload_identity_pool_provider_id")
addOptionalFieldsToSchema(dsSchema, "project")

return &schema.Resource{
Read: dataSourceIAMBetaWorkloadIdentityPoolProviderRead,
Schema: dsSchema,
}
}

func dataSourceIAMBetaWorkloadIdentityPoolProviderRead(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)

id, err := replaceVars(d, config, "projects/{{project}}/locations/global/workloadIdentityPools/{{workload_identity_pool_id}}/providers/{{workload_identity_pool_provider_id}}")
if err != nil {
return fmt.Errorf("Error constructing id: %s", err)
}
d.SetId(id)
return resourceIAMBetaWorkloadIdentityPoolProviderRead(d, meta)

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package google

import (
"testing"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
)

func TestAccDataSourceIAMBetaWorkloadIdentityPoolProvider_basic(t *testing.T) {
t.Parallel()

context := map[string]interface{}{
"random_suffix": randString(t, 10),
}

vcrTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckIAMBetaWorkloadIdentityPoolProviderDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccDataSourceIAMBetaWorkloadIdentityPoolProviderBasic(context),
Check: resource.ComposeTestCheckFunc(
checkDataSourceStateMatchesResourceState("data.google_iam_workload_identity_pool_provider.foo", "google_iam_workload_identity_pool_provider.bar"),
),
},
},
})
}

func testAccDataSourceIAMBetaWorkloadIdentityPoolProviderBasic(context map[string]interface{}) string {
return Nprintf(`
resource "google_iam_workload_identity_pool" "pool" {
workload_identity_pool_id = "pool-%{random_suffix}"
}

resource "google_iam_workload_identity_pool_provider" "bar" {
workload_identity_pool_id = google_iam_workload_identity_pool.pool.workload_identity_pool_id
workload_identity_pool_provider_id = "bar-provider-%{random_suffix}"
display_name = "Name of provider"
description = "OIDC identity pool provider for automated test"
disabled = true
attribute_condition = "\"e968c2ef-047c-498d-8d79-16ca1b61e77e\" in assertion.groups"
attribute_mapping = {
"google.subject" = "assertion.sub"
}
oidc {
allowed_audiences = ["https://example.com/gcp-oidc-federation"]
issuer_uri = "https://sts.windows.net/azure-tenant-id"
}
}

data "google_iam_workload_identity_pool_provider" "foo" {
workload_identity_pool_id = google_iam_workload_identity_pool.pool.workload_identity_pool_id
workload_identity_pool_provider_id = google_iam_workload_identity_pool_provider.bar.workload_identity_pool_provider_id
}
`, context)
}
1 change: 1 addition & 0 deletions google-beta/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -722,6 +722,7 @@ func Provider() *schema.Provider {
"google_iam_role": dataSourceGoogleIamRole(),
"google_iam_testable_permissions": dataSourceGoogleIamTestablePermissions(),
"google_iam_workload_identity_pool": dataSourceIAMBetaWorkloadIdentityPool(),
"google_iam_workload_identity_pool_provider": dataSourceIAMBetaWorkloadIdentityPoolProvider(),
"google_kms_crypto_key": dataSourceGoogleKmsCryptoKey(),
"google_kms_crypto_key_version": dataSourceGoogleKmsCryptoKeyVersion(),
"google_kms_key_ring": dataSourceGoogleKmsKeyRing(),
Expand Down
41 changes: 41 additions & 0 deletions website/docs/d/iam_workload_identity_pool_provider.markdown
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
---
subcategory: "Cloud IAM"
layout: "google"
page_title: "Google: google_iam_workload_identity_pool_provider"
sidebar_current: "docs-google-datasource-iam-workload-identity-pool-provider"
description: |-
Get a IAM workload identity pool provider from Google Cloud
---

# google\_iam\_workload_\identity\_pool\_provider

Get a IAM workload identity provider from Google Cloud by its id.

~> **Warning:** This resource is in beta, and should be used with the terraform-provider-google-beta provider.
See [Provider Versions](https://terraform.io/docs/providers/google/guides/provider_versions.html) for more details on beta resources.

## Example Usage

```tf
data "google_iam_workload_identity_pool_provider" "foo" {
workload_identity_pool_id = "foo-pool"
workload_identity_pool_provider_id = "bar-provider"
}
```

## Argument Reference

The following arguments are supported:

* `workload_identity_pool_id` - (Required) The id of the pool which is the
final component of the pool resource name.
* `workload_identity_pool_provider_id` - (Required) The id of the provider which is the
final component of the resource name.

- - -

* `project` - (Optional) The project in which the resource belongs. If it
is not provided, the provider project is used.

## Attributes Reference
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.
4 changes: 4 additions & 0 deletions website/google.erb
Original file line number Diff line number Diff line change
Expand Up @@ -796,6 +796,10 @@
<a href="/docs/providers/google/d/iam_workload_identity_pool.html">google_iam_workload_identity_pool</a>
</li>

<li>
<a href="/docs/providers/google/d/iam_workload_identity_pool_provider">google_iam_workload_identity_pool_provider</a>
</li>

</ul>
</li>
<li>
Expand Down