-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Signed-off-by: Modular Magician <[email protected]> Signed-off-by: Modular Magician <[email protected]>
- Loading branch information
1 parent
47c7a2e
commit 0f155ac
Showing
4 changed files
with
235 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
```release-note:new-resource | ||
|
||
``` |
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,119 @@ | ||
// ---------------------------------------------------------------------------- | ||
// | ||
// *** HANDWRITTEN CODE *** Type: MMv1 *** | ||
// | ||
// ---------------------------------------------------------------------------- | ||
|
||
package google | ||
|
||
import ( | ||
"context" | ||
"log" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" | ||
) | ||
|
||
func init() { | ||
resource.AddTestSweepers("FirebaseAndroidApp", &resource.Sweeper{ | ||
Name: "FirebaseAndroidApp", | ||
F: testSweepFirebaseAndroidApp, | ||
}) | ||
} | ||
|
||
// At the time of writing, the CI only passes us-central1 as the region | ||
func testSweepFirebaseAndroidApp(region string) error { | ||
resourceName := "FirebaseAndroidApp" | ||
log.Printf("[INFO][SWEEPER_LOG] Starting sweeper for %s", resourceName) | ||
|
||
config, err := sharedConfigForRegion(region) | ||
if err != nil { | ||
log.Printf("[INFO][SWEEPER_LOG] error getting shared config for region: %s", err) | ||
return err | ||
} | ||
|
||
err = config.LoadAndValidate(context.Background()) | ||
if err != nil { | ||
log.Printf("[INFO][SWEEPER_LOG] error loading: %s", err) | ||
return err | ||
} | ||
|
||
t := &testing.T{} | ||
billingId := getTestBillingAccountFromEnv(t) | ||
|
||
// Setup variables to replace in list template | ||
d := &ResourceDataMock{ | ||
FieldsInSchema: map[string]interface{}{ | ||
"project": config.Project, | ||
"region": region, | ||
"location": region, | ||
"zone": "-", | ||
"billing_account": billingId, | ||
}, | ||
} | ||
|
||
listTemplate := strings.Split("https://firebase.googleapis.com/v1beta1/projects/{{project}}/androidApps", "?")[0] | ||
listUrl, err := replaceVars(d, config, listTemplate) | ||
if err != nil { | ||
log.Printf("[INFO][SWEEPER_LOG] error preparing sweeper list url: %s", err) | ||
return nil | ||
} | ||
|
||
res, err := sendRequest(config, "GET", config.Project, listUrl, config.userAgent, nil) | ||
if err != nil { | ||
log.Printf("[INFO][SWEEPER_LOG] Error in response from request %s: %s", listUrl, err) | ||
return nil | ||
} | ||
|
||
resourceList, ok := res["androidApps"] | ||
if !ok { | ||
log.Printf("[INFO][SWEEPER_LOG] Nothing found in response.") | ||
return nil | ||
} | ||
|
||
rl := resourceList.([]interface{}) | ||
|
||
log.Printf("[INFO][SWEEPER_LOG] Found %d items in %s list response.", len(rl), resourceName) | ||
// Keep count of items that aren't sweepable for logging. | ||
nonPrefixCount := 0 | ||
for _, ri := range rl { | ||
obj := ri.(map[string]interface{}) | ||
if obj["name"] == nil { | ||
log.Printf("[INFO][SWEEPER_LOG] %s resource name was nil", resourceName) | ||
return nil | ||
} | ||
|
||
name := GetResourceNameFromSelfLink(obj["name"].(string)) | ||
// Skip resources that shouldn't be sweeped | ||
if !isSweepableTestResource(name) { | ||
nonPrefixCount++ | ||
continue | ||
} | ||
|
||
deleteTemplate := "https://firebase.googleapis.com/v1beta1/{{name}}:remove" | ||
deleteUrl, err := replaceVars(d, config, deleteTemplate) | ||
if err != nil { | ||
log.Printf("[INFO][SWEEPER_LOG] error preparing delete url: %s", err) | ||
return nil | ||
} | ||
deleteUrl = deleteUrl + name | ||
|
||
body := make(map[string]interface{}) | ||
body["immediate"] = true | ||
|
||
// Don't wait on operations as we may have a lot to delete | ||
_, err = sendRequest(config, "DELETE", config.Project, deleteUrl, config.userAgent, body) | ||
if err != nil { | ||
log.Printf("[INFO][SWEEPER_LOG] Error deleting for url %s : %s", deleteUrl, err) | ||
} else { | ||
log.Printf("[INFO][SWEEPER_LOG] Sent delete request for %s resource: %s", resourceName, name) | ||
} | ||
} | ||
|
||
if nonPrefixCount > 0 { | ||
log.Printf("[INFO][SWEEPER_LOG] %d items were non-sweepable and skipped.", nonPrefixCount) | ||
} | ||
|
||
return nil | ||
} |
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 @@ | ||
package google |
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,112 @@ | ||
--- | ||
# ---------------------------------------------------------------------------- | ||
# | ||
# *** AUTO GENERATED CODE *** Type: MMv1 *** | ||
# | ||
# ---------------------------------------------------------------------------- | ||
# | ||
# This file is automatically generated by Magic Modules and manual | ||
# changes will be clobbered when the file is regenerated. | ||
# | ||
# Please read more about how to change this file in | ||
# .github/CONTRIBUTING.md. | ||
# | ||
# ---------------------------------------------------------------------------- | ||
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. | ||
|
||
To get more information about AndroidApp, see: | ||
|
||
* [API documentation](https://firebase.google.com/docs/projects/api/reference/rest/v1beta1/projects.androidApps) | ||
* How-to Guides | ||
* [Official Documentation](https://firebase.google.com/docs/android/setup) | ||
|
||
## Example Usage - Firebase Android App Basic | ||
|
||
|
||
```hcl | ||
resource "google_firebase_android_app" "basic" { | ||
provider = google-beta | ||
project = "my-project-name" | ||
display_name = "Display Name Basic" | ||
package_name = "" | ||
} | ||
``` | ||
|
||
## Argument Reference | ||
|
||
The following arguments are supported: | ||
|
||
|
||
* `display_name` - | ||
(Required) | ||
The user-assigned display name of the App. | ||
|
||
|
||
- - - | ||
|
||
|
||
* `package_name` - | ||
(Optional) | ||
Immutable. The canonical package name of the Android app as would appear in the Google Play | ||
Developer Console. | ||
|
||
* `deletion_policy` - | ||
(Optional) | ||
(Optional) Set to `ABANDON` to allow the AndroidApp to be untracked from terraform state | ||
rather than deleted upon `terraform destroy`. This is useful because the AndroidApp may be | ||
serving traffic. Set to `DELETE` to delete the AndroidApp. Default to `DELETE`. | ||
|
||
* `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. | ||
|
||
|
||
## Timeouts | ||
|
||
This resource provides the following | ||
[Timeouts](/docs/configuration/resources.html#timeouts) configuration options: | ||
|
||
- `create` - Default is 20 minutes. | ||
- `update` - Default is 20 minutes. | ||
- `delete` - Default is 20 minutes. | ||
|
||
## Import | ||
|
||
|
||
AndroidApp can be imported using any of these accepted formats: | ||
|
||
``` | ||
$ terraform import google_firebase_android_app.default projects/{{project}}/androidApps/{{appId}} | ||
$ terraform import google_firebase_android_app.default {{project}}/{{appId}} | ||
$ terraform import google_firebase_android_app.default androidApps/{{appId}} | ||
$ terraform import google_firebase_android_app.default {{appId}} | ||
``` | ||
|
||
## User Project Overrides | ||
|
||
This resource supports [User Project Overrides](https://www.terraform.io/docs/providers/google/guides/provider_reference.html#user_project_override). |