Skip to content

Commit

Permalink
Add AppleApp to Firebase. (#6630) (#13047)
Browse files Browse the repository at this point in the history
* Update api.yaml

* Update api.yaml

* Update api.yaml

* Update api.yaml

* Update terraform.yaml

* Create firebase_apple_app_basic.tf.erb

* Responding to tylerg-dev's comments

* Fixing the failing TestAccFirebaseAppleApp_firebaseAppleAppBasicExample test

* Add a handwritten sweeper to hard-delete the AppleApp

* Fix typo in update_mask

* Fix var name in test

* Add delete request body

* Change appId to app_id in the sweeper delete url

* Use custom_delete for deleting the AppleApp resource

* Update api.yaml

* Remove the repeated block in terraform.api

* Add a 5 sec in the post_delete template

* Move the 5 sec delay to the custom delete code

* Add "Optional" to the deletion_policy description.

* Address melinath@ comments

* Add a manual update test

* Remove unnecessary randomness. Also, move attributes to the vars section so they show up in docs.

* Update mmv1/products/firebase/terraform.yaml

Co-authored-by: Stephen Lewis (Burrows) <stephen.r.burrows@gmail.com>

* Update mmv1/products/firebase/terraform.yaml

Co-authored-by: Stephen Lewis (Burrows) <stephen.r.burrows@gmail.com>

* Update mmv1/products/firebase/terraform.yaml

Co-authored-by: Stephen Lewis (Burrows) <stephen.r.burrows@gmail.com>

* Update mmv1/third_party/terraform/tests/resource_firebase_apple_app_update_test.go.erb

Co-authored-by: Stephen Lewis (Burrows) <stephen.r.burrows@gmail.com>

* Update mmv1/third_party/terraform/tests/resource_firebase_apple_app_update_test.go.erb

Co-authored-by: Stephen Lewis (Burrows) <stephen.r.burrows@gmail.com>

* Update mmv1/third_party/terraform/tests/resource_firebase_apple_app_update_test.go.erb

Co-authored-by: Stephen Lewis (Burrows) <stephen.r.burrows@gmail.com>

* Adding back the test_vars_overrides.

Co-authored-by: Stephen Lewis (Burrows) <stephen.r.burrows@gmail.com>
Signed-off-by: Modular Magician <magic-modules@google.com>

Signed-off-by: Modular Magician <magic-modules@google.com>
Co-authored-by: Stephen Lewis (Burrows) <stephen.r.burrows@gmail.com>
  • Loading branch information
modular-magician and melinath committed Nov 15, 2022
1 parent 39c6dfe commit 0759cba
Show file tree
Hide file tree
Showing 8 changed files with 257 additions and 5 deletions.
3 changes: 3 additions & 0 deletions .changelog/6630.txt
@@ -0,0 +1,3 @@
```release-note:new-resource

```
119 changes: 119 additions & 0 deletions 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
}
1 change: 1 addition & 0 deletions google/resource_firebase_apple_app_update_test.go
@@ -0,0 +1 @@
package google
2 changes: 1 addition & 1 deletion website/docs/r/firebase_android_app.html.markdown
Expand Up @@ -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.


Expand Down
132 changes: 132 additions & 0 deletions 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).
1 change: 0 additions & 1 deletion website/docs/r/firebase_project.html.markdown
Expand Up @@ -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.
Expand Down
2 changes: 0 additions & 2 deletions website/docs/r/firebase_project_location.html.markdown
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion website/docs/r/firebase_web_app.html.markdown
Expand Up @@ -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` -
Expand Down

0 comments on commit 0759cba

Please sign in to comment.