forked from GoogleCloudPlatform/magic-modules
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add OIDC code flow fields to WorkforcePoolProvider. (GoogleCloudPlatf…
…orm#8212) * Add OIDC code flow fields to WorkforcePoolProvider. * Add ignore_read_extra for client secret plaintext to bypass ImportStateVerify check. * Use server-provided to correct external drift for client secret. * Handle nil return values from d.Get. * Validate that client secret plain_text is non-empty to ensure that clearing plain_text on thumbprint change always triggers a diff.
- Loading branch information
1 parent
dc7f9c6
commit 0b4819d
Showing
7 changed files
with
180 additions
and
8 deletions.
There are no files selected for viewing
This file contains 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
31 changes: 31 additions & 0 deletions
31
...ates/terraform/custom_flatten/iam_workforce_pool_provider_oidc_client_secret_value.go.erb
This file contains 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,31 @@ | ||
<%# The license inside this block applies to this file. | ||
# Copyright 2023 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. | ||
-%> | ||
func flatten<%= prefix -%><%= titlelize_property(property) -%>(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { | ||
if v == nil { | ||
return nil | ||
} | ||
original := v.(map[string]interface{}) | ||
if len(original) == 0 { | ||
return nil | ||
} | ||
transformed := make(map[string]interface{}) | ||
transformed["thumbprint"] = original["thumbprint"] | ||
// Trigger a diff based on the plain_text if there is no change in the thumbprint, | ||
// otherwise leave plain_text empty to always trigger a diff. | ||
if original["thumbprint"].(string) == d.Get("oidc.0.client_secret.0.value.0.thumbprint").(string) { | ||
transformed["plain_text"] = d.Get("oidc.0.client_secret.0.value.0.plain_text") | ||
} | ||
return []interface{}{transformed} | ||
} |
This file contains 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
This file contains 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
17 changes: 17 additions & 0 deletions
17
mmv1/templates/terraform/post_create/iam_workforce_pool_provider.go.erb
This file contains 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,17 @@ | ||
createdClientSecret := d.Get("oidc.0.client_secret.0.value.0.plain_text") | ||
if createdClientSecret != nil && createdClientSecret != "" { | ||
// After the create, reading from the API returns a new thumbprint | ||
// for the client secret value, which clears the plain_text. We set the plain_text since | ||
// this case should not warrant a diff. | ||
if err := resourceIAMWorkforcePoolWorkforcePoolProviderRead(d, meta); err != nil { | ||
return err | ||
} | ||
oidc := d.Get("oidc") | ||
clientSecret := oidc.([]interface{})[0].(map[string]interface{})["client_secret"] | ||
clientSecretValue := clientSecret.([]interface{})[0].(map[string]interface{})["value"] | ||
clientSecretValue.([]interface{})[0].(map[string]interface{})["plain_text"] = createdClientSecret | ||
if err := d.Set("oidc", oidc); err != nil { | ||
return err | ||
} | ||
return nil | ||
} |
19 changes: 19 additions & 0 deletions
19
mmv1/templates/terraform/post_update/iam_workforce_pool_provider.go.erb
This file contains 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,19 @@ | ||
if d.HasChange("oidc") { | ||
updatedClientSecret := d.Get("oidc.0.client_secret.0.value.0.plain_text") | ||
if updatedClientSecret != nil && updatedClientSecret != "" { | ||
// After the update, reading from the API returns a different thumbprint | ||
// for the client secret value, which clears the plain_text. We set the plain_text since | ||
// this case should not warrant a diff. | ||
if err := resourceIAMWorkforcePoolWorkforcePoolProviderRead(d, meta); err != nil { | ||
return err | ||
} | ||
oidc := d.Get("oidc") | ||
clientSecret := oidc.([]interface{})[0].(map[string]interface{})["client_secret"] | ||
clientSecretValue := clientSecret.([]interface{})[0].(map[string]interface{})["value"] | ||
clientSecretValue.([]interface{})[0].(map[string]interface{})["plain_text"] = updatedClientSecret | ||
if err := d.Set("oidc", oidc); err != nil { | ||
return err | ||
} | ||
return nil | ||
} | ||
} |
This file contains 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