-
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.
* 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>
- Loading branch information
1 parent
336d650
commit 2fecbdf
Showing
6 changed files
with
293 additions
and
6 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
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
6 changes: 6 additions & 0 deletions
6
mmv1/templates/terraform/examples/firebase_apple_app_basic.tf.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,6 @@ | ||
resource "google_firebase_apple_app" "default" { | ||
provider = google-beta | ||
project = "<%= ctx[:test_env_vars]['project_id'] %>" | ||
display_name = "<%= ctx[:vars]['display_name'] %>" | ||
bundle_id = "<%= ctx[:vars]['bundle_id'] %>" | ||
} |
8 changes: 8 additions & 0 deletions
8
mmv1/templates/terraform/examples/firebase_apple_app_full.tf.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,8 @@ | ||
resource "google_firebase_apple_app" "full" { | ||
provider = google-beta | ||
project = "<%= ctx[:test_env_vars]['project_id'] %>" | ||
display_name = "<%= ctx[:vars]['display_name'] %>" | ||
bundle_id = "<%= ctx[:vars]['bundle_id'] %>" | ||
app_store_id = "<%= ctx[:vars]['app_store_id'] %>" | ||
team_id = "<%= ctx[:vars]['team_id'] %>" | ||
} |
119 changes: 119 additions & 0 deletions
119
mmv1/third_party/terraform/tests/resource_firebase_apple_app_sweeper_test.go
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("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 | ||
} |
49 changes: 49 additions & 0 deletions
49
mmv1/third_party/terraform/tests/resource_firebase_apple_app_update_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,49 @@ | ||
<% autogen_exception -%> | ||
package google | ||
<% unless version == 'ga' -%> | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" | ||
) | ||
|
||
func TestAccFirebaseAppleApp_update(t *testing.T) { | ||
t.Parallel() | ||
context := map[string]interface{}{ | ||
"project_id": getTestProjectFromEnv(), | ||
"bundle_id": "apple.app.12345", | ||
"random_suffix": randString(t, 10), | ||
"display_name": "Display Name N", | ||
} | ||
vcrTest(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProvidersOiCS, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccFirebaseAppleApp(context, 12345, "1"), | ||
}, | ||
{ | ||
Config: testAccFirebaseAppleApp(context, 67890, "2"), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccFirebaseAppleApp(context map[string]interface{}, appStoreId int, delta string) string { | ||
context["display_name"] = context["display_name"].(string) + delta | ||
context["app_store_id"] = appStoreId | ||
context["team_id"] = "123456789" + delta | ||
return Nprintf(` | ||
resource "google_firebase_apple_app" "update" { | ||
provider = google-beta | ||
project = "%{project_id}" | ||
bundle_id = "%{bundle_id}" | ||
display_name = "%{display_name} %{random_suffix}" | ||
app_store_id = "%{app_store_id}" | ||
team_id = "%{team_id}" | ||
} | ||
`, context) | ||
} | ||
|
||
<% end -%> |