|
| 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 | +} |
0 commit comments