forked from GoogleCloudPlatform/magic-modules
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Firebase AndroidApp Data Source (GoogleCloudPlatform#6903)
* 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
1 parent
dc7d54b
commit cee2ed7
Showing
5 changed files
with
145 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
mmv1/third_party/terraform/data_sources/data_source_google_firebase_android_app.go.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 -%> |
54 changes: 54 additions & 0 deletions
54
mmv1/third_party/terraform/tests/data_source_google_firebase_android_app_test.go.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 -%> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
mmv1/third_party/terraform/website/docs/d/firebase_android_app.html.markdown
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |