Skip to content

Commit 45aa6e6

Browse files
Add Firebase AndroidApp Data Source (#6903) (#4955)
* Update api.yaml * Update api.yaml * Add a Datasource for Firebase AndroidApp * Add AndroidApp datasource * Add GA tags to data_source_google_firebase_android_app_test.go * Rename data_source_google_firebase_android_app_test.go to data_source_google_firebase_android_app_test.go.erb Signed-off-by: Modular Magician <[email protected]> Signed-off-by: Modular Magician <[email protected]>
1 parent c251ff1 commit 45aa6e6

File tree

5 files changed

+142
-0
lines changed

5 files changed

+142
-0
lines changed

.changelog/6903.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:new-datasource
2+
`google_firebase_android_app`
3+
```
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package google
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
7+
)
8+
9+
func dataSourceGoogleFirebaseAndroidApp() *schema.Resource {
10+
// Generate datasource schema from resource
11+
dsSchema := datasourceSchemaFromResourceSchema(resourceFirebaseAndroidApp().Schema)
12+
13+
// Set 'Required' schema elements
14+
addRequiredFieldsToSchema(dsSchema, "app_id")
15+
16+
return &schema.Resource{
17+
Read: dataSourceGoogleFirebaseAndroidAppRead,
18+
Schema: dsSchema,
19+
}
20+
}
21+
22+
func dataSourceGoogleFirebaseAndroidAppRead(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/androidApps/%s", project, appId.(string))
30+
d.SetId(name)
31+
if err := d.Set("name", name); err != nil {
32+
return fmt.Errorf("Error setting name: %s", err)
33+
}
34+
return resourceFirebaseAndroidAppRead(d, meta)
35+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package google
2+
3+
import (
4+
"testing"
5+
6+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
7+
)
8+
9+
func TestAccDataSourceGoogleFirebaseAndroidApp(t *testing.T) {
10+
t.Parallel()
11+
12+
context := map[string]interface{}{
13+
"project_id": getTestProjectFromEnv(),
14+
"package_name": "android.package." + randString(t, 5),
15+
"display_name": "Display Name AndroidApp DataSource",
16+
}
17+
18+
resourceName := "data.google_firebase_android_app.my_app"
19+
20+
vcrTest(t, resource.TestCase{
21+
PreCheck: func() { testAccPreCheck(t) },
22+
Providers: testAccProviders,
23+
Steps: []resource.TestStep{
24+
{
25+
Config: testAccDataSourceGoogleFirebaseAndroidApp(context),
26+
Check: resource.ComposeTestCheckFunc(
27+
checkDataSourceStateMatchesResourceStateWithIgnores(
28+
resourceName,
29+
"google_firebase_android_app.my_app",
30+
map[string]struct{}{
31+
"deletion_policy": {},
32+
},
33+
),
34+
),
35+
},
36+
},
37+
})
38+
}
39+
40+
func testAccDataSourceGoogleFirebaseAndroidApp(context map[string]interface{}) string {
41+
return Nprintf(`
42+
resource "google_firebase_android_app" "my_app" {
43+
project = "%{project_id}"
44+
package_name ="%{package_name}"
45+
display_name = "%{display_name}"
46+
}
47+
48+
data "google_firebase_android_app" "my_app" {
49+
app_id = google_firebase_android_app.my_app.app_id
50+
}
51+
`, context)
52+
}

google-beta/provider.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -996,6 +996,7 @@ func Provider() *schema.Provider {
996996
"google_kms_secret": dataSourceGoogleKmsSecret(),
997997
"google_kms_secret_ciphertext": dataSourceGoogleKmsSecretCiphertext(),
998998
"google_kms_secret_asymmetric": dataSourceGoogleKmsSecretAsymmetric(),
999+
"google_firebase_android_app": dataSourceGoogleFirebaseAndroidApp(),
9991000
"google_firebase_web_app": dataSourceGoogleFirebaseWebApp(),
10001001
"google_firebase_web_app_config": dataSourceGoogleFirebaseWebappConfig(),
10011002
"google_folder": dataSourceGoogleFolder(),
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
---
2+
subcategory: "Firebase"
3+
page_title: "Google: google_firebase_android_app"
4+
description: |-
5+
A Google Cloud Firebase Android application instance
6+
---
7+
8+
# google\_firebase\_android\_app
9+
10+
A Google Cloud Firebase Android application instance
11+
12+
~> **Warning:** This resource is in beta, and should be used with the terraform-provider-google-beta provider.
13+
See [Provider Versions](https://terraform.io/docs/providers/google/guides/provider_versions.html) for more details on beta resources.
14+
15+
16+
## Argument Reference
17+
18+
The following arguments are supported:
19+
20+
21+
* `app_id` -
22+
(Required)
23+
The app_ip of name of the Firebase androidApp.
24+
25+
26+
- - -
27+
28+
29+
* `project` - (Optional) The ID of the project in which the resource belongs.
30+
If it is not provided, the provider project is used.
31+
32+
33+
## Attributes Reference
34+
35+
In addition to the arguments listed above, the following computed attributes are exported:
36+
37+
* `id` - an identifier for the resource with format `{{name}}`
38+
39+
* `name` -
40+
The fully qualified resource name of the App, for example:
41+
projects/projectId/androidApps/appId
42+
43+
* `app_id` -
44+
Immutable. The globally unique, Firebase-assigned identifier of the App.
45+
This identifier should be treated as an opaque token, as the data format is not specified.
46+
47+
* `display_name` -
48+
The user-assigned display name of the App.
49+
50+
* `package_name` -
51+
The canonical package name of the Android app as would appear in the Google Play Developer Console.

0 commit comments

Comments
 (0)