Skip to content

Commit fe480e3

Browse files
Add RDB & AOF Persistence support to Memorystore for Redis Cluster (#12219) (#846)
[upstream:a3ffd4e196c5e93a506d53f83464004474bc69f4] Signed-off-by: Modular Magician <[email protected]>
1 parent a9270d3 commit fe480e3

File tree

8 files changed

+329
-0
lines changed

8 files changed

+329
-0
lines changed

redis_cluster_aof/backing_file.tf

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# This file has some scaffolding to make sure that names are unique and that
2+
# a region and zone are selected when you try to create your Terraform resources.
3+
4+
locals {
5+
name_suffix = "${random_pet.suffix.id}"
6+
}
7+
8+
resource "random_pet" "suffix" {
9+
length = 2
10+
}
11+
12+
provider "google" {
13+
region = "us-central1"
14+
zone = "us-central1-c"
15+
}

redis_cluster_aof/main.tf

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
resource "google_redis_cluster" "cluster-aof" {
2+
name = "aof-cluster-${local.name_suffix}"
3+
shard_count = 3
4+
psc_configs {
5+
network = google_compute_network.producer_net.id
6+
}
7+
region = "us-central1"
8+
replica_count = 0
9+
node_type = "REDIS_SHARED_CORE_NANO"
10+
transit_encryption_mode = "TRANSIT_ENCRYPTION_MODE_DISABLED"
11+
authorization_mode = "AUTH_MODE_DISABLED"
12+
redis_configs = {
13+
maxmemory-policy = "volatile-ttl"
14+
}
15+
deletion_protection_enabled = false
16+
17+
zone_distribution_config {
18+
mode = "MULTI_ZONE"
19+
}
20+
maintenance_policy {
21+
weekly_maintenance_window {
22+
day = "MONDAY"
23+
start_time {
24+
hours = 1
25+
minutes = 0
26+
seconds = 0
27+
nanos = 0
28+
}
29+
}
30+
}
31+
persistence_config {
32+
mode = "AOF"
33+
aof_config {
34+
append_fsync = "EVERYSEC"
35+
}
36+
}
37+
depends_on = [
38+
google_network_connectivity_service_connection_policy.default
39+
]
40+
}
41+
42+
resource "google_network_connectivity_service_connection_policy" "default" {
43+
name = "mypolicy-${local.name_suffix}"
44+
location = "us-central1"
45+
service_class = "gcp-memorystore-redis"
46+
description = "my basic service connection policy"
47+
network = google_compute_network.producer_net.id
48+
psc_config {
49+
subnetworks = [google_compute_subnetwork.producer_subnet.id]
50+
}
51+
}
52+
53+
resource "google_compute_subnetwork" "producer_subnet" {
54+
name = "mysubnet-${local.name_suffix}"
55+
ip_cidr_range = "10.0.0.248/29"
56+
region = "us-central1"
57+
network = google_compute_network.producer_net.id
58+
}
59+
60+
resource "google_compute_network" "producer_net" {
61+
name = "mynetwork-${local.name_suffix}"
62+
auto_create_subnetworks = false
63+
}

redis_cluster_aof/motd

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
===
2+
3+
These examples use real resources that will be billed to the
4+
Google Cloud Platform project you use - so make sure that you
5+
run "terraform destroy" before quitting!
6+
7+
===

redis_cluster_aof/tutorial.md

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# Redis Cluster Aof - Terraform
2+
3+
## Setup
4+
5+
<walkthrough-author name="[email protected]" analyticsId="UA-125550242-1" tutorialName="redis_cluster_aof" repositoryUrl="https://github.com/terraform-google-modules/docs-examples"></walkthrough-author>
6+
7+
Welcome to Terraform in Google Cloud Shell! We need you to let us know what project you'd like to use with Terraform.
8+
9+
<walkthrough-project-billing-setup></walkthrough-project-billing-setup>
10+
11+
Terraform provisions real GCP resources, so anything you create in this session will be billed against this project.
12+
13+
## Terraforming!
14+
15+
Let's use {{project-id}} with Terraform! Click the Cloud Shell icon below to copy the command
16+
to your shell, and then run it from the shell by pressing Enter/Return. Terraform will pick up
17+
the project name from the environment variable.
18+
19+
```bash
20+
export GOOGLE_CLOUD_PROJECT={{project-id}}
21+
```
22+
23+
After that, let's get Terraform started. Run the following to pull in the providers.
24+
25+
```bash
26+
terraform init
27+
```
28+
29+
With the providers downloaded and a project set, you're ready to use Terraform. Go ahead!
30+
31+
```bash
32+
terraform apply
33+
```
34+
35+
Terraform will show you what it plans to do, and prompt you to accept. Type "yes" to accept the plan.
36+
37+
```bash
38+
yes
39+
```
40+
41+
42+
## Post-Apply
43+
44+
### Editing your config
45+
46+
Now you've provisioned your resources in GCP! If you run a "plan", you should see no changes needed.
47+
48+
```bash
49+
terraform plan
50+
```
51+
52+
So let's make a change! Try editing a number, or appending a value to the name in the editor. Then,
53+
run a 'plan' again.
54+
55+
```bash
56+
terraform plan
57+
```
58+
59+
Afterwards you can run an apply, which implicitly does a plan and shows you the intended changes
60+
at the 'yes' prompt.
61+
62+
```bash
63+
terraform apply
64+
```
65+
66+
```bash
67+
yes
68+
```
69+
70+
## Cleanup
71+
72+
Run the following to remove the resources Terraform provisioned:
73+
74+
```bash
75+
terraform destroy
76+
```
77+
```bash
78+
yes
79+
```

redis_cluster_rdb/backing_file.tf

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# This file has some scaffolding to make sure that names are unique and that
2+
# a region and zone are selected when you try to create your Terraform resources.
3+
4+
locals {
5+
name_suffix = "${random_pet.suffix.id}"
6+
}
7+
8+
resource "random_pet" "suffix" {
9+
length = 2
10+
}
11+
12+
provider "google" {
13+
region = "us-central1"
14+
zone = "us-central1-c"
15+
}

redis_cluster_rdb/main.tf

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
resource "google_redis_cluster" "cluster-rdb" {
2+
name = "rdb-cluster-${local.name_suffix}"
3+
shard_count = 3
4+
psc_configs {
5+
network = google_compute_network.producer_net.id
6+
}
7+
region = "us-central1"
8+
replica_count = 0
9+
node_type = "REDIS_SHARED_CORE_NANO"
10+
transit_encryption_mode = "TRANSIT_ENCRYPTION_MODE_DISABLED"
11+
authorization_mode = "AUTH_MODE_DISABLED"
12+
redis_configs = {
13+
maxmemory-policy = "volatile-ttl"
14+
}
15+
deletion_protection_enabled = false
16+
17+
zone_distribution_config {
18+
mode = "MULTI_ZONE"
19+
}
20+
maintenance_policy {
21+
weekly_maintenance_window {
22+
day = "MONDAY"
23+
start_time {
24+
hours = 1
25+
minutes = 0
26+
seconds = 0
27+
nanos = 0
28+
}
29+
}
30+
}
31+
persistence_config {
32+
mode = "RDB"
33+
rdb_config {
34+
rdb_snapshot_period = "ONE_HOUR"
35+
rdb_snapshot_start_time = "2024-10-02T15:01:23Z"
36+
}
37+
}
38+
depends_on = [
39+
google_network_connectivity_service_connection_policy.default
40+
]
41+
}
42+
43+
resource "google_network_connectivity_service_connection_policy" "default" {
44+
name = "mypolicy-${local.name_suffix}"
45+
location = "us-central1"
46+
service_class = "gcp-memorystore-redis"
47+
description = "my basic service connection policy"
48+
network = google_compute_network.producer_net.id
49+
psc_config {
50+
subnetworks = [google_compute_subnetwork.producer_subnet.id]
51+
}
52+
}
53+
54+
resource "google_compute_subnetwork" "producer_subnet" {
55+
name = "mysubnet-${local.name_suffix}"
56+
ip_cidr_range = "10.0.0.248/29"
57+
region = "us-central1"
58+
network = google_compute_network.producer_net.id
59+
}
60+
61+
resource "google_compute_network" "producer_net" {
62+
name = "mynetwork-${local.name_suffix}"
63+
auto_create_subnetworks = false
64+
}

redis_cluster_rdb/motd

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
===
2+
3+
These examples use real resources that will be billed to the
4+
Google Cloud Platform project you use - so make sure that you
5+
run "terraform destroy" before quitting!
6+
7+
===

redis_cluster_rdb/tutorial.md

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# Redis Cluster Rdb - Terraform
2+
3+
## Setup
4+
5+
<walkthrough-author name="[email protected]" analyticsId="UA-125550242-1" tutorialName="redis_cluster_rdb" repositoryUrl="https://github.com/terraform-google-modules/docs-examples"></walkthrough-author>
6+
7+
Welcome to Terraform in Google Cloud Shell! We need you to let us know what project you'd like to use with Terraform.
8+
9+
<walkthrough-project-billing-setup></walkthrough-project-billing-setup>
10+
11+
Terraform provisions real GCP resources, so anything you create in this session will be billed against this project.
12+
13+
## Terraforming!
14+
15+
Let's use {{project-id}} with Terraform! Click the Cloud Shell icon below to copy the command
16+
to your shell, and then run it from the shell by pressing Enter/Return. Terraform will pick up
17+
the project name from the environment variable.
18+
19+
```bash
20+
export GOOGLE_CLOUD_PROJECT={{project-id}}
21+
```
22+
23+
After that, let's get Terraform started. Run the following to pull in the providers.
24+
25+
```bash
26+
terraform init
27+
```
28+
29+
With the providers downloaded and a project set, you're ready to use Terraform. Go ahead!
30+
31+
```bash
32+
terraform apply
33+
```
34+
35+
Terraform will show you what it plans to do, and prompt you to accept. Type "yes" to accept the plan.
36+
37+
```bash
38+
yes
39+
```
40+
41+
42+
## Post-Apply
43+
44+
### Editing your config
45+
46+
Now you've provisioned your resources in GCP! If you run a "plan", you should see no changes needed.
47+
48+
```bash
49+
terraform plan
50+
```
51+
52+
So let's make a change! Try editing a number, or appending a value to the name in the editor. Then,
53+
run a 'plan' again.
54+
55+
```bash
56+
terraform plan
57+
```
58+
59+
Afterwards you can run an apply, which implicitly does a plan and shows you the intended changes
60+
at the 'yes' prompt.
61+
62+
```bash
63+
terraform apply
64+
```
65+
66+
```bash
67+
yes
68+
```
69+
70+
## Cleanup
71+
72+
Run the following to remove the resources Terraform provisioned:
73+
74+
```bash
75+
terraform destroy
76+
```
77+
```bash
78+
yes
79+
```

0 commit comments

Comments
 (0)