Skip to content

Commit 794784c

Browse files
Memorystore Valkey Multi vpc support (#13355) (#948)
[upstream:a89d9534c8d63aad647030a54bc7fd62dd5935bd] Signed-off-by: Modular Magician <[email protected]>
1 parent 4adf65c commit 794784c

File tree

8 files changed

+460
-0
lines changed

8 files changed

+460
-0
lines changed
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+
}
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
resource "google_memorystore_instance_desired_user_created_endpoints" "instance-user-auto-conn" {
2+
name = "instance-user-auto-conn-${local.name_suffix}"
3+
region = "us-central1"
4+
desired_user_created_endpoints {
5+
connections {
6+
psc_connection {
7+
psc_connection_id = google_compute_forwarding_rule.forwarding_rule1_network2.psc_connection_id
8+
ip_address = google_compute_address.ip1_network2.address
9+
forwarding_rule = google_compute_forwarding_rule.forwarding_rule1_network2.id
10+
network = google_compute_network.network2.id
11+
service_attachment = google_memorystore_instance.instance-user-auto-conn.psc_attachment_details[0].service_attachment
12+
}
13+
}
14+
connections {
15+
psc_connection {
16+
psc_connection_id = google_compute_forwarding_rule.forwarding_rule2_network2.psc_connection_id
17+
ip_address = google_compute_address.ip2_network2.address
18+
forwarding_rule = google_compute_forwarding_rule.forwarding_rule2_network2.id
19+
network = google_compute_network.network2.id
20+
service_attachment = google_memorystore_instance.instance-user-auto-conn.psc_attachment_details[1].service_attachment
21+
}
22+
}
23+
}
24+
}
25+
26+
resource "google_compute_forwarding_rule" "forwarding_rule1_network2" {
27+
name = "fwd1-net2-${local.name_suffix}"
28+
region = "us-central1"
29+
ip_address = google_compute_address.ip1_network2.id
30+
load_balancing_scheme = ""
31+
network = google_compute_network.network2.id
32+
target = google_memorystore_instance.instance-user-auto-conn.psc_attachment_details[0].service_attachment
33+
}
34+
35+
resource "google_compute_forwarding_rule" "forwarding_rule2_network2" {
36+
name = "fwd2-net2-${local.name_suffix}"
37+
region = "us-central1"
38+
ip_address = google_compute_address.ip2_network2.id
39+
load_balancing_scheme = ""
40+
network = google_compute_network.network2.id
41+
target = google_memorystore_instance.instance-user-auto-conn.psc_attachment_details[1].service_attachment
42+
}
43+
44+
resource "google_compute_address" "ip1_network2" {
45+
name = "ip1-net2-${local.name_suffix}"
46+
region = "us-central1"
47+
subnetwork = google_compute_subnetwork.subnet_network2.id
48+
address_type = "INTERNAL"
49+
purpose = "GCE_ENDPOINT"
50+
}
51+
52+
resource "google_compute_address" "ip2_network2" {
53+
name = "ip2-net2-${local.name_suffix}"
54+
region = "us-central1"
55+
subnetwork = google_compute_subnetwork.subnet_network2.id
56+
address_type = "INTERNAL"
57+
purpose = "GCE_ENDPOINT"
58+
}
59+
60+
resource "google_compute_subnetwork" "subnet_network2" {
61+
name = "subnet-net2-${local.name_suffix}"
62+
ip_cidr_range = "10.0.0.248/29"
63+
region = "us-central1"
64+
network = google_compute_network.network2.id
65+
}
66+
67+
resource "google_compute_network" "network2" {
68+
name = "network2-${local.name_suffix}"
69+
auto_create_subnetworks = false
70+
}
71+
72+
//valkey instance with endpoints
73+
resource "google_memorystore_instance" "instance-user-auto-conn" {
74+
instance_id = "instance-user-auto-conn-${local.name_suffix}"
75+
shard_count = 1
76+
desired_psc_auto_connections {
77+
network = google_compute_network.network1.id
78+
project_id = data.google_project.project.project_id
79+
}
80+
location = "us-central1"
81+
deletion_protection_enabled = false
82+
depends_on = [google_network_connectivity_service_connection_policy.default]
83+
84+
}
85+
86+
resource "google_network_connectivity_service_connection_policy" "default" {
87+
name = "scpolicy-${local.name_suffix}"
88+
location = "us-central1"
89+
service_class = "gcp-memorystore"
90+
description = "my basic service connection policy"
91+
network = google_compute_network.network1.id
92+
psc_config {
93+
subnetworks = [google_compute_subnetwork.subnet_network1.id]
94+
}
95+
}
96+
97+
resource "google_compute_subnetwork" "subnet_network1" {
98+
name = "subnet-net1-${local.name_suffix}"
99+
ip_cidr_range = "10.0.0.248/29"
100+
region = "us-central1"
101+
network = google_compute_network.network1.id
102+
}
103+
104+
resource "google_compute_network" "network1" {
105+
name = "net1-${local.name_suffix}"
106+
auto_create_subnetworks = false
107+
}
108+
109+
data "google_project" "project" {
110+
}
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+
===
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# Memorystore Instance Desired User And Auto Created Endpoints - Terraform
2+
3+
## Setup
4+
5+
<walkthrough-author name="[email protected]" analyticsId="UA-125550242-1" tutorialName="memorystore_instance_desired_user_and_auto_created_endpoints" 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+
```
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+
}
Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
resource "google_memorystore_instance_desired_user_created_endpoints" "instance-user-conn" {
2+
name = "instance-user-conn-${local.name_suffix}"
3+
region = "us-central1"
4+
desired_user_created_endpoints {
5+
connections {
6+
psc_connection {
7+
psc_connection_id = google_compute_forwarding_rule.forwarding_rule1_network1.psc_connection_id
8+
ip_address = google_compute_address.ip1_network1.address
9+
forwarding_rule = google_compute_forwarding_rule.forwarding_rule1_network1.id
10+
network = google_compute_network.network1.id
11+
service_attachment = google_memorystore_instance.instance-user-conn.psc_attachment_details[0].service_attachment
12+
}
13+
}
14+
connections {
15+
psc_connection {
16+
psc_connection_id = google_compute_forwarding_rule.forwarding_rule2_network1.psc_connection_id
17+
ip_address = google_compute_address.ip2_network1.address
18+
forwarding_rule = google_compute_forwarding_rule.forwarding_rule2_network1.id
19+
network = google_compute_network.network1.id
20+
service_attachment = google_memorystore_instance.instance-user-conn.psc_attachment_details[1].service_attachment
21+
}
22+
}
23+
}
24+
desired_user_created_endpoints {
25+
connections {
26+
psc_connection {
27+
psc_connection_id = google_compute_forwarding_rule.forwarding_rule1_network2.psc_connection_id
28+
ip_address = google_compute_address.ip1_network2.address
29+
forwarding_rule = google_compute_forwarding_rule.forwarding_rule1_network2.id
30+
network = google_compute_network.network2.id
31+
service_attachment = google_memorystore_instance.instance-user-conn.psc_attachment_details[0].service_attachment
32+
}
33+
}
34+
connections {
35+
psc_connection {
36+
psc_connection_id = google_compute_forwarding_rule.forwarding_rule2_network2.psc_connection_id
37+
ip_address = google_compute_address.ip2_network2.address
38+
forwarding_rule = google_compute_forwarding_rule.forwarding_rule2_network2.id
39+
network = google_compute_network.network2.id
40+
service_attachment = google_memorystore_instance.instance-user-conn.psc_attachment_details[1].service_attachment
41+
}
42+
}
43+
}
44+
}
45+
46+
resource "google_compute_forwarding_rule" "forwarding_rule1_network1" {
47+
name = "fwd1-net1-${local.name_suffix}"
48+
region = "us-central1"
49+
ip_address = google_compute_address.ip1_network1.id
50+
load_balancing_scheme = ""
51+
network = google_compute_network.network1.id
52+
target = google_memorystore_instance.instance-user-conn.psc_attachment_details[0].service_attachment
53+
}
54+
55+
resource "google_compute_forwarding_rule" "forwarding_rule2_network1" {
56+
name = "fwd2-net1-${local.name_suffix}"
57+
region = "us-central1"
58+
ip_address = google_compute_address.ip2_network1.id
59+
load_balancing_scheme = ""
60+
network = google_compute_network.network1.id
61+
target = google_memorystore_instance.instance-user-conn.psc_attachment_details[1].service_attachment
62+
}
63+
64+
resource "google_compute_address" "ip1_network1" {
65+
name = "ip1-net1-${local.name_suffix}"
66+
region = "us-central1"
67+
subnetwork = google_compute_subnetwork.subnet_network1.id
68+
address_type = "INTERNAL"
69+
purpose = "GCE_ENDPOINT"
70+
}
71+
72+
resource "google_compute_address" "ip2_network1" {
73+
name = "ip2-net1-${local.name_suffix}"
74+
region = "us-central1"
75+
subnetwork = google_compute_subnetwork.subnet_network1.id
76+
address_type = "INTERNAL"
77+
purpose = "GCE_ENDPOINT"
78+
}
79+
80+
resource "google_compute_subnetwork" "subnet_network1" {
81+
name = "subnet-net1-${local.name_suffix}"
82+
ip_cidr_range = "10.0.0.248/29"
83+
region = "us-central1"
84+
network = google_compute_network.network1.id
85+
}
86+
87+
resource "google_compute_network" "network1" {
88+
name = "net1-${local.name_suffix}"
89+
auto_create_subnetworks = false
90+
}
91+
92+
resource "google_compute_forwarding_rule" "forwarding_rule1_network2" {
93+
name = "fwd1-net2-${local.name_suffix}"
94+
region = "us-central1"
95+
ip_address = google_compute_address.ip1_network2.id
96+
load_balancing_scheme = ""
97+
network = google_compute_network.network2.id
98+
target = google_memorystore_instance.instance-user-conn.psc_attachment_details[0].service_attachment
99+
}
100+
101+
resource "google_compute_forwarding_rule" "forwarding_rule2_network2" {
102+
name = "fwd2-net2-${local.name_suffix}"
103+
region = "us-central1"
104+
ip_address = google_compute_address.ip2_network2.id
105+
load_balancing_scheme = ""
106+
network = google_compute_network.network2.id
107+
target = google_memorystore_instance.instance-user-conn.psc_attachment_details[1].service_attachment
108+
}
109+
110+
resource "google_compute_address" "ip1_network2" {
111+
name = "ip1-net2-${local.name_suffix}"
112+
region = "us-central1"
113+
subnetwork = google_compute_subnetwork.subnet_network2.id
114+
address_type = "INTERNAL"
115+
purpose = "GCE_ENDPOINT"
116+
}
117+
118+
resource "google_compute_address" "ip2_network2" {
119+
name = "ip2-net2-${local.name_suffix}"
120+
region = "us-central1"
121+
subnetwork = google_compute_subnetwork.subnet_network2.id
122+
address_type = "INTERNAL"
123+
purpose = "GCE_ENDPOINT"
124+
}
125+
126+
//Valkey instance without endpoints
127+
resource "google_memorystore_instance" "instance-user-conn" {
128+
instance_id = "instance-user-conn-${local.name_suffix}"
129+
shard_count = 1
130+
location = "us-central1"
131+
deletion_protection_enabled = false
132+
}
133+
134+
resource "google_compute_subnetwork" "subnet_network2" {
135+
name = "subnet-net2-${local.name_suffix}"
136+
ip_cidr_range = "10.0.0.248/29"
137+
region = "us-central1"
138+
network = google_compute_network.network2.id
139+
}
140+
141+
resource "google_compute_network" "network2" {
142+
name = "network2-${local.name_suffix}"
143+
auto_create_subnetworks = false
144+
}
145+
146+
147+
data "google_project" "project" {
148+
}
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+
===

0 commit comments

Comments
 (0)