Skip to content

Commit 55f053a

Browse files
Fix minor edit suggestions for IAM OAuth Client resource (#13258) (#21726)
[upstream:5662a5b0eb35f2f9e7ceff3dcbb47a9b90ef0df5] Signed-off-by: Modular Magician <[email protected]>
1 parent 868bfa8 commit 55f053a

File tree

5 files changed

+45
-146
lines changed

5 files changed

+45
-146
lines changed

.changelog/13258.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note: none
2+
Fix minor edit suggestions for IAM OAuth Client resource
3+
```

google/services/iamworkforcepool/resource_iam_oauth_client.go

Lines changed: 5 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import (
2424
"log"
2525
"net/http"
2626
"reflect"
27-
"regexp"
2827
"strings"
2928
"time"
3029

@@ -35,27 +34,6 @@ import (
3534
transport_tpg "github.com/hashicorp/terraform-provider-google/google/transport"
3635
)
3736

38-
const oauthClientIdRegexp = `^[a-z][a-z0-9-]{4,61}[a-z0-9]$`
39-
40-
func ValidateOauthClientId(v interface{}, k string) (ws []string, errors []error) {
41-
value := v.(string)
42-
43-
if strings.HasPrefix(value, "gcp-") {
44-
errors = append(errors, fmt.Errorf(
45-
"%q (%q) can not start with \"gcp-\". "+
46-
"The prefix `gcp-` is reserved for use by Google, and may not be specified.", k, value))
47-
}
48-
49-
if !regexp.MustCompile(oauthClientIdRegexp).MatchString(value) {
50-
errors = append(errors, fmt.Errorf(
51-
"%q (%q) must contain only lowercase letters [a-z], digits [0-9], and hyphens "+
52-
"[-]. The OauthClient ID must be between 6 and 63 characters, begin "+
53-
"with a letter, and cannot have a trailing hyphen.", k, value))
54-
}
55-
56-
return
57-
}
58-
5937
func ResourceIAMWorkforcePoolOauthClient() *schema.Resource {
6038
return &schema.Resource{
6139
Create: resourceIAMWorkforcePoolOauthClientCreate,
@@ -145,20 +123,20 @@ CONFIDENTIAL_CLIENT`,
145123
"description": {
146124
Type: schema.TypeString,
147125
Optional: true,
148-
Description: `Optional. A user-specified description of the OauthClient.
126+
Description: `A user-specified description of the OauthClient.
149127
150128
Cannot exceed 256 characters.`,
151129
},
152130
"disabled": {
153131
Type: schema.TypeBool,
154132
Optional: true,
155-
Description: `Optional. Whether the OauthClient is disabled. You cannot use a disabled OAuth
133+
Description: `Whether the OauthClient is disabled. You cannot use a disabled OAuth
156134
client.`,
157135
},
158136
"display_name": {
159137
Type: schema.TypeString,
160138
Optional: true,
161-
Description: `Optional. A user-specified display name of the OauthClient.
139+
Description: `A user-specified display name of the OauthClient.
162140
163141
Cannot exceed 32 characters.`,
164142
},
@@ -170,7 +148,7 @@ Cannot exceed 32 characters.`,
170148
"expire_time": {
171149
Type: schema.TypeString,
172150
Computed: true,
173-
Description: `Output only. Time after which the OauthClient will be permanently purged and cannot
151+
Description: `Time after which the OauthClient will be permanently purged and cannot
174152
be recovered.`,
175153
},
176154
"name": {
@@ -183,7 +161,7 @@ Format:'projects/{project}/locations/{location}/oauthClients/{oauth_client}'.`,
183161
"state": {
184162
Type: schema.TypeString,
185163
Computed: true,
186-
Description: `Output only. The state of the OauthClient.
164+
Description: `The state of the OauthClient.
187165
Possible values:
188166
STATE_UNSPECIFIED
189167
ACTIVE

google/services/iamworkforcepool/resource_iam_oauth_client_generated_test.go

Lines changed: 2 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -30,44 +30,6 @@ import (
3030
transport_tpg "github.com/hashicorp/terraform-provider-google/google/transport"
3131
)
3232

33-
func TestAccIAMWorkforcePoolOauthClient_iamOauthClientBasicExample(t *testing.T) {
34-
t.Parallel()
35-
36-
context := map[string]interface{}{
37-
"random_suffix": acctest.RandString(t, 10),
38-
}
39-
40-
acctest.VcrTest(t, resource.TestCase{
41-
PreCheck: func() { acctest.AccTestPreCheck(t) },
42-
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
43-
CheckDestroy: testAccCheckIAMWorkforcePoolOauthClientDestroyProducer(t),
44-
Steps: []resource.TestStep{
45-
{
46-
Config: testAccIAMWorkforcePoolOauthClient_iamOauthClientBasicExample(context),
47-
},
48-
{
49-
ResourceName: "google_iam_oauth_client.example",
50-
ImportState: true,
51-
ImportStateVerify: true,
52-
ImportStateVerifyIgnore: []string{"location", "oauth_client_id"},
53-
},
54-
},
55-
})
56-
}
57-
58-
func testAccIAMWorkforcePoolOauthClient_iamOauthClientBasicExample(context map[string]interface{}) string {
59-
return acctest.Nprintf(`
60-
resource "google_iam_oauth_client" "example" {
61-
oauth_client_id = "tf-test-example-client-id%{random_suffix}"
62-
location = "global"
63-
allowed_grant_types = ["AUTHORIZATION_CODE_GRANT"]
64-
allowed_redirect_uris = ["https://www.example.com"]
65-
allowed_scopes = ["https://www.googleapis.com/auth/cloud-platform"]
66-
client_type = "CONFIDENTIAL_CLIENT"
67-
}
68-
`, context)
69-
}
70-
7133
func TestAccIAMWorkforcePoolOauthClient_iamOauthClientFullExample(t *testing.T) {
7234
t.Parallel()
7335

@@ -121,7 +83,7 @@ func testAccCheckIAMWorkforcePoolOauthClientDestroyProducer(t *testing.T) func(s
12183

12284
config := acctest.GoogleProviderConfig(t)
12385

124-
url, err := tpgresource.ReplaceVarsForTest(config, rs, "{{IAMWorkforcePoolBasePath}}projects/{{project}}/locations/global/oauthClients/{{oauth_client_id}}")
86+
url, err := tpgresource.ReplaceVarsForTest(config, rs, "{{IAMWorkforcePoolBasePath}}projects/{{project}}/locations/{{location}}/oauthClients/{{oauth_client_id}}")
12587
if err != nil {
12688
return err
12789
}
@@ -140,7 +102,7 @@ func testAccCheckIAMWorkforcePoolOauthClientDestroyProducer(t *testing.T) func(s
140102
return nil
141103
}
142104

143-
return fmt.Errorf("IAMOAuthCLient still exists at %s", url)
105+
return fmt.Errorf("IAMOAuthClient still exists at %s", url)
144106
}
145107

146108
return nil

google/services/iamworkforcepool/resource_iam_oauth_client_test.go

Lines changed: 30 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@ import (
66
"testing"
77

88
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
9+
"github.com/hashicorp/terraform-plugin-testing/plancheck"
910

1011
"github.com/hashicorp/terraform-provider-google/google/acctest"
1112
)
1213

13-
func TestAccIAMWorkforcePoolOauthClient_basic(t *testing.T) {
14+
func TestAccIAMWorkforcePoolOauthClient_full(t *testing.T) {
1415
t.Parallel()
1516

1617
context := map[string]interface{}{
@@ -23,7 +24,7 @@ func TestAccIAMWorkforcePoolOauthClient_basic(t *testing.T) {
2324
CheckDestroy: testAccCheckIAMWorkforcePoolOauthClientDestroyProducer(t),
2425
Steps: []resource.TestStep{
2526
{
26-
Config: testAccIAMWorkforcePoolOauthClient_basic(context),
27+
Config: testAccIAMWorkforcePoolOauthClient_full(context),
2728
},
2829
{
2930
ResourceName: "google_iam_oauth_client.example",
@@ -32,58 +33,12 @@ func TestAccIAMWorkforcePoolOauthClient_basic(t *testing.T) {
3233
ImportStateVerifyIgnore: []string{"location", "oauth_client_id"},
3334
},
3435
{
35-
Config: testAccIAMWorkforcePoolOauthClient_basic_update(context),
36-
},
37-
{
38-
ResourceName: "google_iam_oauth_client.example",
39-
ImportState: true,
40-
ImportStateVerify: true,
41-
ImportStateVerifyIgnore: []string{"location", "oauth_client_id"},
42-
},
43-
},
44-
})
45-
}
46-
47-
func testAccIAMWorkforcePoolOauthClient_basic(context map[string]interface{}) string {
48-
return acctest.Nprintf(`
49-
resource "google_iam_oauth_client" "example" {
50-
oauth_client_id = "tf-test-example-client-id%{random_suffix}"
51-
location = "global"
52-
allowed_grant_types = ["AUTHORIZATION_CODE_GRANT"]
53-
allowed_redirect_uris = ["https://www.example.com"]
54-
allowed_scopes = ["https://www.googleapis.com/auth/cloud-platform"]
55-
client_type = "CONFIDENTIAL_CLIENT"
56-
}
57-
`, context)
58-
}
59-
60-
func testAccIAMWorkforcePoolOauthClient_basic_update(context map[string]interface{}) string {
61-
return acctest.Nprintf(`
62-
resource "google_iam_oauth_client" "example" {
63-
oauth_client_id = "tf-test-example-client-id%{random_suffix}"
64-
location = "global"
65-
allowed_grant_types = ["AUTHORIZATION_CODE_GRANT"]
66-
allowed_redirect_uris = ["https://www.update.com"]
67-
allowed_scopes = ["https://www.googleapis.com/auth/cloud-platform", "openid"]
68-
client_type = "CONFIDENTIAL_CLIENT"
69-
}
70-
`, context)
71-
}
72-
73-
func TestAccIAMWorkforcePoolOauthClient_full(t *testing.T) {
74-
t.Parallel()
75-
76-
context := map[string]interface{}{
77-
"random_suffix": acctest.RandString(t, 10),
78-
}
79-
80-
acctest.VcrTest(t, resource.TestCase{
81-
PreCheck: func() { acctest.AccTestPreCheck(t) },
82-
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
83-
CheckDestroy: testAccCheckIAMWorkforcePoolOauthClientDestroyProducer(t),
84-
Steps: []resource.TestStep{
85-
{
86-
Config: testAccIAMWorkforcePoolOauthClient_full(context),
36+
Config: testAccIAMWorkforcePoolOauthClient_full_update(context),
37+
ConfigPlanChecks: resource.ConfigPlanChecks{
38+
PreApply: []plancheck.PlanCheck{
39+
plancheck.ExpectResourceAction("google_iam_oauth_client.example", plancheck.ResourceActionUpdate),
40+
},
41+
},
8742
},
8843
{
8944
ResourceName: "google_iam_oauth_client.example",
@@ -92,7 +47,12 @@ func TestAccIAMWorkforcePoolOauthClient_full(t *testing.T) {
9247
ImportStateVerifyIgnore: []string{"location", "oauth_client_id"},
9348
},
9449
{
95-
Config: testAccIAMWorkforcePoolOauthClient_full_update(context),
50+
Config: testAccIAMWorkforcePoolOauthClient_full_cleanOptionalFields(context),
51+
ConfigPlanChecks: resource.ConfigPlanChecks{
52+
PreApply: []plancheck.PlanCheck{
53+
plancheck.ExpectResourceAction("google_iam_oauth_client.example", plancheck.ResourceActionUpdate),
54+
},
55+
},
9656
},
9757
{
9858
ResourceName: "google_iam_oauth_client.example",
@@ -128,7 +88,21 @@ resource "google_iam_oauth_client" "example" {
12888
description = "Updated description"
12989
location = "global"
13090
disabled = true
131-
allowed_grant_types = ["AUTHORIZATION_CODE_GRANT", ]
91+
allowed_grant_types = ["AUTHORIZATION_CODE_GRANT"]
92+
allowed_redirect_uris = ["https://www.update.com"]
93+
allowed_scopes = ["https://www.googleapis.com/auth/cloud-platform", "openid"]
94+
client_type = "CONFIDENTIAL_CLIENT"
95+
}
96+
`, context)
97+
}
98+
99+
func testAccIAMWorkforcePoolOauthClient_full_cleanOptionalFields(context map[string]interface{}) string {
100+
return acctest.Nprintf(`
101+
resource "google_iam_oauth_client" "example" {
102+
oauth_client_id = "tf-test-example-client-id%{random_suffix}"
103+
location = "global"
104+
disabled = true
105+
allowed_grant_types = ["AUTHORIZATION_CODE_GRANT"]
132106
allowed_redirect_uris = ["https://www.update.com"]
133107
allowed_scopes = ["https://www.googleapis.com/auth/cloud-platform", "openid"]
134108
client_type = "CONFIDENTIAL_CLIENT"

website/docs/r/iam_oauth_client.html.markdown

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -32,24 +32,6 @@ To get more information about OauthClient, see:
3232
* How-to Guides
3333
* [Managing OAuth clients](https://cloud.google.com/iam/docs/workforce-manage-oauth-app#manage-clients)
3434

35-
<div class = "oics-button" style="float: right; margin: 0 0 -15px">
36-
<a href="https://console.cloud.google.com/cloudshell/open?cloudshell_git_repo=https%3A%2F%2Fgithub.com%2Fterraform-google-modules%2Fdocs-examples.git&cloudshell_image=gcr.io%2Fcloudshell-images%2Fcloudshell%3Alatest&cloudshell_print=.%2Fmotd&cloudshell_tutorial=.%2Ftutorial.md&cloudshell_working_dir=iam_oauth_client_basic&open_in_editor=main.tf" target="_blank">
37-
<img alt="Open in Cloud Shell" src="//gstatic.com/cloudssh/images/open-btn.svg" style="max-height: 44px; margin: 32px auto; max-width: 100%;">
38-
</a>
39-
</div>
40-
## Example Usage - Iam Oauth Client Basic
41-
42-
43-
```hcl
44-
resource "google_iam_oauth_client" "example" {
45-
oauth_client_id = "example-client-id"
46-
location = "global"
47-
allowed_grant_types = ["AUTHORIZATION_CODE_GRANT"]
48-
allowed_redirect_uris = ["https://www.example.com"]
49-
allowed_scopes = ["https://www.googleapis.com/auth/cloud-platform"]
50-
client_type = "CONFIDENTIAL_CLIENT"
51-
}
52-
```
5335
<div class = "oics-button" style="float: right; margin: 0 0 -15px">
5436
<a href="https://console.cloud.google.com/cloudshell/open?cloudshell_git_repo=https%3A%2F%2Fgithub.com%2Fterraform-google-modules%2Fdocs-examples.git&cloudshell_image=gcr.io%2Fcloudshell-images%2Fcloudshell%3Alatest&cloudshell_print=.%2Fmotd&cloudshell_tutorial=.%2Ftutorial.md&cloudshell_working_dir=iam_oauth_client_full&open_in_editor=main.tf" target="_blank">
5537
<img alt="Open in Cloud Shell" src="//gstatic.com/cloudssh/images/open-btn.svg" style="max-height: 44px; margin: 32px auto; max-width: 100%;">
@@ -117,17 +99,17 @@ The following arguments are supported:
11799

118100
* `disabled` -
119101
(Optional)
120-
Optional. Whether the OauthClient is disabled. You cannot use a disabled OAuth
102+
Whether the OauthClient is disabled. You cannot use a disabled OAuth
121103
client.
122104

123105
* `display_name` -
124106
(Optional)
125-
Optional. A user-specified display name of the OauthClient.
107+
A user-specified display name of the OauthClient.
126108
Cannot exceed 32 characters.
127109

128110
* `description` -
129111
(Optional)
130-
Optional. A user-specified description of the OauthClient.
112+
A user-specified description of the OauthClient.
131113
Cannot exceed 256 characters.
132114

133115
* `client_type` -
@@ -155,7 +137,7 @@ In addition to the arguments listed above, the following computed attributes are
155137
Format:`projects/{project}/locations/{location}/oauthClients/{oauth_client}`.
156138

157139
* `state` -
158-
Output only. The state of the OauthClient.
140+
The state of the OauthClient.
159141
Possible values:
160142
STATE_UNSPECIFIED
161143
ACTIVE
@@ -165,7 +147,7 @@ In addition to the arguments listed above, the following computed attributes are
165147
Output only. The system-generated OauthClient id.
166148

167149
* `expire_time` -
168-
Output only. Time after which the OauthClient will be permanently purged and cannot
150+
Time after which the OauthClient will be permanently purged and cannot
169151
be recovered.
170152

171153

0 commit comments

Comments
 (0)