Skip to content

Commit 4e9eeb9

Browse files
App Check reCAPTCHA V3 and reCAPTCHA Enterprise providers (#9991) (#6989)
* App check debug token * Use api_name and identity to wire up debugTokenId * App Check * update mask [upstream:5ddf4406a2fdb1f18a3cdf35872a9f7d072c5b7e] Signed-off-by: Modular Magician <[email protected]>
1 parent 03954f7 commit 4e9eeb9

10 files changed

+1257
-2
lines changed

.changelog/9991.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
```release-note:new-resource
2+
`google_firebase_app_check_recaptcha_enterprise_config`
3+
`google_firebase_app_check_recaptcha_v3_config `
4+
```

google-beta/provider/provider_mmv1_resources.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -429,9 +429,9 @@ var handwrittenIAMDatasources = map[string]*schema.Resource{
429429
}
430430

431431
// Resources
432-
// Generated resources: 441
432+
// Generated resources: 443
433433
// Generated IAM resources: 258
434-
// Total generated resources: 699
434+
// Total generated resources: 701
435435
var generatedResources = map[string]*schema.Resource{
436436
"google_folder_access_approval_settings": accessapproval.ResourceAccessApprovalFolderSettings(),
437437
"google_organization_access_approval_settings": accessapproval.ResourceAccessApprovalOrganizationSettings(),
@@ -822,6 +822,8 @@ var generatedResources = map[string]*schema.Resource{
822822
"google_firebase_app_check_app_attest_config": firebaseappcheck.ResourceFirebaseAppCheckAppAttestConfig(),
823823
"google_firebase_app_check_debug_token": firebaseappcheck.ResourceFirebaseAppCheckDebugToken(),
824824
"google_firebase_app_check_play_integrity_config": firebaseappcheck.ResourceFirebaseAppCheckPlayIntegrityConfig(),
825+
"google_firebase_app_check_recaptcha_enterprise_config": firebaseappcheck.ResourceFirebaseAppCheckRecaptchaEnterpriseConfig(),
826+
"google_firebase_app_check_recaptcha_v3_config": firebaseappcheck.ResourceFirebaseAppCheckRecaptchaV3Config(),
825827
"google_firebase_app_check_service_config": firebaseappcheck.ResourceFirebaseAppCheckServiceConfig(),
826828
"google_firebase_database_instance": firebasedatabase.ResourceFirebaseDatabaseInstance(),
827829
"google_firebase_extensions_instance": firebaseextensions.ResourceFirebaseExtensionsInstance(),
Lines changed: 342 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,342 @@
1+
// Copyright (c) HashiCorp, Inc.
2+
// SPDX-License-Identifier: MPL-2.0
3+
4+
// ----------------------------------------------------------------------------
5+
//
6+
// *** AUTO GENERATED CODE *** Type: MMv1 ***
7+
//
8+
// ----------------------------------------------------------------------------
9+
//
10+
// This file is automatically generated by Magic Modules and manual
11+
// changes will be clobbered when the file is regenerated.
12+
//
13+
// Please read more about how to change this file in
14+
// .github/CONTRIBUTING.md.
15+
//
16+
// ----------------------------------------------------------------------------
17+
18+
package firebaseappcheck
19+
20+
import (
21+
"fmt"
22+
"log"
23+
"reflect"
24+
"strings"
25+
"time"
26+
27+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/customdiff"
28+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
29+
30+
"github.com/hashicorp/terraform-provider-google-beta/google-beta/tpgresource"
31+
transport_tpg "github.com/hashicorp/terraform-provider-google-beta/google-beta/transport"
32+
)
33+
34+
func ResourceFirebaseAppCheckRecaptchaEnterpriseConfig() *schema.Resource {
35+
return &schema.Resource{
36+
Create: resourceFirebaseAppCheckRecaptchaEnterpriseConfigCreate,
37+
Read: resourceFirebaseAppCheckRecaptchaEnterpriseConfigRead,
38+
Update: resourceFirebaseAppCheckRecaptchaEnterpriseConfigUpdate,
39+
Delete: resourceFirebaseAppCheckRecaptchaEnterpriseConfigDelete,
40+
41+
Importer: &schema.ResourceImporter{
42+
State: resourceFirebaseAppCheckRecaptchaEnterpriseConfigImport,
43+
},
44+
45+
Timeouts: &schema.ResourceTimeout{
46+
Create: schema.DefaultTimeout(20 * time.Minute),
47+
Update: schema.DefaultTimeout(20 * time.Minute),
48+
Delete: schema.DefaultTimeout(20 * time.Minute),
49+
},
50+
51+
CustomizeDiff: customdiff.All(
52+
tpgresource.DefaultProviderProject,
53+
),
54+
55+
Schema: map[string]*schema.Schema{
56+
"app_id": {
57+
Type: schema.TypeString,
58+
Required: true,
59+
ForceNew: true,
60+
Description: `The ID of an
61+
[Web App](https://firebase.google.com/docs/reference/firebase-management/rest/v1beta1/projects.webApps#WebApp.FIELDS.app_id).`,
62+
},
63+
"site_key": {
64+
Type: schema.TypeString,
65+
Required: true,
66+
Description: `The score-based site key created in reCAPTCHA Enterprise used to invoke reCAPTCHA and generate the reCAPTCHA tokens for your application.
67+
68+
**Important**: This is not the siteSecret (as it is in reCAPTCHA v3), but rather your score-based reCAPTCHA Enterprise site key.`,
69+
},
70+
"token_ttl": {
71+
Type: schema.TypeString,
72+
Computed: true,
73+
Optional: true,
74+
Description: `Specifies the duration for which App Check tokens exchanged from reCAPTCHA Enterprise artifacts will be valid.
75+
If unset, a default value of 1 hour is assumed. Must be between 30 minutes and 7 days, inclusive.
76+
77+
A duration in seconds with up to nine fractional digits, ending with 's'. Example: "3.5s".`,
78+
},
79+
"name": {
80+
Type: schema.TypeString,
81+
Computed: true,
82+
Description: `The relative resource name of the reCAPTCHA Enterprise configuration object`,
83+
},
84+
"project": {
85+
Type: schema.TypeString,
86+
Optional: true,
87+
Computed: true,
88+
ForceNew: true,
89+
},
90+
},
91+
UseJSONNumber: true,
92+
}
93+
}
94+
95+
func resourceFirebaseAppCheckRecaptchaEnterpriseConfigCreate(d *schema.ResourceData, meta interface{}) error {
96+
config := meta.(*transport_tpg.Config)
97+
userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent)
98+
if err != nil {
99+
return err
100+
}
101+
102+
obj := make(map[string]interface{})
103+
tokenTtlProp, err := expandFirebaseAppCheckRecaptchaEnterpriseConfigTokenTtl(d.Get("token_ttl"), d, config)
104+
if err != nil {
105+
return err
106+
} else if v, ok := d.GetOkExists("token_ttl"); !tpgresource.IsEmptyValue(reflect.ValueOf(tokenTtlProp)) && (ok || !reflect.DeepEqual(v, tokenTtlProp)) {
107+
obj["tokenTtl"] = tokenTtlProp
108+
}
109+
siteKeyProp, err := expandFirebaseAppCheckRecaptchaEnterpriseConfigSiteKey(d.Get("site_key"), d, config)
110+
if err != nil {
111+
return err
112+
} else if v, ok := d.GetOkExists("site_key"); !tpgresource.IsEmptyValue(reflect.ValueOf(siteKeyProp)) && (ok || !reflect.DeepEqual(v, siteKeyProp)) {
113+
obj["siteKey"] = siteKeyProp
114+
}
115+
116+
url, err := tpgresource.ReplaceVars(d, config, "{{FirebaseAppCheckBasePath}}projects/{{project}}/apps/{{app_id}}/recaptchaEnterpriseConfig?updateMask=tokenTtl,siteKey")
117+
if err != nil {
118+
return err
119+
}
120+
121+
log.Printf("[DEBUG] Creating new RecaptchaEnterpriseConfig: %#v", obj)
122+
billingProject := ""
123+
124+
project, err := tpgresource.GetProject(d, config)
125+
if err != nil {
126+
return fmt.Errorf("Error fetching project for RecaptchaEnterpriseConfig: %s", err)
127+
}
128+
billingProject = project
129+
130+
// err == nil indicates that the billing_project value was found
131+
if bp, err := tpgresource.GetBillingProject(d, config); err == nil {
132+
billingProject = bp
133+
}
134+
135+
res, err := transport_tpg.SendRequest(transport_tpg.SendRequestOptions{
136+
Config: config,
137+
Method: "PATCH",
138+
Project: billingProject,
139+
RawURL: url,
140+
UserAgent: userAgent,
141+
Body: obj,
142+
Timeout: d.Timeout(schema.TimeoutCreate),
143+
})
144+
if err != nil {
145+
return fmt.Errorf("Error creating RecaptchaEnterpriseConfig: %s", err)
146+
}
147+
if err := d.Set("name", flattenFirebaseAppCheckRecaptchaEnterpriseConfigName(res["name"], d, config)); err != nil {
148+
return fmt.Errorf(`Error setting computed identity field "name": %s`, err)
149+
}
150+
151+
// Store the ID now
152+
id, err := tpgresource.ReplaceVars(d, config, "projects/{{project}}/apps/{{app_id}}/recaptchaEnterpriseConfig")
153+
if err != nil {
154+
return fmt.Errorf("Error constructing id: %s", err)
155+
}
156+
d.SetId(id)
157+
158+
log.Printf("[DEBUG] Finished creating RecaptchaEnterpriseConfig %q: %#v", d.Id(), res)
159+
160+
return resourceFirebaseAppCheckRecaptchaEnterpriseConfigRead(d, meta)
161+
}
162+
163+
func resourceFirebaseAppCheckRecaptchaEnterpriseConfigRead(d *schema.ResourceData, meta interface{}) error {
164+
config := meta.(*transport_tpg.Config)
165+
userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent)
166+
if err != nil {
167+
return err
168+
}
169+
170+
url, err := tpgresource.ReplaceVars(d, config, "{{FirebaseAppCheckBasePath}}projects/{{project}}/apps/{{app_id}}/recaptchaEnterpriseConfig")
171+
if err != nil {
172+
return err
173+
}
174+
175+
billingProject := ""
176+
177+
project, err := tpgresource.GetProject(d, config)
178+
if err != nil {
179+
return fmt.Errorf("Error fetching project for RecaptchaEnterpriseConfig: %s", err)
180+
}
181+
billingProject = project
182+
183+
// err == nil indicates that the billing_project value was found
184+
if bp, err := tpgresource.GetBillingProject(d, config); err == nil {
185+
billingProject = bp
186+
}
187+
188+
res, err := transport_tpg.SendRequest(transport_tpg.SendRequestOptions{
189+
Config: config,
190+
Method: "GET",
191+
Project: billingProject,
192+
RawURL: url,
193+
UserAgent: userAgent,
194+
})
195+
if err != nil {
196+
return transport_tpg.HandleNotFoundError(err, d, fmt.Sprintf("FirebaseAppCheckRecaptchaEnterpriseConfig %q", d.Id()))
197+
}
198+
199+
if err := d.Set("project", project); err != nil {
200+
return fmt.Errorf("Error reading RecaptchaEnterpriseConfig: %s", err)
201+
}
202+
203+
if err := d.Set("name", flattenFirebaseAppCheckRecaptchaEnterpriseConfigName(res["name"], d, config)); err != nil {
204+
return fmt.Errorf("Error reading RecaptchaEnterpriseConfig: %s", err)
205+
}
206+
if err := d.Set("token_ttl", flattenFirebaseAppCheckRecaptchaEnterpriseConfigTokenTtl(res["tokenTtl"], d, config)); err != nil {
207+
return fmt.Errorf("Error reading RecaptchaEnterpriseConfig: %s", err)
208+
}
209+
if err := d.Set("site_key", flattenFirebaseAppCheckRecaptchaEnterpriseConfigSiteKey(res["siteKey"], d, config)); err != nil {
210+
return fmt.Errorf("Error reading RecaptchaEnterpriseConfig: %s", err)
211+
}
212+
213+
return nil
214+
}
215+
216+
func resourceFirebaseAppCheckRecaptchaEnterpriseConfigUpdate(d *schema.ResourceData, meta interface{}) error {
217+
config := meta.(*transport_tpg.Config)
218+
userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent)
219+
if err != nil {
220+
return err
221+
}
222+
223+
billingProject := ""
224+
225+
project, err := tpgresource.GetProject(d, config)
226+
if err != nil {
227+
return fmt.Errorf("Error fetching project for RecaptchaEnterpriseConfig: %s", err)
228+
}
229+
billingProject = project
230+
231+
obj := make(map[string]interface{})
232+
tokenTtlProp, err := expandFirebaseAppCheckRecaptchaEnterpriseConfigTokenTtl(d.Get("token_ttl"), d, config)
233+
if err != nil {
234+
return err
235+
} else if v, ok := d.GetOkExists("token_ttl"); !tpgresource.IsEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, tokenTtlProp)) {
236+
obj["tokenTtl"] = tokenTtlProp
237+
}
238+
siteKeyProp, err := expandFirebaseAppCheckRecaptchaEnterpriseConfigSiteKey(d.Get("site_key"), d, config)
239+
if err != nil {
240+
return err
241+
} else if v, ok := d.GetOkExists("site_key"); !tpgresource.IsEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, siteKeyProp)) {
242+
obj["siteKey"] = siteKeyProp
243+
}
244+
245+
url, err := tpgresource.ReplaceVars(d, config, "{{FirebaseAppCheckBasePath}}projects/{{project}}/apps/{{app_id}}/recaptchaEnterpriseConfig")
246+
if err != nil {
247+
return err
248+
}
249+
250+
log.Printf("[DEBUG] Updating RecaptchaEnterpriseConfig %q: %#v", d.Id(), obj)
251+
updateMask := []string{}
252+
253+
if d.HasChange("token_ttl") {
254+
updateMask = append(updateMask, "tokenTtl")
255+
}
256+
257+
if d.HasChange("site_key") {
258+
updateMask = append(updateMask, "siteKey")
259+
}
260+
// updateMask is a URL parameter but not present in the schema, so ReplaceVars
261+
// won't set it
262+
url, err = transport_tpg.AddQueryParams(url, map[string]string{"updateMask": strings.Join(updateMask, ",")})
263+
if err != nil {
264+
return err
265+
}
266+
267+
// err == nil indicates that the billing_project value was found
268+
if bp, err := tpgresource.GetBillingProject(d, config); err == nil {
269+
billingProject = bp
270+
}
271+
272+
// if updateMask is empty we are not updating anything so skip the post
273+
if len(updateMask) > 0 {
274+
res, err := transport_tpg.SendRequest(transport_tpg.SendRequestOptions{
275+
Config: config,
276+
Method: "PATCH",
277+
Project: billingProject,
278+
RawURL: url,
279+
UserAgent: userAgent,
280+
Body: obj,
281+
Timeout: d.Timeout(schema.TimeoutUpdate),
282+
})
283+
284+
if err != nil {
285+
return fmt.Errorf("Error updating RecaptchaEnterpriseConfig %q: %s", d.Id(), err)
286+
} else {
287+
log.Printf("[DEBUG] Finished updating RecaptchaEnterpriseConfig %q: %#v", d.Id(), res)
288+
}
289+
290+
}
291+
292+
return resourceFirebaseAppCheckRecaptchaEnterpriseConfigRead(d, meta)
293+
}
294+
295+
func resourceFirebaseAppCheckRecaptchaEnterpriseConfigDelete(d *schema.ResourceData, meta interface{}) error {
296+
log.Printf("[WARNING] FirebaseAppCheck RecaptchaEnterpriseConfig resources"+
297+
" cannot be deleted from Google Cloud. The resource %s will be removed from Terraform"+
298+
" state, but will still be present on Google Cloud.", d.Id())
299+
d.SetId("")
300+
301+
return nil
302+
}
303+
304+
func resourceFirebaseAppCheckRecaptchaEnterpriseConfigImport(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) {
305+
config := meta.(*transport_tpg.Config)
306+
if err := tpgresource.ParseImportId([]string{
307+
"^projects/(?P<project>[^/]+)/apps/(?P<app_id>[^/]+)/recaptchaEnterpriseConfig$",
308+
"^(?P<project>[^/]+)/(?P<app_id>[^/]+)$",
309+
"^(?P<app_id>[^/]+)$",
310+
}, d, config); err != nil {
311+
return nil, err
312+
}
313+
314+
// Replace import id for the resource id
315+
id, err := tpgresource.ReplaceVars(d, config, "projects/{{project}}/apps/{{app_id}}/recaptchaEnterpriseConfig")
316+
if err != nil {
317+
return nil, fmt.Errorf("Error constructing id: %s", err)
318+
}
319+
d.SetId(id)
320+
321+
return []*schema.ResourceData{d}, nil
322+
}
323+
324+
func flattenFirebaseAppCheckRecaptchaEnterpriseConfigName(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
325+
return v
326+
}
327+
328+
func flattenFirebaseAppCheckRecaptchaEnterpriseConfigTokenTtl(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
329+
return v
330+
}
331+
332+
func flattenFirebaseAppCheckRecaptchaEnterpriseConfigSiteKey(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
333+
return v
334+
}
335+
336+
func expandFirebaseAppCheckRecaptchaEnterpriseConfigTokenTtl(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
337+
return v, nil
338+
}
339+
340+
func expandFirebaseAppCheckRecaptchaEnterpriseConfigSiteKey(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
341+
return v, nil
342+
}

0 commit comments

Comments
 (0)