Skip to content

Commit 051877b

Browse files
modular-magicianChris Stephens
andauthored
Add Firebase WebApp resource (#3340) (#1950)
* Add Firebase WebApp resource Signed-off-by: Matt Morrissette <[email protected]> * Add "config" to Firebase WebApp * Add "google_firebase_web_app" data source * Exclude update from async op * Add datasource and an update test. Add the google_firebase_web_app_config data source Test for updating google_firebase_web_app resource * Get import working and fix build * Adding documentation Docs for both web app datasources Adding resources to the website side bar * exclude beta data source * removing comments Co-authored-by: Chris Stephens <[email protected]> Signed-off-by: Modular Magician <[email protected]> Co-authored-by: Chris Stephens <[email protected]>
1 parent b2fa518 commit 051877b

13 files changed

+855
-4
lines changed

.changelog/3340.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
```release-note:new-resource
2+
firebase: `google_firebase_web_app`
3+
```
4+
```release-note:new-datasource
5+
firebase: `google_firebase_web_app`
6+
```
7+
```release-note:new-datasource
8+
firebase: `google_firebase_web_app_config`
9+
```
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package google
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
7+
)
8+
9+
func dataSourceGoogleFirebaseWebApp() *schema.Resource {
10+
// Generate datasource schema from resource
11+
dsSchema := datasourceSchemaFromResourceSchema(resourceFirebaseWebApp().Schema)
12+
13+
// Set 'Required' schema elements
14+
addRequiredFieldsToSchema(dsSchema, "app_id")
15+
16+
return &schema.Resource{
17+
Read: dataSourceGoogleFirebaseWebAppRead,
18+
Schema: dsSchema,
19+
}
20+
}
21+
22+
func dataSourceGoogleFirebaseWebAppRead(d *schema.ResourceData, meta interface{}) error {
23+
config := meta.(*Config)
24+
appId := d.Get("app_id")
25+
project, err := getProject(d, config)
26+
if err != nil {
27+
return err
28+
}
29+
name := fmt.Sprintf("projects/%s/webApps/%s", project, appId.(string))
30+
d.SetId(name)
31+
d.Set("name", name)
32+
return resourceFirebaseWebAppRead(d, meta)
33+
}
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
package google
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
7+
)
8+
9+
func dataSourceGoogleFirebaseWebappConfig() *schema.Resource {
10+
return &schema.Resource{
11+
Read: dataSourceGoogleFirebaseWebappConfigRead,
12+
13+
Schema: map[string]*schema.Schema{
14+
"web_app_id": {
15+
Type: schema.TypeString,
16+
Required: true,
17+
Description: `The id of the Firebase web App.`,
18+
},
19+
"project": {
20+
Type: schema.TypeString,
21+
Optional: true,
22+
Description: `The project id of the Firebase web App.`,
23+
},
24+
"api_key": {
25+
Type: schema.TypeString,
26+
Computed: true,
27+
Description: `The API key associated with the web App.`,
28+
},
29+
"auth_domain": {
30+
Type: schema.TypeString,
31+
Computed: true,
32+
Description: `The domain Firebase Auth configures for OAuth redirects, in the format:
33+
34+
projectId.firebaseapp.com`,
35+
},
36+
"database_url": {
37+
Type: schema.TypeString,
38+
Computed: true,
39+
Description: `The default Firebase Realtime Database URL.`,
40+
},
41+
"location_id": {
42+
Type: schema.TypeString,
43+
Computed: true,
44+
Description: `The ID of the project's default GCP resource location. The location is one of the available GCP resource
45+
locations.
46+
47+
This field is omitted if the default GCP resource location has not been finalized yet. To set your project's
48+
default GCP resource location, call defaultLocation.finalize after you add Firebase services to your project.`,
49+
},
50+
"measurement_id": {
51+
Type: schema.TypeString,
52+
Computed: true,
53+
Description: `The unique Google-assigned identifier of the Google Analytics web stream associated with the Firebase Web App.
54+
Firebase SDKs use this ID to interact with Google Analytics APIs.
55+
56+
This field is only present if the App is linked to a web stream in a Google Analytics App + Web property.
57+
Learn more about this ID and Google Analytics web streams in the Analytics documentation.
58+
59+
To generate a measurementId and link the Web App with a Google Analytics web stream,
60+
call projects.addGoogleAnalytics.`,
61+
},
62+
"messaging_sender_id": {
63+
Type: schema.TypeString,
64+
Computed: true,
65+
Description: `The sender ID for use with Firebase Cloud Messaging.`,
66+
},
67+
"storage_bucket": {
68+
Type: schema.TypeString,
69+
Computed: true,
70+
Description: `The default Cloud Storage for Firebase storage bucket name.`,
71+
},
72+
},
73+
}
74+
75+
}
76+
77+
func dataSourceGoogleFirebaseWebappConfigRead(d *schema.ResourceData, meta interface{}) error {
78+
config := meta.(*Config)
79+
80+
id := d.Get("web_app_id").(string)
81+
82+
project, err := getProject(d, config)
83+
if err != nil {
84+
return err
85+
}
86+
87+
url, err := replaceVars(d, config, "{{FirebaseBasePath}}projects/{{project}}/webApps/{{web_app_id}}/config")
88+
if err != nil {
89+
return err
90+
}
91+
92+
res, err := sendRequest(config, "GET", project, url, nil)
93+
if err != nil {
94+
return handleNotFoundError(err, d, fmt.Sprintf("FirebaseWebApp config %q", d.Id()))
95+
}
96+
97+
err = d.Set("api_key", res["apiKey"])
98+
if err != nil {
99+
return err
100+
}
101+
err = d.Set("auth_domain", res["authDomain"])
102+
if err != nil {
103+
return err
104+
}
105+
err = d.Set("database_url", res["databaseURL"])
106+
if err != nil {
107+
return err
108+
}
109+
err = d.Set("location_id", res["locationId"])
110+
if err != nil {
111+
return err
112+
}
113+
err = d.Set("measurement_id", res["measurementId"])
114+
if err != nil {
115+
return err
116+
}
117+
err = d.Set("messaging_sender_id", res["messagingSenderId"])
118+
if err != nil {
119+
return err
120+
}
121+
err = d.Set("storage_bucket", res["storageBucket"])
122+
if err != nil {
123+
return err
124+
}
125+
126+
d.SetId(id)
127+
return nil
128+
}

google-beta/provider.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -558,6 +558,8 @@ func Provider() terraform.ResourceProvider {
558558
"google_kms_key_ring": dataSourceGoogleKmsKeyRing(),
559559
"google_kms_secret": dataSourceGoogleKmsSecret(),
560560
"google_kms_secret_ciphertext": dataSourceGoogleKmsSecretCiphertext(),
561+
"google_firebase_web_app": dataSourceGoogleFirebaseWebApp(),
562+
"google_firebase_web_app_config": dataSourceGoogleFirebaseWebappConfig(),
561563
"google_folder": dataSourceGoogleFolder(),
562564
"google_folder_organization_policy": dataSourceGoogleFolderOrganizationPolicy(),
563565
"google_monitoring_notification_channel": dataSourceMonitoringNotificationChannel(),
@@ -596,9 +598,9 @@ func Provider() terraform.ResourceProvider {
596598
return provider
597599
}
598600

599-
// Generated resources: 142
601+
// Generated resources: 143
600602
// Generated IAM resources: 54
601-
// Total generated resources: 196
603+
// Total generated resources: 197
602604
func ResourceMap() map[string]*schema.Resource {
603605
resourceMap, _ := ResourceMapWithErrors()
604606
return resourceMap
@@ -714,6 +716,7 @@ func ResourceMapWithErrors() (map[string]*schema.Resource, error) {
714716
"google_filestore_instance": resourceFilestoreInstance(),
715717
"google_firebase_project": resourceFirebaseProject(),
716718
"google_firebase_project_location": resourceFirebaseProjectLocation(),
719+
"google_firebase_web_app": resourceFirebaseWebApp(),
717720
"google_firestore_index": resourceFirestoreIndex(),
718721
"google_game_services_realm": resourceGameServicesRealm(),
719722
"google_game_services_game_server_cluster": resourceGameServicesGameServerCluster(),

google-beta/resource_firebase_project.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func resourceFirebaseProject() *schema.Resource {
3434

3535
Timeouts: &schema.ResourceTimeout{
3636
Create: schema.DefaultTimeout(10 * time.Minute),
37-
Delete: schema.DefaultTimeout(10 * time.Minute),
37+
Delete: schema.DefaultTimeout(4 * time.Minute),
3838
},
3939

4040
Schema: map[string]*schema.Schema{

0 commit comments

Comments
 (0)