Skip to content

Commit

Permalink
Add Firebase AndroidApp Data Source (#6903)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
mraouffouad committed Dec 6, 2022
1 parent 4256948 commit 5528753
Show file tree
Hide file tree
Showing 5 changed files with 145 additions and 2 deletions.
2 changes: 1 addition & 1 deletion mmv1/products/firebase/api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -295,4 +295,4 @@ objects:
- !ruby/object:Api::Type::String
name: teamId
description: |
The Apple Developer Team ID associated with the App in the App Store.
The Apple Developer Team ID associated with the App in the App Store.
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<% autogen_exception -%>
package google
<% unless version == 'ga' -%>
import (
"fmt"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)

func dataSourceGoogleFirebaseAndroidApp() *schema.Resource {
// Generate datasource schema from resource
dsSchema := datasourceSchemaFromResourceSchema(resourceFirebaseAndroidApp().Schema)

// Set 'Required' schema elements
addRequiredFieldsToSchema(dsSchema, "app_id")

return &schema.Resource{
Read: dataSourceGoogleFirebaseAndroidAppRead,
Schema: dsSchema,
}
}

func dataSourceGoogleFirebaseAndroidAppRead(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
appId := d.Get("app_id")
project, err := getProject(d, config)
if err != nil {
return err
}
name := fmt.Sprintf("projects/%s/androidApps/%s", project, appId.(string))
d.SetId(name)
if err := d.Set("name", name); err != nil {
return fmt.Errorf("Error setting name: %s", err)
}
return resourceFirebaseAndroidAppRead(d, meta)
}
<% end -%>
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<% autogen_exception -%>
package google
<% unless version == 'ga' -%>
import (
"testing"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
)

func TestAccDataSourceGoogleFirebaseAndroidApp(t *testing.T) {
t.Parallel()

context := map[string]interface{}{
"project_id": getTestProjectFromEnv(),
"package_name": "android.package." + randString(t, 5),
"display_name": "Display Name AndroidApp DataSource",
}

resourceName := "data.google_firebase_android_app.my_app"

vcrTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccDataSourceGoogleFirebaseAndroidApp(context),
Check: resource.ComposeTestCheckFunc(
checkDataSourceStateMatchesResourceStateWithIgnores(
resourceName,
"google_firebase_android_app.my_app",
map[string]struct{}{
"deletion_policy": {},
},
),
),
},
},
})
}

func testAccDataSourceGoogleFirebaseAndroidApp(context map[string]interface{}) string {
return Nprintf(`
resource "google_firebase_android_app" "my_app" {
project = "%{project_id}"
package_name ="%{package_name}"
display_name = "%{display_name}"
}

data "google_firebase_android_app" "my_app" {
app_id = google_firebase_android_app.my_app.app_id
}
`, context)
}
<% end -%>
3 changes: 2 additions & 1 deletion mmv1/third_party/terraform/utils/provider.go.erb
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,8 @@ func Provider() *schema.Provider {
"google_kms_secret": dataSourceGoogleKmsSecret(),
"google_kms_secret_ciphertext": dataSourceGoogleKmsSecretCiphertext(),
<% unless version == 'ga' -%>
"google_kms_secret_asymmetric": dataSourceGoogleKmsSecretAsymmetric(),
"google_kms_secret_asymmetric": dataSourceGoogleKmsSecretAsymmetric(),
"google_firebase_android_app": dataSourceGoogleFirebaseAndroidApp(),
"google_firebase_web_app": dataSourceGoogleFirebaseWebApp(),
"google_firebase_web_app_config": dataSourceGoogleFirebaseWebappConfig(),
<% end -%>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
---
subcategory: "Firebase"
page_title: "Google: google_firebase_android_app"
description: |-
A Google Cloud Firebase Android application instance
---

# google\_firebase\_android\_app

A Google Cloud Firebase Android application instance

~> **Warning:** This resource is in beta, and should be used with the terraform-provider-google-beta provider.
See [Provider Versions](https://terraform.io/docs/providers/google/guides/provider_versions.html) for more details on beta resources.


## Argument Reference

The following arguments are supported:


* `app_id` -
(Required)
The app_ip of name of the Firebase androidApp.


- - -


* `project` - (Optional) The ID of the project in which the resource belongs.
If it is not provided, the provider project is used.


## Attributes Reference

In addition to the arguments listed above, the following computed attributes are exported:

* `id` - an identifier for the resource with format `{{name}}`

* `name` -
The fully qualified resource name of the App, for example:
projects/projectId/androidApps/appId

* `app_id` -
Immutable. The globally unique, Firebase-assigned identifier of the App.
This identifier should be treated as an opaque token, as the data format is not specified.

* `display_name` -
The user-assigned display name of the App.

* `package_name` -
The canonical package name of the Android app as would appear in the Google Play Developer Console.

0 comments on commit 5528753

Please sign in to comment.