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 #2663

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/4134.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:new-datasource
`google_iam_workload_identity_pool`
```
31 changes: 31 additions & 0 deletions google-beta/data_source_iam_beta_workload_identity_pool.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package google

import (
"fmt"

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

func dataSourceIAMBetaWorkloadIdentityPool() *schema.Resource {

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

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

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

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

}
44 changes: 44 additions & 0 deletions google-beta/data_source_iam_beta_workload_identity_pool_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package google

import (
"testing"

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

func TestAccDataSourceIAMBetaWorkloadIdentityPool_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: testAccCheckIAMBetaWorkloadIdentityPoolDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccDataSourceIAMBetaWorkloadIdentityPoolBasic(context),
Check: resource.ComposeTestCheckFunc(
checkDataSourceStateMatchesResourceState("data.google_iam_workload_identity_pool.foo", "google_iam_workload_identity_pool.bar"),
),
},
},
})
}

func testAccDataSourceIAMBetaWorkloadIdentityPoolBasic(context map[string]interface{}) string {
return Nprintf(`
resource "google_iam_workload_identity_pool" "bar" {
workload_identity_pool_id = "bar-pool-%{random_suffix}"
display_name = "Name of pool"
description = "Identity pool for automated test"
disabled = true
}

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

# google\_iam\_workload_\identity\_pool

Get a IAM workload identity pool 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" "foo" {
workload_identity_pool_id = "foo-pool"
}
```

## Argument Reference

The following arguments are supported:

* `workload_identity_pool_id` - (Required) The id of the pool 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](https://www.terraform.io/docs/providers/google/r/iam_workload_identity_pool.html) resource for details of all the available attributes.
10 changes: 10 additions & 0 deletions website/google.erb
Original file line number Diff line number Diff line change
Expand Up @@ -774,6 +774,16 @@
<li>
<a href="#">Cloud IAM</a>
<ul class="nav">
<li>
<a href="#">Data Sources</a>
<ul class="nav nav-auto-expand">

<li>
<a href="/docs/providers/google/d/iam_workload_identity_pool">google_iam_workload_identity_pool</a>
</li>

</ul>
</li>
<li>
<a href="#">Resources</a>
<ul class="nav nav-auto-expand">
Expand Down