Skip to content

Commit d4d2bff

Browse files
committed
add sub-module for valkey
1 parent 75222fc commit d4d2bff

File tree

16 files changed

+751
-11
lines changed

16 files changed

+751
-11
lines changed

.terraform.lock

Whitespace-only changes.

README.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
# Google Cloud Memorystore Terraform Module
22
[terraform registry](https://registry.terraform.io/modules/terraform-google-modules/memorystore/google/)
33

4-
A Terraform module for creating a fully functional Google Memorystore Redis instance. For Memcache and Redis Cluster see [sub-modules](./modules/)
4+
A Terraform module for creating a fully functional Google Memorystore Redis instance. For other memory store engine use [sub-modules](https://github.com/terraform-google-modules/terraform-google-memorystore/tree/master/modules).
5+
6+
- Memcache [sub-modules](https://github.com/terraform-google-modules/terraform-google-memorystore/tree/master/modules/memcache)
7+
- Redis Cluster [sub-modules](https://github.com/terraform-google-modules/terraform-google-memorystore/tree/master/modules/redis-cluster)
8+
- Valkey [sub-modules](https://github.com/terraform-google-modules/terraform-google-memorystore/tree/master/modules/valkey)
59

610
## Compatibility
711
This module is meant for use with Terraform 1.3+ and tested using Terraform 1.3+. If you find incompatibilities using Terraform >=1.3, please open an issue.
@@ -19,7 +23,7 @@ Current version is 11.0. Upgrade guides:
1923

2024
## Usage
2125

22-
Check the [examples/](./examples/) directory for more.
26+
Check the [examples/](https://github.com/terraform-google-modules/terraform-google-memorystore/tree/master/examples) directory for more.
2327

2428
```hcl
2529
module "memorystore" {

examples/valkey/README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Valkey Test
2+
3+
This test will create a new valkey cluster.
4+
5+
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
6+
## Inputs
7+
8+
| Name | Description | Type | Default | Required |
9+
|------|-------------|------|---------|:--------:|
10+
| project\_id | Google cloud project id to create valkey cluster. | `string` | n/a | yes |
11+
12+
## Outputs
13+
14+
| Name | Description |
15+
|------|-------------|
16+
| authorization\_mode | The valkey cluster authorization mode |
17+
| cluster | The valkey cluster created |
18+
| cluster\_id | The valkey cluster instance ID |
19+
| cluster\_name | The valkey cluster name |
20+
| cluster\_region | The valkey cluster region |
21+
| node\_type | The valkey cluster node type |
22+
| replica\_count | The valkey cluster replica count |
23+
| shard\_count | The valkey cluster shard count |
24+
| size\_gb | The valkey cluster size |
25+
| transit\_encryption\_mode | The valkey cluster transit encryption mode |
26+
27+
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->

examples/valkey/iam.tf

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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+
## Enable Service Identity and assign Network Connectivity Service Agent role
18+
## https://cloud.google.com/vpc/docs/configure-service-connection-policies#configure-service-project
19+
20+
resource "google_project_service_identity" "network_connectivity_sa" {
21+
provider = google-beta
22+
23+
project = var.project_id
24+
service = "networkconnectivity.googleapis.com"
25+
}
26+
27+
resource "google_project_iam_member" "network_connectivity_sa" {
28+
project = var.project_id
29+
role = "roles/networkconnectivity.serviceAgent"
30+
member = "serviceAccount:${google_project_service_identity.network_connectivity_sa.email}"
31+
}

examples/valkey/main.tf

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
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+
module "enable_apis" {
18+
source = "terraform-google-modules/project-factory/google//modules/project_services"
19+
version = "~> 17.0"
20+
21+
project_id = var.project_id
22+
enable_apis = true
23+
24+
disable_services_on_destroy = false
25+
disable_dependent_services = false
26+
27+
activate_apis = [
28+
"memorystore.googleapis.com",
29+
"serviceconsumermanagement.googleapis.com",
30+
"networkconnectivity.googleapis.com",
31+
"compute.googleapis.com",
32+
]
33+
}
34+
35+
36+
module "valkey_cluster" {
37+
source = "terraform-google-modules/memorystore/google//modules/valkey"
38+
version = "~> 11.0"
39+
40+
instance_id = "test-valkey-cluster"
41+
project = var.project_id
42+
location = "us-central1"
43+
node_type = "HIGHMEM_MEDIUM"
44+
deletion_protection_enabled = false
45+
engine_version = "VALKEY_8_0"
46+
47+
network = local.network_name
48+
49+
service_connection_policies = {
50+
test-net-valkey-cluster-scp = {
51+
subnet_names = [
52+
"valkey-subnet-100",
53+
"valkey-subnet-101",
54+
]
55+
}
56+
}
57+
58+
persistence_config = {
59+
mode = "RDB"
60+
rdb_config = {
61+
rdb_snapshot_period = "ONE_HOUR"
62+
rdb_snapshot_start_time = "2024-10-02T15:01:23Z"
63+
}
64+
}
65+
66+
engine_configs = {
67+
maxmemory-policy = "volatile-ttl"
68+
}
69+
70+
depends_on = [
71+
module.test_vpc,
72+
module.enable_apis,
73+
]
74+
}

examples/valkey/network.tf

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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+
locals {
18+
network_name = "test-valkey-network"
19+
}
20+
21+
module "test_vpc" {
22+
source = "terraform-google-modules/network/google"
23+
version = "~> 9.2"
24+
project_id = var.project_id
25+
network_name = local.network_name
26+
mtu = 1460
27+
28+
subnets = [
29+
{
30+
subnet_name = "valkey-subnet-100"
31+
subnet_ip = "10.10.100.0/24"
32+
subnet_region = "us-central1"
33+
},
34+
{
35+
subnet_name = "valkey-subnet-101"
36+
subnet_ip = "10.10.101.0/24"
37+
subnet_region = "us-central1"
38+
},
39+
{
40+
subnet_name = "valkey-subnet-102"
41+
subnet_ip = "10.10.102.0/24"
42+
subnet_region = "us-east1"
43+
},
44+
]
45+
}

examples/valkey/outputs.tf

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
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+
output "cluster_id" {
18+
description = "The valkey cluster instance ID"
19+
value = module.valkey_cluster.id
20+
}
21+
22+
output "size_gb" {
23+
description = "The valkey cluster size"
24+
value = module.valkey_cluster.valkey_cluster.node_config[0].size_gb
25+
}
26+
27+
output "cluster_region" {
28+
description = "The valkey cluster region"
29+
value = module.valkey_cluster.valkey_cluster.location
30+
}
31+
32+
output "replica_count" {
33+
description = "The valkey cluster replica count"
34+
value = module.valkey_cluster.valkey_cluster.replica_count
35+
}
36+
37+
output "transit_encryption_mode" {
38+
description = "The valkey cluster transit encryption mode"
39+
value = module.valkey_cluster.valkey_cluster.transit_encryption_mode
40+
}
41+
42+
output "cluster_name" {
43+
description = "The valkey cluster name"
44+
value = module.valkey_cluster.valkey_cluster.instance_id
45+
}
46+
47+
output "shard_count" {
48+
description = "The valkey cluster shard count"
49+
value = module.valkey_cluster.valkey_cluster.shard_count
50+
}
51+
52+
output "authorization_mode" {
53+
description = "The valkey cluster authorization mode"
54+
value = module.valkey_cluster.valkey_cluster.authorization_mode
55+
}
56+
57+
output "node_type" {
58+
description = "The valkey cluster node type"
59+
value = module.valkey_cluster.valkey_cluster.node_type
60+
}
61+
62+
output "cluster" {
63+
description = "The valkey cluster created"
64+
value = module.valkey_cluster
65+
}

examples/valkey/variables.tf

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
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+
variable "project_id" {
18+
description = "Google cloud project id to create valkey cluster."
19+
type = string
20+
}

modules/valkey/README.md

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
# Memorystore Valkey Terraform Module
2+
3+
A Terraform module for creating Google [Memorystore for Valkey](https://cloud.google.com/memorystore/docs/valkey/product-overview). It can also create [service connection policies](https://cloud.google.com/vpc/docs/about-service-connection-policies). You can also create service connection policy outside of this module. If you are not creating service connection policy as part of this module then make sure they exist before creating valkey cluster. You can find more details [here](https://cloud.google.com/memorystore/docs/valkey/networking)
4+
5+
## Compatibility
6+
This module is meant for use with Terraform 1.3+ and tested using Terraform 1.3+. If you find incompatibilities using Terraform >=1.3, please open an issue.
7+
8+
## Usage
9+
10+
```
11+
module "valkey_cluster" {
12+
source = "terraform-google-modules/memorystore/google//modules/valkey"
13+
version = "~> 11.0"
14+
15+
instance_id = "test-valkey-cluster"
16+
project = var.project_id
17+
location = "us-central1"
18+
node_type = "HIGHMEM_MEDIUM"
19+
deletion_protection_enabled = false
20+
engine_version = "VALKEY_8_0"
21+
22+
network = "valkey-network"
23+
24+
service_connection_policies = {
25+
test-net-valkey-cluster-scp = {
26+
subnet_names = [
27+
"valkey-subnet-100",
28+
"valkey-subnet-101",
29+
]
30+
}
31+
}
32+
33+
engine_configs = {
34+
maxmemory-policy = "volatile-ttl"
35+
}
36+
}
37+
```
38+
39+
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
40+
## Inputs
41+
42+
| Name | Description | Type | Default | Required |
43+
|------|-------------|------|---------|:--------:|
44+
| authorization\_mode | The Immutable. Authorization mode of the instance. Possible values: AUTH\_DISABLED IAM\_AUTH | `string` | `"AUTH_DISABLED"` | no |
45+
| deletion\_protection\_enabled | If set to true deletion of the instance will fail | `bool` | `true` | no |
46+
| enable\_apis | Flag for enabling memcache.googleapis.com in your project | `bool` | `false` | no |
47+
| engine\_configs | User-provided engine configurations for the instance | <pre>object({<br> maxmemory = optional(string)<br> maxmemory-clients = optional(string)<br> maxmemory-policy = optional(string)<br> notify-keyspace-events = optional(string)<br> slowlog-log-slower-than = optional(number)<br> maxclients = optional(number)<br> })</pre> | `null` | no |
48+
| engine\_version | Immutable. Engine version of the instance | `string` | `"VALKEY_8_0"` | no |
49+
| instance\_id | The ID to use for the instance, which will become the final component of the instance's resource name. Must be 4-63 characters in length with lowercase letters, digits, and hyphens. Must not end with a hyphen. Must be unique within a location | `string` | n/a | yes |
50+
| labels | The resource labels to represent user provided metadata. | `map(string)` | `{}` | no |
51+
| location | The region where valkey cluster will be created | `string` | n/a | yes |
52+
| network | Name of the consumer network where the network address of the discovery endpoint will be reserved | `string` | n/a | yes |
53+
| network\_project | project ID of the consumer network where the network address of the discovery endpoint will be reserved. Required for Shared VPC host | `string` | `null` | no |
54+
| node\_type | The nodeType for the valkey cluster. Possible values are: SHARED\_CORE\_NANO, HIGHMEM\_MEDIUM, HIGHMEM\_XLARGE, STANDARD\_SMALL | `string` | `null` | no |
55+
| persistence\_config | User-provided persistence configurations for the instance | <pre>object({<br> mode = optional(string)<br> rdb_config = optional(object({<br> rdb_snapshot_period = optional(string)<br> rdb_snapshot_start_time = optional(string)<br> }), null)<br> aof_config = optional(object({<br> append_fsync = string<br> }), null)<br> })</pre> | `{}` | no |
56+
| project | The ID of the project in which the resource belongs to. | `string` | n/a | yes |
57+
| replica\_count | Number of replica nodes per shard. If omitted the default is 0 replicas | `number` | `0` | no |
58+
| service\_connection\_policies | The Service Connection Policies to create. Required to create service connection policy. Not needed if service connection policy already exist | <pre>map(object({<br> subnet_names = list(string)<br> description = optional(string)<br> limit = optional(number)<br> labels = optional(map(string), {})<br> }))</pre> | `{}` | no |
59+
| shard\_count | Number of shards for the instance | `number` | `3` | no |
60+
| transit\_encryption\_mode | Immutable. In-transit encryption mode of the instance. Possible values: TRANSIT\_ENCRYPTION\_DISABLED SERVER\_AUTHENTICATION | `string` | `"TRANSIT_ENCRYPTION_DISABLED"` | no |
61+
| zone\_distribution\_config\_mode | The mode for zone distribution for Memorystore valkey cluster (Immutable). If not provided, MULTI\_ZONE will be used as default value. Possible values are: MULTI\_ZONE, SINGLE\_ZONE | `string` | `"MULTI_ZONE"` | no |
62+
| zone\_distribution\_config\_zone | The zone for single zone Memorystore valkey cluster (Immutable) | `string` | `null` | no |
63+
64+
## Outputs
65+
66+
| Name | Description |
67+
|------|-------------|
68+
| discovery\_endpoints | Endpoints created on each given network, for valkey clients to connect to the cluster. Currently only one endpoint is supported |
69+
| id | The valkey cluster instance ID |
70+
| psc\_connections | PSC connections for discovery of the cluster topology and accessing the cluster |
71+
| valkey\_cluster | The valkey cluster created |
72+
73+
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
74+
75+
## Requirements
76+
77+
These sections describe requirements for using this module.
78+
79+
### Software
80+
81+
The following dependencies must be available:
82+
83+
- [Terraform][terraform] v1.3+
84+
- [Terraform Provider for GCP][terraform-provider-gcp] plugin v6.3+
85+
86+
### Service Account
87+
88+
Following roles contain permissions to deploy resource.
89+
90+
- Cloud Memorystore valkey Admin: `roles/memorystore.admin`
91+
- Compute Network Admin: `roles/compute.networkAdmin`
92+
93+
### Enable API's
94+
In order to operate with the Service Account you must activate the following API on the project where the Service Account was created:
95+
96+
- Memorystore for valkey API - `memorystore.googleapis.com`
97+
- Service Consumer Management API - `serviceconsumermanagement.googleapis.com`
98+
- Network Connectivity API - `networkconnectivity.googleapis.com`
99+
- Compute Engine API - `compute.googleapis.com`
100+

0 commit comments

Comments
 (0)