Skip to content

Commit 1515656

Browse files
committed
fixed test caess
1 parent 64e0dab commit 1515656

File tree

3 files changed

+119
-95
lines changed

3 files changed

+119
-95
lines changed

mmv1/products/filestore/Instance.yaml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -168,17 +168,13 @@ properties:
168168
projects/{projectId}/locations/{locationId}/backups/{backupId},
169169
that this file share has been restored from.
170170
immutable: true
171-
conflicts:
172-
- 'sourceBackupdrBackup'
173171
- name: 'sourceBackupdrBackup'
174172
type: String
175173
description: |
176174
The resource name of the BackupDR backup, in the format
177175
`projects/{project_id}/locations/{location_id}/backupVaults/{backupvault_id}/dataSources/{datasource_id}/backups/{backup_id}`,
178176
that this file share has been restored from.
179177
immutable: true
180-
conflicts:
181-
- 'sourceBackup'
182178
- name: 'nfsExportOptions'
183179
type: Array
184180
description: |

mmv1/third_party/terraform/services/filestore/resource_filestore_backup_test.go

Lines changed: 0 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package filestore_test
22

33
import (
44
"fmt"
5-
"regexp"
65
"testing"
76

87
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
@@ -181,93 +180,3 @@ resource "google_filestore_backup" "backup" {
181180
}
182181
`, context)
183182
}
184-
185-
func TestAccFilestoreInstance_restoreBackupDR(t *testing.T) {
186-
t.Parallel()
187-
188-
name := fmt.Sprintf("tf-test-%d", acctest.RandInt(t))
189-
backupName := "projects/my-project/locations/us-central1/backupVaults/my-vault/dataSources/my-source/backups/my-backup"
190-
191-
acctest.VcrTest(t, resource.TestCase{
192-
PreCheck: func() { acctest.AccTestPreCheck(t) },
193-
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
194-
CheckDestroy: testAccCheckFilestoreInstanceDestroyProducer(t),
195-
Steps: []resource.TestStep{
196-
{
197-
Config: testAccFilestoreInstance_restoreBackupDR(name, backupName),
198-
Check: resource.ComposeTestCheckFunc(
199-
resource.TestCheckResourceAttr("google_filestore_instance.instance", "file_shares.0.source_backupdr_backup", backupName),
200-
),
201-
},
202-
{
203-
ResourceName: "google_filestore_instance.instance",
204-
ImportState: true,
205-
ImportStateVerify: true,
206-
ImportStateVerifyIgnore: []string{"zone", "location"},
207-
},
208-
},
209-
})
210-
}
211-
212-
func testAccFilestoreInstance_restoreBackupDR(name, backupName string) string {
213-
return fmt.Sprintf(`
214-
resource "google_filestore_instance" "instance" {
215-
name = "tf-instance-%s"
216-
location = "us-central1-b"
217-
tier = "BASIC_HDD"
218-
219-
file_shares {
220-
capacity_gb = 1024
221-
name = "share"
222-
source_backupdr_backup = "%s"
223-
}
224-
225-
networks {
226-
network = "default"
227-
modes = ["MODE_IPV4"]
228-
}
229-
}
230-
`, name, backupName)
231-
}
232-
233-
func TestAccFilestoreInstance_restoreBackupDR_conflicts(t *testing.T) {
234-
t.Parallel()
235-
236-
name := fmt.Sprintf("tf-test-%d", acctest.RandInt(t))
237-
backupName := "projects/my-project/locations/us-central1/backups/my-backup"
238-
backupdrName := "projects/my-project/locations/us-central1/backupVaults/my-vault/dataSources/my-source/backups/my-backup"
239-
240-
acctest.VcrTest(t, resource.TestCase{
241-
PreCheck: func() { acctest.AccTestPreCheck(t) },
242-
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
243-
CheckDestroy: testAccCheckFilestoreInstanceDestroyProducer(t),
244-
Steps: []resource.TestStep{
245-
{
246-
Config: testAccFilestoreInstance_sourceBackupDRConflicts(name, backupName, backupdrName),
247-
ExpectError: regexp.MustCompile(`"source_backupdr_backup": conflicts with "source_backup"`),
248-
},
249-
},
250-
})
251-
}
252-
253-
func testAccFilestoreInstance_sourceBackupDRConflicts(name, backupName, backupdrName string) string {
254-
return fmt.Sprintf(`
255-
resource "google_filestore_instance" "instance" {
256-
name = "tf-instance-%s"
257-
location = "us-central1-b"
258-
tier = "BASIC_HDD"
259-
260-
file_shares {
261-
capacity_gb = 1024
262-
name = "share"
263-
source_backup = "%s"
264-
source_backupdr_backup = "%s"
265-
}
266-
267-
networks {
268-
network = "default"
269-
modes = ["MODE_IPV4"]
270-
}
271-
}
272-
`, name, backupName, backupdrName)
273-
}

mmv1/third_party/terraform/services/filestore/resource_filestore_restore_test.go

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,3 +83,122 @@ func testAccFilestoreInstanceRestore_restore(srcInstancetName, restoreInstanceNa
8383
8484
`, srcInstancetName, restoreInstanceName, backupName)
8585
}
86+
87+
func TestAccFilestoreInstance_restoreBackupDR(t *testing.T) {
88+
t.Parallel()
89+
90+
instanceName := fmt.Sprintf("tf-test-%d", acctest.RandInt(t))
91+
backupName := fmt.Sprintf("tf-test-backup-%d", acctest.RandInt(t))
92+
acctest.VcrTest(t, resource.TestCase{
93+
PreCheck: func() { acctest.AccTestPreCheck(t) },
94+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
95+
CheckDestroy: testAccCheckFilestoreInstanceDestroyProducer(t),
96+
Steps: []resource.TestStep{
97+
{
98+
Config: testAccFilestoreInstance_restoreBackupDR(instanceName, backupName),
99+
},
100+
{
101+
ResourceName: "google_filestore_instance.instance",
102+
ImportState: true,
103+
ImportStateVerify: true,
104+
ImportStateVerifyIgnore: []string{"zone", "location"},
105+
},
106+
},
107+
})
108+
}
109+
110+
func testAccFilestoreInstance_restoreBackupDR(instanceName string, backupName string) string {
111+
return fmt.Sprintf(`
112+
data "google_project" "project" {}
113+
114+
locals {
115+
instance_name = "%s"
116+
backup_name = "%s"
117+
}
118+
119+
resource "google_filestore_instance" "source_instance" {
120+
name = "tf-source-instance-${local.instance_name}"
121+
location = "us-central1"
122+
tier = "REGIONAL"
123+
124+
file_shares {
125+
capacity_gb = 1024
126+
name = "share"
127+
}
128+
129+
networks {
130+
network = "default"
131+
modes = ["MODE_IPV4"]
132+
}
133+
}
134+
135+
resource "google_backup_dr_backup_vault" "backup_vault" {
136+
location ="us-central1"
137+
backup_vault_id = "tf-backup-vault-${local.backup_name}"
138+
description = "This is a second backup vault built by Terraform."
139+
backup_minimum_enforced_retention_duration = "100000s"
140+
force_update = "true"
141+
force_delete = "true"
142+
allow_missing = "true"
143+
}
144+
145+
resource "google_backup_dr_backup_plan" "backup_plan" {
146+
location = "us-central1"
147+
backup_plan_id = "tf-backup-plan-${local.backup_name}"
148+
resource_type = "file.googleapis.com/Instance"
149+
backup_vault = google_backup_dr_backup_vault.backup_vault.name
150+
151+
backup_rules {
152+
rule_id = "rule-1"
153+
backup_retention_days = 2
154+
155+
standard_schedule {
156+
recurrence_type = "HOURLY"
157+
hourly_frequency = 6
158+
time_zone = "UTC"
159+
160+
backup_window {
161+
start_hour_of_day = 12
162+
end_hour_of_day = 18
163+
}
164+
}
165+
}
166+
}
167+
168+
resource "google_backup_dr_backup_plan_association" "backcup_association" {
169+
location = "us-central1"
170+
backup_plan_association_id = "tf-backup-plan-association-${local.backup_name}"
171+
resource = google_filestore_instance.source_instance.id
172+
resource_type= "file.googleapis.com/Instance"
173+
backup_plan = google_backup_dr_backup_plan.backup_plan.name
174+
depends_on = [ google_filestore_instance.source_instance ]
175+
}
176+
177+
data "google_backup_dr_data_source_references" "all_refs" {
178+
project = data.google_project.project.project_id
179+
location = "us-central1"
180+
resource_type = "file.googleapis.com/Instance"
181+
depends_on = [google_backup_dr_backup_plan_association.backcup_association]
182+
}
183+
184+
185+
resource "google_filestore_instance" "instance" {
186+
name = "tf-restored-instance-${local.instance_name}"
187+
location = "us-central1"
188+
tier = "REGIONAL"
189+
190+
file_shares {
191+
capacity_gb = 1024
192+
name = "share"
193+
source_backupdr_backup = data.google_backup_dr_data_source_references.all_refs.data_source_references[0].name
194+
}
195+
196+
networks {
197+
network = "default"
198+
modes = ["MODE_IPV4"]
199+
}
200+
201+
depends_on = [data.google_backup_dr_data_source_references.all_refs]
202+
}
203+
`, instanceName, backupName)
204+
}

0 commit comments

Comments
 (0)