-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Add workload identity pool managed identity. #14048
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
Merged
zli82016
merged 1 commit into
GoogleCloudPlatform:main
from
stevenyang72:mwlid-managed-identities
May 22, 2025
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
115 changes: 115 additions & 0 deletions
115
mmv1/products/iambeta/WorkloadIdentityPoolManagedIdentity.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,115 @@ | ||
| # Copyright 2025 Google Inc. | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| --- | ||
| name: 'WorkloadIdentityPoolManagedIdentity' | ||
| description: | | ||
| Represents a managed identity for a workload identity pool namespace. | ||
| references: | ||
| guides: | ||
| 'Configure managed workload identity authentication for Compute Engine': 'https://cloud.google.com/iam/docs/create-managed-workload-identities' | ||
| 'Configure managed workload identity authentication for GKE': 'https://cloud.google.com/iam/docs/create-managed-workload-identities-gke' | ||
| api: 'https://cloud.google.com/iam/docs/reference/rest/v1/projects.locations.workloadIdentityPools.namespaces.managedIdentities' | ||
| min_version: beta | ||
| base_url: 'projects/{{project}}/locations/global/workloadIdentityPools/{{workload_identity_pool_id}}/namespaces/{{workload_identity_pool_namespace_id}}/managedIdentities' | ||
| self_link: 'projects/{{project}}/locations/global/workloadIdentityPools/{{workload_identity_pool_id}}/namespaces/{{workload_identity_pool_namespace_id}}/managedIdentities/{{workload_identity_pool_managed_identity_id}}' | ||
| create_url: 'projects/{{project}}/locations/global/workloadIdentityPools/{{workload_identity_pool_id}}/namespaces/{{workload_identity_pool_namespace_id}}/managedIdentities?workloadIdentityPoolManagedIdentityId={{workload_identity_pool_managed_identity_id}}' | ||
| update_verb: 'PATCH' | ||
| update_mask: true | ||
| import_format: | ||
| - 'projects/{{project}}/locations/global/workloadIdentityPools/{{workload_identity_pool_id}}/namespaces/{{workload_identity_pool_namespace_id}}/managedIdentities/{{workload_identity_pool_managed_identity_id}}' | ||
| autogen_async: true | ||
| custom_code: | ||
| constants: 'templates/terraform/constants/iam_workload_identity_pool_managed_identity.go.tmpl' | ||
| decoder: 'templates/terraform/decoders/treat_deleted_state_as_gone.go.tmpl' | ||
| test_check_destroy: 'templates/terraform/custom_check_destroy/iam_workload_identity_pool_managed_identity.go.tmpl' | ||
| examples: | ||
| - name: 'iam_workload_identity_pool_managed_identity_basic' | ||
| primary_resource_id: 'example' | ||
| vars: | ||
| workload_identity_pool_id: 'example-pool' | ||
| workload_identity_pool_namespace_id: 'example-namespace' | ||
| workload_identity_pool_managed_identity_id: 'example-managed-identity' | ||
| - name: 'iam_workload_identity_pool_managed_identity_full' | ||
| primary_resource_id: 'example' | ||
| vars: | ||
| workload_identity_pool_id: 'example-pool' | ||
| workload_identity_pool_namespace_id: 'example-namespace' | ||
| workload_identity_pool_managed_identity_id: 'example-managed-identity' | ||
| parameters: | ||
| - name: 'workload_identity_pool_id' | ||
| type: String | ||
| required: true | ||
| immutable: true | ||
| url_param_only: true | ||
| description: | | ||
| The ID to use for the pool, which becomes the final component of the resource name. This | ||
| value should be 4-32 characters, and may contain the characters [a-z0-9-]. The prefix | ||
| `gcp-` is reserved for use by Google, and may not be specified. | ||
| - name: 'workload_identity_pool_namespace_id' | ||
| type: String | ||
| required: true | ||
| immutable: true | ||
| url_param_only: true | ||
| description: | | ||
| The ID to use for the namespace. This value must: | ||
| * contain at most 63 characters | ||
| * contain only lowercase alphanumeric characters or `-` | ||
| * start with an alphanumeric character | ||
| * end with an alphanumeric character | ||
|
|
||
|
|
||
| The prefix `gcp-` will be reserved for future uses. | ||
| - name: 'workload_identity_pool_managed_identity_id' | ||
| type: String | ||
| required: true | ||
| immutable: true | ||
| url_param_only: true | ||
| description: | | ||
| The ID to use for the managed identity. This value must: | ||
| * contain at most 63 characters | ||
| * contain only lowercase alphanumeric characters or `-` | ||
| * start with an alphanumeric character | ||
| * end with an alphanumeric character | ||
|
|
||
|
|
||
| The prefix `gcp-` will be reserved for future uses. | ||
| properties: | ||
| - name: 'name' | ||
| type: String | ||
| description: | | ||
| The resource name of the managed identity as | ||
| `projects/{project_number}/locations/global/workloadIdentityPools/{workload_identity_pool_id}/namespaces/{workload_identity_pool_namespace_id}/managedIdentities/{workload_identity_pool_managed_identity_id}`. | ||
| output: true | ||
| - name: 'description' | ||
| type: String | ||
| description: | | ||
| A description of the managed identity. Cannot exceed 256 characters. | ||
| - name: 'state' | ||
| type: Enum | ||
| description: | | ||
| The current state of the managed identity. | ||
| * `ACTIVE`: The managed identity is active. | ||
| * `DELETED`: The managed identity is soft-deleted. Soft-deleted managed identities are | ||
| permanently deleted after approximately 30 days. You can restore a soft-deleted managed | ||
| identity using UndeleteWorkloadIdentityPoolManagedIdentity. You cannot reuse the ID of a | ||
| soft-deleted managed identity until it is permanently deleted. | ||
| output: true | ||
| enum_values: | ||
| - 'ACTIVE' | ||
| - 'DELETED' | ||
| - name: 'disabled' | ||
| type: Boolean | ||
| description: | | ||
| Whether the managed identity is disabled. If disabled, credentials may no longer be issued for | ||
| the identity, however existing credentials will still be accepted until they expire. | ||
44 changes: 44 additions & 0 deletions
44
mmv1/templates/terraform/constants/iam_workload_identity_pool_managed_identity.go.tmpl
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| const workloadIdentityPoolManagedIdentityIdRegexp = `^[0-9a-z-]+$` | ||
|
|
||
| func ValidateWorkloadIdentityPoolManagedIdentityId(v interface{}, k string) (ws []string, errors []error) { | ||
| value := v.(string) | ||
|
|
||
| if !regexp.MustCompile(workloadIdentityPoolManagedIdentityIdRegexp).MatchString(value) { | ||
| errors = append(errors, fmt.Errorf( | ||
| "%q must contain only lowercase letters (a-z), numbers (0-9), or dashes (-)", k)) | ||
| } | ||
|
|
||
| if len(value) < 2 { | ||
| errors = append(errors, fmt.Errorf( | ||
| "%q cannot be less than 2 characters", k)) | ||
| return | ||
| } | ||
|
|
||
| if len(value) > 63 { | ||
| errors = append(errors, fmt.Errorf( | ||
| "%q cannot be greater than 63 characters", k)) | ||
| } | ||
|
|
||
| isLowerAlphaNumeric := func(r byte) bool { | ||
| return (r >= '0' && r <= '9') || (r >= 'a' && r <= 'z') | ||
| } | ||
|
|
||
| firstChar := value[0] | ||
| if !isLowerAlphaNumeric(firstChar) { | ||
| errors = append(errors, fmt.Errorf( | ||
| "%q must start with an alphanumeric character", k)) | ||
| } | ||
|
|
||
| lastChar := value[len(value) - 1] | ||
| if !isLowerAlphaNumeric(lastChar) { | ||
| errors = append(errors, fmt.Errorf( | ||
| "%q must end with an alphanumeric character", k)) | ||
| } | ||
|
|
||
| if strings.HasPrefix(value, "gcp-") { | ||
| errors = append(errors, fmt.Errorf( | ||
| "%q (%q) can not start with \"gcp-\"", k, value)) | ||
| } | ||
|
|
||
| return | ||
| } |
22 changes: 22 additions & 0 deletions
22
...plates/terraform/custom_check_destroy/iam_workload_identity_pool_managed_identity.go.tmpl
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| config := acctest.GoogleProviderConfig(t) | ||
|
|
||
| url, err := tpgresource.ReplaceVarsForTest(config, rs, "{{"{{"}}IAMBetaBasePath{{"}}"}}projects/{{"{{"}}project{{"}}"}}/locations/global/workloadIdentityPools/{{"{{"}}workload_identity_pool_id{{"}}"}}/namespaces/{{"{{"}}workload_identity_pool_namespace_id{{"}}"}}/managedIdentities/{{"{{"}}workload_identity_pool_managed_identity_id{{"}}"}}") | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| res, err := transport_tpg.SendRequest(transport_tpg.SendRequestOptions{ | ||
| Config: config, | ||
| Method: "GET", | ||
| RawURL: url, | ||
| UserAgent: config.UserAgent, | ||
| }) | ||
| if err != nil { | ||
| return nil | ||
| } | ||
|
|
||
| if v := res["state"]; v == "DELETED" { | ||
| return nil | ||
| } | ||
|
|
||
| return fmt.Errorf("IAMBetaWorkloadIdentityPoolManagedIdentity still exists at %s", url) |
21 changes: 21 additions & 0 deletions
21
mmv1/templates/terraform/examples/iam_workload_identity_pool_managed_identity_basic.tf.tmpl
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| resource "google_iam_workload_identity_pool" "pool" { | ||
| provider = google-beta | ||
|
|
||
| workload_identity_pool_id = "{{index $.Vars "workload_identity_pool_id"}}" | ||
| mode = "TRUST_DOMAIN" | ||
| } | ||
|
|
||
| resource "google_iam_workload_identity_pool_namespace" "ns" { | ||
| provider = google-beta | ||
|
|
||
| workload_identity_pool_id = google_iam_workload_identity_pool.pool.workload_identity_pool_id | ||
| workload_identity_pool_namespace_id = "{{index $.Vars "workload_identity_pool_namespace_id"}}" | ||
| } | ||
|
|
||
| resource "google_iam_workload_identity_pool_managed_identity" "{{$.PrimaryResourceId}}" { | ||
| provider = google-beta | ||
|
|
||
| workload_identity_pool_id = google_iam_workload_identity_pool.pool.workload_identity_pool_id | ||
| workload_identity_pool_namespace_id = google_iam_workload_identity_pool_namespace.ns.workload_identity_pool_namespace_id | ||
| workload_identity_pool_managed_identity_id = "{{index $.Vars "workload_identity_pool_managed_identity_id"}}" | ||
| } |
23 changes: 23 additions & 0 deletions
23
mmv1/templates/terraform/examples/iam_workload_identity_pool_managed_identity_full.tf.tmpl
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| resource "google_iam_workload_identity_pool" "pool" { | ||
| provider = google-beta | ||
|
|
||
| workload_identity_pool_id = "{{index $.Vars "workload_identity_pool_id"}}" | ||
| mode = "TRUST_DOMAIN" | ||
| } | ||
|
|
||
| resource "google_iam_workload_identity_pool_namespace" "ns" { | ||
| provider = google-beta | ||
|
|
||
| workload_identity_pool_id = google_iam_workload_identity_pool.pool.workload_identity_pool_id | ||
| workload_identity_pool_namespace_id = "{{index $.Vars "workload_identity_pool_namespace_id"}}" | ||
| } | ||
|
|
||
| resource "google_iam_workload_identity_pool_managed_identity" "{{$.PrimaryResourceId}}" { | ||
| provider = google-beta | ||
|
|
||
| workload_identity_pool_id = google_iam_workload_identity_pool.pool.workload_identity_pool_id | ||
| workload_identity_pool_namespace_id = google_iam_workload_identity_pool_namespace.ns.workload_identity_pool_namespace_id | ||
| workload_identity_pool_managed_identity_id = "{{index $.Vars "workload_identity_pool_managed_identity_id"}}" | ||
| description = "Example Managed Identity in a Workload Identity Pool Namespace" | ||
| disabled = true | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.