Skip to content

Commit 0165cb5

Browse files
committed
Merge remote-tracking branch 'origin/promote-gmk' into promote-gmk
2 parents f2f4405 + fc5e45b commit 0165cb5

File tree

24 files changed

+468
-44
lines changed

24 files changed

+468
-44
lines changed

.github/.keep

Whitespace-only changes.

.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: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
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+
account_id = "my-serviceaccount"
19+
display_name = "Custom SA for VM Instance"
20+
}
21+
22+
resource "google_compute_instance" "default" {
23+
name = "my-instance"
24+
machine_type = "n2-standard-2"
25+
zone = "us-central1-a"
26+
tags = ["foo", "bar"]
27+
28+
boot_disk {
29+
initialize_params {
30+
image = "debian-cloud/debian-11"
31+
labels = {
32+
my_label = "value"
33+
}
34+
}
35+
}
36+
37+
// Local SSD disk
38+
scratch_disk {
39+
interface = "NVME"
40+
}
41+
42+
network_interface {
43+
network = "default"
44+
access_config {
45+
// Ephemeral public IP
46+
}
47+
}
48+
49+
service_account {
50+
# Google recommends custom service accounts that have cloud-platform scope and permissions granted via IAM Roles.
51+
email = google_service_account.default.email
52+
scopes = ["cloud-platform"]
53+
}
54+
}
55+
56+
resource "google_backup_dr_backup_vault" "default" {
57+
provider = google-beta
58+
location = "us-central1"
59+
backup_vault_id = "my-vault"
60+
description = "This is a second backup vault built by Terraform."
61+
backup_minimum_enforced_retention_duration = "100000s"
62+
63+
labels = {
64+
foo = "bar1"
65+
bar = "baz1"
66+
}
67+
68+
annotations = {
69+
annotations1 = "bar1"
70+
annotations2 = "baz1"
71+
}
72+
73+
force_update = "true"
74+
force_delete = "true"
75+
allow_missing = "true"
76+
}
77+
78+
resource "google_backup_dr_backup_plan" "default" {
79+
provider = google-beta
80+
location = "us-central1"
81+
backup_plan_id = "my-bp"
82+
resource_type = "compute.googleapis.com/Instance"
83+
backup_vault = google_backup_dr_backup_vault.default.name
84+
85+
backup_rules {
86+
rule_id = "rule-1"
87+
backup_retention_days = 2
88+
89+
standard_schedule {
90+
recurrence_type = "HOURLY"
91+
hourly_frequency = 6
92+
time_zone = "UTC"
93+
94+
backup_window {
95+
start_hour_of_day = 12
96+
end_hour_of_day = 18
97+
}
98+
}
99+
}
100+
}
101+
102+
# [START backupdr_create_backupplanassociation]
103+
104+
# Before creating a backup plan association, you need to create backup plan (google_backup_dr_backup_plan)
105+
# and compute instance (google_compute_instance).
106+
resource "google_backup_dr_backup_plan_association" "default" {
107+
provider = google-beta
108+
location = "us-central1"
109+
backup_plan_association_id = "my-bpa"
110+
resource = google_compute_instance.default.id
111+
resource_type = "compute.googleapis.com/Instance"
112+
backup_plan = google_backup_dr_backup_plan.default.name
113+
}
114+
115+
# [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]

build/int.cloudbuild.yaml

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,27 +28,33 @@ steps:
2828
fi
2929
3030
git fetch --unshallow
31-
git diff origin/${_BASE_BRANCH} --name-only > _changed_files
32-
sed 's/\/.*/\//' _changed_files > _changed_folders
31+
git diff origin/main --name-only > _changed_files
32+
sed 's:[^/]*$::' _changed_files > _changed_folders
33+
sort -u -o _changed_folders{,}
34+
echo Folders with changes:
35+
cat _changed_folders
3336
3437
# Do not prune if changing tests themselves
35-
_INFRA_FOLDERS="build test .github"
36-
for d in _changed_folders; do
37-
if [[ "${_INFRA_FOLDERS}" =~ "$d" ]]; then
38-
echo "Infrastructure folders have changed; no tests will be pruned."
38+
while read d; do
39+
if [[ "build test .github" =~ "${d%/}" ]]; then
40+
echo "Infrastructure folder ${d%/} has changed; no tests will be pruned."
3941
exit 0 # do not prune
4042
fi
41-
done
43+
done < _changed_folders
4244
43-
for d in */; do
44-
if ! grep -q "^$d" _changed_folders && [[ "$d" != "test/" ]]; then
45-
rm -rf $d;
45+
# Remove leaf folders without changes or non-tf resources
46+
for d in `find . -type d -name 'test' -prune -o -links 2 -printf '%P\n'`; do
47+
if ! grep -q "^$d" _changed_folders && ! [ -n "$(find $d -maxdepth 1 -not -name '*.tf' -type f -print -quit)" ]; then
48+
rm -rf $d
4649
fi
4750
done
4851
52+
# Remove any empty folders
53+
find . -empty -type d -delete
54+
4955
# Report remaining folders
5056
echo Folders in scope for tests:
51-
for d in */; do echo $d; done
57+
find . -type d -printf '%P\n'
5258
5359
- id: prepare
5460
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'

composer/.keep

Whitespace-only changes.

compute/.keep

Whitespace-only changes.
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
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+
/**
18+
* Made to resemble:
19+
* gcloud alpha compute instance-groups managed create flex-igm --project=$PROJECT --region=us-central1 \
20+
* --target-distribution-shape=any-single-zone --instance-redistribution-type NONE \
21+
* --template example-template --size 3 \
22+
* --instance-selection "rank=1,name=best-choice,machine-type=n1-standard-1,n1-standard-2" \
23+
* --instance-selection "rank=2,name=still-ok,machine-type=n2-standard-1" \
24+
* --instance-selection "rank=3,name=if-nothing-else,machine-type=e2-standard-2"
25+
*/
26+
27+
28+
terraform {
29+
required_providers {
30+
google = {
31+
source = "hashicorp/google-beta"
32+
version = ">= 6.12.0"
33+
}
34+
}
35+
}
36+
37+
# [START compute_region_igm_instance_flexibility_policy_parent_tag]
38+
resource "google_compute_instance_template" "default" {
39+
name = "example-template"
40+
machine_type = "e2-medium"
41+
disk {
42+
source_image = "debian-cloud/debian-11"
43+
}
44+
network_interface {
45+
network = "default"
46+
}
47+
}
48+
49+
# [START compute_region_igm_instance_flexibility_policy]
50+
resource "google_compute_region_instance_group_manager" "default" {
51+
name = "flex-igm"
52+
base_instance_name = "tf-test-flex-igm"
53+
region = "us-central1"
54+
55+
target_size = 3
56+
distribution_policy_target_shape = "ANY_SINGLE_ZONE"
57+
58+
version {
59+
instance_template = google_compute_instance_template.default.id
60+
}
61+
62+
instance_flexibility_policy {
63+
instance_selections {
64+
name = "best-choice"
65+
rank = 1
66+
machine_types = ["n1-standard-1", "n1-standard-2"]
67+
}
68+
instance_selections {
69+
name = "still-ok"
70+
rank = 2
71+
machine_types = ["n2-standard-1"]
72+
}
73+
instance_selections {
74+
name = "if-nothing-else"
75+
rank = 3
76+
machine_types = ["e2-standard-2"]
77+
}
78+
}
79+
80+
update_policy {
81+
instance_redistribution_type = "NONE"
82+
type = "OPPORTUNISTIC"
83+
minimal_action = "REPLACE"
84+
max_surge_fixed = 0
85+
max_unavailable_fixed = 6
86+
}
87+
}
88+
# [END compute_region_igm_instance_flexibility_policy]
89+
# [END compute_region_igm_instance_flexibility_policy_parent_tag]

dns/.keep

Whitespace-only changes.

0 commit comments

Comments
 (0)