Skip to content

Add tests for force deletion #9496

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

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
3 changes: 3 additions & 0 deletions .changelog/13219.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
firebasedataconnect: added `deletion_policy` support to `google_firebase_data_connect_service` resource
```
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ resource "google_project_service" "fdc" {
disable_on_destroy = false
}

# Create an FDC service
# Create a Firebase Data Connect service
resource "google_firebase_data_connect_service" "default" {
project = "%{project_id}"
location = "us-central1"
Expand All @@ -87,6 +87,53 @@ resource "google_firebase_data_connect_service" "default" {
`, context)
}

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

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

acctest.VcrTest(t, resource.TestCase{
PreCheck: func() { acctest.AccTestPreCheck(t) },
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
CheckDestroy: testAccCheckFirebaseDataConnectServiceDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccFirebaseDataConnectService_firebasedataconnectServiceWithForceDeletionExample(context),
},
{
ResourceName: "google_firebase_data_connect_service.default",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"annotations", "deletion_policy", "labels", "location", "service_id", "terraform_labels"},
},
},
})
}

func testAccFirebaseDataConnectService_firebasedataconnectServiceWithForceDeletionExample(context map[string]interface{}) string {
return acctest.Nprintf(`
# Enable Firebase Data Connect API
resource "google_project_service" "fdc" {
project = "%{project_id}"
service = "firebasedataconnect.googleapis.com"
disable_on_destroy = false
}

# Create a Firebase Data Connect service
resource "google_firebase_data_connect_service" "default" {
project = "%{project_id}"
location = "us-central1"
service_id = "tf-test-example-service%{random_suffix}"
deletion_policy = "FORCE"

depends_on = [google_project_service.fdc]
}
`, context)
}

func testAccCheckFirebaseDataConnectServiceDestroyProducer(t *testing.T) func(s *terraform.State) error {
return func(s *terraform.State) error {
for name, rs := range s.RootModule().Resources {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,16 @@ func TestAccFirebaseDataConnectService_Update(t *testing.T) {
CheckDestroy: testAccCheckFirebaseDataConnectServiceDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccFirebaseDataConnectService_update(context, "Original display name"),
Config: testAccFirebaseDataConnectService_update(context, "Original display name", "DEFAULT"),
},
{
ResourceName: "google_firebase_data_connect_service.default",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"annotations", "labels", "location", "service_id", "terraform_labels"},
ImportStateVerifyIgnore: []string{"annotations", "labels", "location", "service_id", "terraform_labels", "deletion_policy"},
},
{
Config: testAccFirebaseDataConnectService_update(context, "Updated display name"),
Config: testAccFirebaseDataConnectService_update(context, "Updated display name", "FORCE"),
ConfigPlanChecks: resource.ConfigPlanChecks{
PreApply: []plancheck.PlanCheck{
plancheck.ExpectResourceAction("google_firebase_data_connect_service.default", plancheck.ResourceActionUpdate),
Expand All @@ -49,15 +49,15 @@ func TestAccFirebaseDataConnectService_Update(t *testing.T) {
ResourceName: "google_firebase_data_connect_service.default",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"annotations", "labels", "location", "service_id", "terraform_labels"},
ImportStateVerifyIgnore: []string{"annotations", "labels", "location", "service_id", "terraform_labels", "deletion_policy"},
},
},
})
}

// TODO(b/394642094): Cover force deletion once it's supported
func testAccFirebaseDataConnectService_update(context map[string]interface{}, display_name string) string {
func testAccFirebaseDataConnectService_update(context map[string]interface{}, display_name string, deletion_policy string) string {
context["display_name"] = display_name
context["deletion_policy"] = deletion_policy
return acctest.Nprintf(`
# Enable Firebase Data Connect API
resource "google_project_service" "fdc" {
Expand All @@ -72,6 +72,7 @@ resource "google_firebase_data_connect_service" "default" {
location = "us-central1"
service_id = "tf-fdc-%{random_suffix}"
display_name = "%{display_name}"
deletion_policy = "%{deletion_policy}"

depends_on = [google_project_service.fdc]
}
Expand Down
23 changes: 22 additions & 1 deletion website/docs/r/firebase_data_connect_service.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ resource "google_project_service" "fdc" {
disable_on_destroy = false
}

# Create an FDC service
# Create a Firebase Data Connect service
resource "google_firebase_data_connect_service" "default" {
project = "my-project-name"
location = "us-central1"
Expand All @@ -60,6 +60,27 @@ resource "google_firebase_data_connect_service" "default" {
depends_on = [google_project_service.fdc]
}
```
## Example Usage - Firebasedataconnect Service With Force Deletion


```hcl
# Enable Firebase Data Connect API
resource "google_project_service" "fdc" {
project = "my-project-name"
service = "firebasedataconnect.googleapis.com"
disable_on_destroy = false
}

# Create a Firebase Data Connect service
resource "google_firebase_data_connect_service" "default" {
project = "my-project-name"
location = "us-central1"
service_id = "example-service"
deletion_policy = "FORCE"

depends_on = [google_project_service.fdc]
}
```

## Argument Reference

Expand Down