Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix https://github.com/hashicorp/terraform-provider-google/issues/17389 #10206

Merged
merged 1 commit into from
Mar 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 -%>