diff --git a/.changelog/6630.txt b/.changelog/6630.txt new file mode 100644 index 00000000000..e3972ecc597 --- /dev/null +++ b/.changelog/6630.txt @@ -0,0 +1,3 @@ +```release-note:new-resource + +``` diff --git a/google/resource_firebase_apple_app_sweeper_test.go b/google/resource_firebase_apple_app_sweeper_test.go new file mode 100644 index 00000000000..4ab444d873b --- /dev/null +++ b/google/resource_firebase_apple_app_sweeper_test.go @@ -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("FirebaseAppleApp", &resource.Sweeper{ + Name: "FirebaseAppleApp", + F: testSweepFirebaseAppleApp, + }) +} + +// At the time of writing, the CI only passes us-central1 as the region +func testSweepFirebaseAppleApp(region string) error { + resourceName := "FirebaseAppleApp" + 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}}/iosApps", "?")[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["appleApps"] + 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/projects/{{project}}/iosApps/{{app_id}}: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 +} diff --git a/google/resource_firebase_apple_app_update_test.go b/google/resource_firebase_apple_app_update_test.go new file mode 100644 index 00000000000..71664db3c87 --- /dev/null +++ b/google/resource_firebase_apple_app_update_test.go @@ -0,0 +1 @@ +package google diff --git a/website/docs/r/firebase_android_app.html.markdown b/website/docs/r/firebase_android_app.html.markdown index 9f453eb9443..f1c8e38b1ee 100644 --- a/website/docs/r/firebase_android_app.html.markdown +++ b/website/docs/r/firebase_android_app.html.markdown @@ -82,7 +82,7 @@ In addition to the arguments listed above, the following computed attributes are projects/projectId/androidApps/appId * `app_id` - - Immutable. The globally unique, Firebase-assigned identifier of the App. + 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. diff --git a/website/docs/r/firebase_apple_app.html.markdown b/website/docs/r/firebase_apple_app.html.markdown new file mode 100644 index 00000000000..e6baff2b4dc --- /dev/null +++ b/website/docs/r/firebase_apple_app.html.markdown @@ -0,0 +1,132 @@ +--- +# ---------------------------------------------------------------------------- +# +# *** 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_apple_app" +description: |- + A Google Cloud Firebase Apple application instance +--- + +# google\_firebase\_apple\_app + +A Google Cloud Firebase Apple 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 AppleApp, see: + +* [API documentation](https://firebase.google.com/docs/projects/api/reference/rest/v1beta1/projects.iosApps) +* How-to Guides + * [Official Documentation](https://firebase.google.com/docs/ios/setup) + +## Example Usage - Firebase Apple App Basic + + +```hcl +resource "google_firebase_apple_app" "default" { + provider = google-beta + project = "my-project-name" + display_name = "Display Name Basic" + bundle_id = "apple.app.12345" +} +``` +## Example Usage - Firebase Apple App Full + + +```hcl +resource "google_firebase_apple_app" "full" { + provider = google-beta + project = "my-project-name" + display_name = "Display Name Full" + bundle_id = "apple.app.12345" + app_store_id = "12345" + team_id = "9987654321" +} +``` + +## Argument Reference + +The following arguments are supported: + + +* `display_name` - + (Required) + The user-assigned display name of the App. + + +- - - + + +* `bundle_id` - + (Optional) + The canonical bundle ID of the Apple app as it would appear in the Apple AppStore. + +* `app_store_id` - + (Optional) + The automatically generated Apple ID assigned to the Apple app by Apple in the Apple App Store. + +* `team_id` - + (Optional) + The Apple Developer Team ID associated with the App in the App Store. + +* `deletion_policy` - + (Optional) + (Optional) Set to `ABANDON` to allow the AppleApp to be untracked from terraform state + rather than deleted upon `terraform destroy`. This is useful because the AppleApp may be + serving traffic. Set to `DELETE` to delete the AppleApp. 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/iosApps/appId + +* `app_id` - + 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 + + +AppleApp can be imported using any of these accepted formats: + +``` +$ terraform import google_firebase_apple_app.default projects/{{project}}/iosApps/{{appId}} +$ terraform import google_firebase_apple_app.default {{project}}/{{appId}} +$ terraform import google_firebase_apple_app.default iosApps/{{appId}} +$ terraform import google_firebase_apple_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). diff --git a/website/docs/r/firebase_project.html.markdown b/website/docs/r/firebase_project.html.markdown index 46598d7a801..4a6698e7ecb 100644 --- a/website/docs/r/firebase_project.html.markdown +++ b/website/docs/r/firebase_project.html.markdown @@ -23,7 +23,6 @@ description: |- A Google Cloud Firebase instance. This enables Firebase resources on a given google project. Since a FirebaseProject is actually also a GCP Project, a FirebaseProject uses underlying GCP identifiers (most importantly, the projectId) as its own for easy interop with GCP APIs. - Once Firebase has been added to a Google Project it cannot be removed. ~> **Warning:** This resource is in beta, and should be used with the terraform-provider-google-beta provider. diff --git a/website/docs/r/firebase_project_location.html.markdown b/website/docs/r/firebase_project_location.html.markdown index 77a4ba14895..f573caff93b 100644 --- a/website/docs/r/firebase_project_location.html.markdown +++ b/website/docs/r/firebase_project_location.html.markdown @@ -21,10 +21,8 @@ description: |- # google\_firebase\_project\_location Sets the default Google Cloud Platform (GCP) resource location for the specified FirebaseProject. - This method creates an App Engine application with a default Cloud Storage bucket, located in the specified locationId. This location must be one of the available GCP resource locations. - After the default GCP resource location is finalized, or if it was already set, it cannot be changed. The default GCP resource location for the specified FirebaseProject might already be set because either the GCP Project already has an App Engine application or defaultLocation.finalize was previously called with a diff --git a/website/docs/r/firebase_web_app.html.markdown b/website/docs/r/firebase_web_app.html.markdown index 251e2dfdf4c..1138a414159 100644 --- a/website/docs/r/firebase_web_app.html.markdown +++ b/website/docs/r/firebase_web_app.html.markdown @@ -117,7 +117,7 @@ In addition to the arguments listed above, the following computed attributes are projects/projectId/webApps/appId * `app_id` - - Immutable. The globally unique, Firebase-assigned identifier of the App. + 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. * `app_urls` -