Skip to content

Commit 534e563

Browse files
Add tests for force deletion (#13219) (#21736)
[upstream:38466ac80f7868e8e9e7eeee4b174d73613659b5] Signed-off-by: Modular Magician <[email protected]>
1 parent 7b838de commit 534e563

File tree

4 files changed

+80
-8
lines changed

4 files changed

+80
-8
lines changed

.changelog/13219.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
firebasedataconnect: added `deletion_policy` support to `google_firebase_data_connect_service` resource
3+
```

google/services/firebasedataconnect/resource_firebase_data_connect_service_generated_test.go

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ resource "google_project_service" "fdc" {
6666
disable_on_destroy = false
6767
}
6868
69-
# Create an FDC service
69+
# Create a Firebase Data Connect service
7070
resource "google_firebase_data_connect_service" "default" {
7171
project = "%{project_id}"
7272
location = "us-central1"
@@ -87,6 +87,53 @@ resource "google_firebase_data_connect_service" "default" {
8787
`, context)
8888
}
8989

90+
func TestAccFirebaseDataConnectService_firebasedataconnectServiceWithForceDeletionExample(t *testing.T) {
91+
t.Parallel()
92+
93+
context := map[string]interface{}{
94+
"project_id": envvar.GetTestProjectFromEnv(),
95+
"random_suffix": acctest.RandString(t, 10),
96+
}
97+
98+
acctest.VcrTest(t, resource.TestCase{
99+
PreCheck: func() { acctest.AccTestPreCheck(t) },
100+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
101+
CheckDestroy: testAccCheckFirebaseDataConnectServiceDestroyProducer(t),
102+
Steps: []resource.TestStep{
103+
{
104+
Config: testAccFirebaseDataConnectService_firebasedataconnectServiceWithForceDeletionExample(context),
105+
},
106+
{
107+
ResourceName: "google_firebase_data_connect_service.default",
108+
ImportState: true,
109+
ImportStateVerify: true,
110+
ImportStateVerifyIgnore: []string{"annotations", "deletion_policy", "labels", "location", "service_id", "terraform_labels"},
111+
},
112+
},
113+
})
114+
}
115+
116+
func testAccFirebaseDataConnectService_firebasedataconnectServiceWithForceDeletionExample(context map[string]interface{}) string {
117+
return acctest.Nprintf(`
118+
# Enable Firebase Data Connect API
119+
resource "google_project_service" "fdc" {
120+
project = "%{project_id}"
121+
service = "firebasedataconnect.googleapis.com"
122+
disable_on_destroy = false
123+
}
124+
125+
# Create a Firebase Data Connect service
126+
resource "google_firebase_data_connect_service" "default" {
127+
project = "%{project_id}"
128+
location = "us-central1"
129+
service_id = "tf-test-example-service%{random_suffix}"
130+
deletion_policy = "FORCE"
131+
132+
depends_on = [google_project_service.fdc]
133+
}
134+
`, context)
135+
}
136+
90137
func testAccCheckFirebaseDataConnectServiceDestroyProducer(t *testing.T) func(s *terraform.State) error {
91138
return func(s *terraform.State) error {
92139
for name, rs := range s.RootModule().Resources {

google/services/firebasedataconnect/resource_firebase_data_connect_service_test.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,16 @@ func TestAccFirebaseDataConnectService_Update(t *testing.T) {
2929
CheckDestroy: testAccCheckFirebaseDataConnectServiceDestroyProducer(t),
3030
Steps: []resource.TestStep{
3131
{
32-
Config: testAccFirebaseDataConnectService_update(context, "Original display name"),
32+
Config: testAccFirebaseDataConnectService_update(context, "Original display name", "DEFAULT"),
3333
},
3434
{
3535
ResourceName: "google_firebase_data_connect_service.default",
3636
ImportState: true,
3737
ImportStateVerify: true,
38-
ImportStateVerifyIgnore: []string{"annotations", "labels", "location", "service_id", "terraform_labels"},
38+
ImportStateVerifyIgnore: []string{"annotations", "labels", "location", "service_id", "terraform_labels", "deletion_policy"},
3939
},
4040
{
41-
Config: testAccFirebaseDataConnectService_update(context, "Updated display name"),
41+
Config: testAccFirebaseDataConnectService_update(context, "Updated display name", "FORCE"),
4242
ConfigPlanChecks: resource.ConfigPlanChecks{
4343
PreApply: []plancheck.PlanCheck{
4444
plancheck.ExpectResourceAction("google_firebase_data_connect_service.default", plancheck.ResourceActionUpdate),
@@ -49,15 +49,15 @@ func TestAccFirebaseDataConnectService_Update(t *testing.T) {
4949
ResourceName: "google_firebase_data_connect_service.default",
5050
ImportState: true,
5151
ImportStateVerify: true,
52-
ImportStateVerifyIgnore: []string{"annotations", "labels", "location", "service_id", "terraform_labels"},
52+
ImportStateVerifyIgnore: []string{"annotations", "labels", "location", "service_id", "terraform_labels", "deletion_policy"},
5353
},
5454
},
5555
})
5656
}
5757

58-
// TODO(b/394642094): Cover force deletion once it's supported
59-
func testAccFirebaseDataConnectService_update(context map[string]interface{}, display_name string) string {
58+
func testAccFirebaseDataConnectService_update(context map[string]interface{}, display_name string, deletion_policy string) string {
6059
context["display_name"] = display_name
60+
context["deletion_policy"] = deletion_policy
6161
return acctest.Nprintf(`
6262
# Enable Firebase Data Connect API
6363
resource "google_project_service" "fdc" {
@@ -72,6 +72,7 @@ resource "google_firebase_data_connect_service" "default" {
7272
location = "us-central1"
7373
service_id = "tf-fdc-%{random_suffix}"
7474
display_name = "%{display_name}"
75+
deletion_policy = "%{deletion_policy}"
7576
7677
depends_on = [google_project_service.fdc]
7778
}

website/docs/r/firebase_data_connect_service.html.markdown

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ resource "google_project_service" "fdc" {
4141
disable_on_destroy = false
4242
}
4343
44-
# Create an FDC service
44+
# Create a Firebase Data Connect service
4545
resource "google_firebase_data_connect_service" "default" {
4646
project = "my-project-name"
4747
location = "us-central1"
@@ -60,6 +60,27 @@ resource "google_firebase_data_connect_service" "default" {
6060
depends_on = [google_project_service.fdc]
6161
}
6262
```
63+
## Example Usage - Firebasedataconnect Service With Force Deletion
64+
65+
66+
```hcl
67+
# Enable Firebase Data Connect API
68+
resource "google_project_service" "fdc" {
69+
project = "my-project-name"
70+
service = "firebasedataconnect.googleapis.com"
71+
disable_on_destroy = false
72+
}
73+
74+
# Create a Firebase Data Connect service
75+
resource "google_firebase_data_connect_service" "default" {
76+
project = "my-project-name"
77+
location = "us-central1"
78+
service_id = "example-service"
79+
deletion_policy = "FORCE"
80+
81+
depends_on = [google_project_service.fdc]
82+
}
83+
```
6384

6485
## Argument Reference
6586

0 commit comments

Comments
 (0)