Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
)
  • Loading branch information
rainshen49 authored and balanaguharsha committed Apr 19, 2024
1 parent 8383b40 commit d4d4b5b
Show file tree
Hide file tree
Showing 3 changed files with 137 additions and 57 deletions.
4 changes: 2 additions & 2 deletions mmv1/products/firebaseappcheck/ServiceConfig.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ examples:
name: "firebase_app_check_service_config_unenforced"
primary_resource_id: "default"
vars:
service_id: "firebasedatabase.googleapis.com"
service_id: "identitytoolkit.googleapis.com"
test_vars_overrides:
service_id: '"firebasedatabase.googleapis.com"'
service_id: '"identitytoolkit.googleapis.com"'
test_env_vars:
project_id: :PROJECT_NAME
parameters:
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
<% autogen_exception -%>
package firebaseappcheck_test
<% unless version == 'ga' -%>

import (
"testing"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"

"github.com/hashicorp/terraform-provider-google/google/acctest"
"github.com/hashicorp/terraform-provider-google/google/envvar"
)

func TestAccFirebaseAppCheckServiceConfig_firebaseAppCheckServiceConfigUpdate(t *testing.T) {
t.Parallel()

context := map[string]interface{}{
"org_id": envvar.GetTestOrgFromEnv(t),
"random_suffix": acctest.RandString(t, 10),
}

acctest.VcrTest(t, resource.TestCase{
PreCheck: func() { acctest.AccTestPreCheck(t) },
ProtoV5ProviderFactories: acctest.ProtoV5ProviderBetaFactories(t),
CheckDestroy: testAccCheckFirebaseAppCheckServiceConfigDestroyProducer(t),
ExternalProviders: map[string]resource.ExternalProvider{
"random": {},
"time": {},
},
Steps: []resource.TestStep{
{
Config: testAccFirebaseAppCheckServiceConfig_firebaseAppCheckServiceConfigUpdate(context, "UNENFORCED"),
},
{
ResourceName: "google_firebase_app_check_service_config.default",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"service_id"},
},
{
Config: testAccFirebaseAppCheckServiceConfig_firebaseAppCheckServiceConfigUpdate(context, "ENFORCED"),
},
{
ResourceName: "google_firebase_app_check_service_config.default",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"service_id"},
},
{
Config: testAccFirebaseAppCheckServiceConfig_firebaseAppCheckServiceConfigUpdate(context, ""),
},
{
ResourceName: "google_firebase_app_check_service_config.default",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"service_id"},
},
},
})
}

func testAccFirebaseAppCheckServiceConfig_firebaseAppCheckServiceConfigUpdate(context map[string]interface{}, enforcementMode string) string {
context["enforcement_mode"] = enforcementMode
return acctest.Nprintf(`
resource "google_project" "default" {
provider = google-beta
project_id = "tf-test-appcheck%{random_suffix}"
name = "tf-test-appcheck%{random_suffix}"
org_id = "%{org_id}"
labels = {
"firebase" = "enabled"
}
}

resource "google_project_service" "firebase" {
provider = google-beta
project = google_project.default.project_id
service = "firebase.googleapis.com"
disable_on_destroy = false
}

resource "google_project_service" "database" {
provider = google-beta
project = google_project.default.project_id
service = "firebasedatabase.googleapis.com"
disable_on_destroy = false
}

resource "google_project_service" "appcheck" {
provider = google-beta
project = google_project.default.project_id
service = "firebaseappcheck.googleapis.com"
disable_on_destroy = false
}

resource "google_firebase_project" "default" {
provider = google-beta
project = google_project.default.project_id

depends_on = [
google_project_service.firebase,
google_project_service.database,
google_project_service.appcheck,
]
}

# It takes a while for the new project to be ready for a database
resource "time_sleep" "wait_30s" {
depends_on = [google_firebase_project.default]
create_duration = "30s"
}

resource "google_firebase_database_instance" "default" {
provider = google-beta
project = google_firebase_project.default.project
region = "us-central1"
instance_id = "tf-test-appcheck%{random_suffix}-default-rtdb"
type = "DEFAULT_DATABASE"

depends_on = [time_sleep.wait_30s]
}

resource "google_firebase_app_check_service_config" "default" {
provider = google-beta
project = google_firebase_project.default.project
service_id = "firebasedatabase.googleapis.com"
enforcement_mode = "%{enforcement_mode}"

depends_on = [google_firebase_database_instance.default]
}
`, context)
}
<% end -%>

0 comments on commit d4d4b5b

Please sign in to comment.