Skip to content

Commit c57afd8

Browse files
niharika-98apeabodyglasnt
authored
feat(terraform): add BV, BP, BPA resources to sample configurations (#761)
* Adding BV,BP,BPA resources to terraform samples --------- Co-authored-by: Andrew Peabody <[email protected]> Co-authored-by: Katie McLaughlin <[email protected]>
1 parent 4361a53 commit c57afd8

File tree

5 files changed

+218
-0
lines changed

5 files changed

+218
-0
lines changed

.github/CODEOWNERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,4 @@
2222
/traffic_director/ @terraform-google-modules/dee-infra @terraform-google-modules/terraform-samples-reviewers
2323
/vpc/ @terraform-google-modules/dee-infra @terraform-google-modules/terraform-samples-reviewers
2424
/managedkafka/ @terraform-google-modules/managedkafka-dev-team @terraform-google-modules/terraform-samples-reviewers
25+
/backupdr/ @terraform-google-modules/gcbdr-samples-team @terraform-google-modules/terraform-samples-reviewers

backupdr/backup_plan/main.tf

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/**
2+
* Copyright 2024 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
# [START backupdr_create_backupvault]
17+
18+
resource "google_backup_dr_backup_vault" "default" {
19+
provider = google-beta
20+
location = "us-central1"
21+
backup_vault_id = "my-vault"
22+
description = "This is a second backup vault built by Terraform."
23+
backup_minimum_enforced_retention_duration = "100000s"
24+
25+
labels = {
26+
foo = "bar1"
27+
bar = "baz1"
28+
}
29+
30+
annotations = {
31+
annotations1 = "bar1"
32+
annotations2 = "baz1"
33+
}
34+
35+
force_update = "true"
36+
force_delete = "true"
37+
allow_missing = "true"
38+
}
39+
40+
# [END backupdr_create_backupvault]
41+
42+
# [START backupdr_create_backupplan]
43+
44+
# Before creating a backup plan, you need to create backup vault (google_backup_dr_backup_vault).
45+
resource "google_backup_dr_backup_plan" "default" {
46+
provider = google-beta
47+
location = "us-central1"
48+
backup_plan_id = "my-bp"
49+
resource_type = "compute.googleapis.com/Instance"
50+
backup_vault = google_backup_dr_backup_vault.default.name
51+
52+
backup_rules {
53+
rule_id = "rule-1"
54+
backup_retention_days = 5
55+
56+
standard_schedule {
57+
recurrence_type = "HOURLY"
58+
hourly_frequency = 6
59+
time_zone = "UTC"
60+
61+
backup_window {
62+
start_hour_of_day = 0
63+
end_hour_of_day = 24
64+
}
65+
}
66+
}
67+
}
68+
69+
# [END backupdr_create_backupplan]
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
/**
2+
* Copyright 2024 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
resource "google_service_account" "default" {
18+
provider = google-beta
19+
account_id = "my-sa"
20+
display_name = "Custom SA for VM Instance"
21+
}
22+
23+
resource "google_compute_instance" "default" {
24+
provider = google-beta
25+
name = "my-instance"
26+
machine_type = "n2-standard-2"
27+
zone = "us-central1-a"
28+
tags = ["foo", "bar"]
29+
30+
boot_disk {
31+
initialize_params {
32+
image = "debian-cloud/debian-11"
33+
labels = {
34+
my_label = "value"
35+
}
36+
}
37+
}
38+
39+
// Local SSD disk
40+
scratch_disk {
41+
interface = "NVME"
42+
}
43+
44+
network_interface {
45+
network = "default"
46+
access_config {
47+
// Ephemeral public IP
48+
}
49+
}
50+
51+
service_account {
52+
# Google recommends custom service accounts that have cloud-platform scope and permissions granted via IAM Roles.
53+
email = google_service_account.default.email
54+
scopes = ["cloud-platform"]
55+
}
56+
}
57+
58+
resource "google_backup_dr_backup_vault" "default" {
59+
provider = google-beta
60+
location = "us-central1"
61+
backup_vault_id = "my-vault"
62+
description = "This is a second backup vault built by Terraform."
63+
backup_minimum_enforced_retention_duration = "100000s"
64+
65+
labels = {
66+
foo = "bar1"
67+
bar = "baz1"
68+
}
69+
70+
annotations = {
71+
annotations1 = "bar1"
72+
annotations2 = "baz1"
73+
}
74+
75+
force_update = "true"
76+
force_delete = "true"
77+
allow_missing = "true"
78+
}
79+
80+
resource "google_backup_dr_backup_plan" "default" {
81+
provider = google-beta
82+
location = "us-central1"
83+
backup_plan_id = "my-bp"
84+
resource_type = "compute.googleapis.com/Instance"
85+
backup_vault = google_backup_dr_backup_vault.default.name
86+
87+
backup_rules {
88+
rule_id = "rule-1"
89+
backup_retention_days = 2
90+
91+
standard_schedule {
92+
recurrence_type = "HOURLY"
93+
hourly_frequency = 6
94+
time_zone = "UTC"
95+
96+
backup_window {
97+
start_hour_of_day = 12
98+
end_hour_of_day = 18
99+
}
100+
}
101+
}
102+
}
103+
104+
# [START backupdr_create_backupplanassociation]
105+
106+
# Before creating a backup plan association, you need to create backup plan (google_backup_dr_backup_plan)
107+
# and compute instance (google_compute_instance).
108+
resource "google_backup_dr_backup_plan_association" "default" {
109+
provider = google-beta
110+
location = "us-central1"
111+
backup_plan_association_id = "my-bpa"
112+
resource = google_compute_instance.default.id
113+
resource_type = "compute.googleapis.com/Instance"
114+
backup_plan = google_backup_dr_backup_plan.default.name
115+
}
116+
117+
# [END backupdr_create_backupplanassociation]

backupdr/backup_vault/main.tf

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/**
2+
* Copyright 2024 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
# [START backupdr_create_backupvault]
18+
19+
resource "google_backup_dr_backup_vault" "default" {
20+
provider = google-beta
21+
location = "us-central1"
22+
backup_vault_id = "my-vault"
23+
description = "This vault is created usingTerraform."
24+
backup_minimum_enforced_retention_duration = "100000s"
25+
force_update = "true"
26+
force_delete = "true"
27+
allow_missing = "true"
28+
}
29+
30+
# [END backupdr_create_backupvault]

test/setup/main.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ module "projects" {
4242
"anthos.googleapis.com",
4343
"anthospolicycontroller.googleapis.com",
4444
"artifactregistry.googleapis.com",
45+
"backupdr.googleapis.com",
4546
"biglake.googleapis.com",
4647
"bigquery.googleapis.com",
4748
"bigqueryconnection.googleapis.com",

0 commit comments

Comments
 (0)