Skip to content

Commit e169437

Browse files
authored
Added backupvault resource to Terraform backupdr product (beta) (#11317)
1 parent f0933ec commit e169437

File tree

4 files changed

+260
-1
lines changed

4 files changed

+260
-1
lines changed
+143
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
--- !ruby/object:Api::Resource
2+
base_url: projects/{{project}}/locations/{{location}}/backupVaults
3+
create_url: projects/{{project}}/locations/{{location}}/backupVaults?backupVaultId={{backup_vault_id}}
4+
update_url: projects/{{project}}/locations/{{location}}/backupVaults/{{backup_vault_id}}?force={{force_update}}
5+
delete_url: projects/{{project}}/locations/{{location}}/backupVaults/{{backup_vault_id}}?force={{force_delete}}&allowMissing={{allow_missing}}
6+
self_link: projects/{{project}}/locations/{{location}}/backupVaults/{{backup_vault_id}}
7+
id_format: projects/{{project}}/locations/{{location}}/backupVaults/{{backup_vault_id}}
8+
import_format:
9+
- projects/{{project}}/locations/{{location}}/backupVaults/{{backup_vault_id}}
10+
name: BackupVault
11+
description: Container to store and organize immutable and indelible backups.
12+
autogen_async: true
13+
examples:
14+
- !ruby/object:Provider::Terraform::Examples
15+
min_version: beta
16+
name: 'backup_dr_backup_vault_full'
17+
primary_resource_id: 'backup-vault-test'
18+
vars:
19+
backup_vault_id: 'backup-vault-test'
20+
test_env_vars:
21+
project: :PROJECT_NAME
22+
properties:
23+
- !ruby/object:Api::Type::String
24+
name: name
25+
description: 'Output only. Identifier. The resource name. '
26+
output: true
27+
- !ruby/object:Api::Type::String
28+
name: description
29+
description: 'Optional. The description of the BackupVault instance (2048 characters
30+
or less). '
31+
- !ruby/object:Api::Type::KeyValueLabels
32+
name: labels
33+
description: "Optional. Resource labels to represent user provided metadata. "
34+
- !ruby/object:Api::Type::String
35+
name: createTime
36+
description: 'Output only. The time when the instance was created. '
37+
output: true
38+
- !ruby/object:Api::Type::String
39+
name: updateTime
40+
description: 'Output only. The time when the instance was updated. '
41+
output: true
42+
- !ruby/object:Api::Type::String
43+
name: backupMinimumEnforcedRetentionDuration
44+
description: "Required. The default and minimum enforced retention for each backup
45+
within the backup vault. The enforced retention for each backup can be extended. "
46+
required: true
47+
- !ruby/object:Api::Type::Boolean
48+
name: deletable
49+
description: 'Output only. Set to true when there are no backups nested under this
50+
resource. '
51+
output: true
52+
- !ruby/object:Api::Type::String
53+
name: etag
54+
output: true
55+
description: "Optional. Server specified ETag for the backup vault resource to prevent
56+
simultaneous updates from overwiting each other. "
57+
- !ruby/object:Api::Type::String
58+
name: state
59+
description: "Output only. The BackupVault resource instance state. \n Possible
60+
values:\n STATE_UNSPECIFIED\n CREATING\n ACTIVE\n DELETING\n ERROR"
61+
output: true
62+
- !ruby/object:Api::Type::String
63+
name: effectiveTime
64+
description: 'Optional. Time after which the BackupVault resource is locked. '
65+
- !ruby/object:Api::Type::String
66+
name: backupCount
67+
description: 'Output only. The number of backups in this backup vault. '
68+
output: true
69+
- !ruby/object:Api::Type::String
70+
name: serviceAccount
71+
description: "Output only. Service account used by the BackupVault Service for this
72+
BackupVault. The user should grant this account permissions in their workload
73+
project to enable the service to run backups and restores there. "
74+
output: true
75+
- !ruby/object:Api::Type::String
76+
name: totalStoredBytes
77+
description: 'Output only. Total size of the storage used by all backup resources. '
78+
output: true
79+
- !ruby/object:Api::Type::String
80+
name: uid
81+
description: "Output only. Output only Immutable after resource creation until
82+
resource deletion. "
83+
output: true
84+
- !ruby/object:Api::Type::KeyValueAnnotations
85+
name: annotations
86+
description: "Optional. User annotations. See https://google.aip.dev/128#annotations\nStores
87+
small amounts of arbitrary data. "
88+
parameters:
89+
- !ruby/object:Api::Type::String
90+
name: location
91+
description: "The GCP location for the backup vault. "
92+
url_param_only: true
93+
required: true
94+
immutable: true
95+
- !ruby/object:Api::Type::String
96+
name: backupVaultId
97+
description: "Required. ID of the requesting object."
98+
url_param_only: true
99+
required: true
100+
immutable: true
101+
- !ruby/object:Api::Type::Boolean
102+
name: 'force_update'
103+
default_value: false
104+
url_param_only: true
105+
description: |
106+
If set, allow update to extend the minimum enforced retention for backup vault. This overrides
107+
the restriction against conflicting retention periods. This conflict may occur when the
108+
expiration schedule defined by the associated backup plan is shorter than the minimum
109+
retention set by the backup vault.
110+
- !ruby/object:Api::Type::Boolean
111+
name: 'force_delete'
112+
default_value: false
113+
url_param_only: true
114+
description: |
115+
If set, the following restrictions against deletion of the backup vault instance can be overridden:
116+
* deletion of a backup vault instance containing no backups, but still containing empty datasources.
117+
* deletion of a backup vault instance that is being referenced by an active backup plan.
118+
- !ruby/object:Api::Type::Boolean
119+
name: 'allow_missing'
120+
default_value: false
121+
url_param_only: true
122+
description: |
123+
Allow idempotent deletion of backup vault. The request will still succeed in case the backup vault does not exist.
124+
async: !ruby/object:Api::OpAsync
125+
operation: !ruby/object:Api::OpAsync::Operation
126+
path: name
127+
base_url: "{{op_id}}"
128+
wait_ms: 1000
129+
timeouts:
130+
result: !ruby/object:Api::OpAsync::Result
131+
path: response
132+
resource_inside_response: true
133+
status: !ruby/object:Api::OpAsync::Status
134+
path: done
135+
complete: true
136+
allowed:
137+
- true
138+
- false
139+
error: !ruby/object:Api::OpAsync::Error
140+
path: error
141+
message: message
142+
update_verb: :PATCH
143+
update_mask: true

mmv1/products/backupdr/product.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
--- !ruby/object:Api::Product
1515
name: BackupDR
16-
display_name: Backup and DR
16+
display_name: Backup and DR Service
1717
scopes:
1818
- https://www.googleapis.com/auth/cloud-platform
1919
versions:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
resource "google_backup_dr_backup_vault" "<%= ctx[:primary_resource_id] %>" {
2+
provider = google-beta
3+
location = "us-central1"
4+
backup_vault_id = "<%= ctx[:vars]['backup_vault_id'] %>"
5+
description = "This is a second backup vault built by Terraform."
6+
backup_minimum_enforced_retention_duration = "100000s"
7+
labels = {
8+
foo = "bar1"
9+
bar = "baz1"
10+
}
11+
annotations = {
12+
annotations1 = "bar1"
13+
annotations2 = "baz1"
14+
}
15+
force_update = "true"
16+
force_delete = "true"
17+
allow_missing = "true"
18+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
<% autogen_exception -%>
2+
package backupdr_test
3+
<% unless version == 'ga' -%>
4+
5+
import (
6+
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
7+
"github.com/hashicorp/terraform-provider-google/google/acctest"
8+
"github.com/hashicorp/terraform-provider-google/google/envvar"
9+
"testing"
10+
"time"
11+
)
12+
13+
func TestAccBackupDRBackupVault_fullUpdate(t *testing.T) {
14+
t.Parallel()
15+
16+
timeNow := time.Now().UTC()
17+
referenceTime := time.Date(timeNow.Year(), timeNow.Month(), timeNow.Day(), 0, 0, 0, 0, time.UTC)
18+
19+
context := map[string]interface{}{
20+
"project": envvar.GetTestProjectFromEnv(),
21+
"effective_time": referenceTime.Add(24 * time.Hour).Format(time.RFC3339),
22+
"random_suffix": acctest.RandString(t, 10),
23+
}
24+
25+
acctest.VcrTest(t, resource.TestCase{
26+
PreCheck: func() { acctest.AccTestPreCheck(t) },
27+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderBetaFactories(t),
28+
Steps: []resource.TestStep{
29+
{
30+
Config: testAccBackupDRBackupVault_fullCreate(context),
31+
},
32+
{
33+
ResourceName: "google_backup_dr_backup_vault.backup-vault-test",
34+
ImportState: true,
35+
ImportStateVerify: true,
36+
ImportStateVerifyIgnore: []string{"allow_missing", "annotations", "backup_vault_id", "force_delete", "force_update", "labels", "location", "terraform_labels"},
37+
},
38+
{
39+
Config: testAccBackupDRBackupVault_fullUpdate(context),
40+
},
41+
{
42+
ResourceName: "google_backup_dr_backup_vault.backup-vault-test",
43+
ImportState: true,
44+
ImportStateVerify: true,
45+
ImportStateVerifyIgnore: []string{"allow_missing", "annotations", "backup_vault_id", "force_delete", "force_update", "labels", "location", "terraform_labels"},
46+
},
47+
},
48+
})
49+
}
50+
51+
func testAccBackupDRBackupVault_fullCreate(context map[string]interface{}) string {
52+
return acctest.Nprintf(`
53+
resource "google_backup_dr_backup_vault" "backup-vault-test" {
54+
provider = google-beta
55+
location = "us-central1"
56+
backup_vault_id = "tf-test-backup-vault-test%{random_suffix}"
57+
description = "This is a backup vault built by Terraform."
58+
backup_minimum_enforced_retention_duration = "100000s"
59+
effective_time = "%{effective_time}"
60+
labels = {
61+
foo = "bar"
62+
bar = "baz"
63+
}
64+
annotations = {
65+
annotations1 = "bar"
66+
annotations2 = "baz"
67+
}
68+
force_update = "true"
69+
force_delete = "true"
70+
allow_missing = "true"
71+
}
72+
`, context)
73+
}
74+
75+
func testAccBackupDRBackupVault_fullUpdate(context map[string]interface{}) string {
76+
return acctest.Nprintf(`
77+
resource "google_backup_dr_backup_vault" "backup-vault-test" {
78+
provider = google-beta
79+
location = "us-central1"
80+
backup_vault_id = "tf-test-backup-vault-test%{random_suffix}"
81+
description = "This is a second backup vault built by Terraform."
82+
backup_minimum_enforced_retention_duration = "200000s"
83+
effective_time = "%{effective_time}"
84+
labels = {
85+
foo = "bar1"
86+
bar = "baz1"
87+
}
88+
annotations = {
89+
annotations1 = "bar1"
90+
annotations2 = "baz1"
91+
}
92+
force_update = "true"
93+
force_delete = "true"
94+
allow_missing = "true"
95+
}
96+
`, context)
97+
}
98+
<% end -%>

0 commit comments

Comments
 (0)