Skip to content

Commit

Permalink
feat: add sub-module memorystore for Valkey (#239)
Browse files Browse the repository at this point in the history
  • Loading branch information
imrannayer authored Oct 7, 2024
1 parent 75222fc commit 9c3c3f3
Show file tree
Hide file tree
Showing 17 changed files with 812 additions and 19 deletions.
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
# Google Cloud Memorystore Terraform Module
[terraform registry](https://registry.terraform.io/modules/terraform-google-modules/memorystore/google/)

A Terraform module for creating a fully functional Google Memorystore Redis instance. For Memcache and Redis Cluster see [sub-modules](./modules/)
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).

- Memcache [sub-modules](https://github.com/terraform-google-modules/terraform-google-memorystore/tree/master/modules/memcache)
- Redis Cluster [sub-modules](https://github.com/terraform-google-modules/terraform-google-memorystore/tree/master/modules/redis-cluster)
- Valkey [sub-modules](https://github.com/terraform-google-modules/terraform-google-memorystore/tree/master/modules/valkey)

## Compatibility
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.
Expand All @@ -19,7 +23,7 @@ Current version is 11.0. Upgrade guides:

## Usage

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

```hcl
module "memorystore" {
Expand Down
60 changes: 53 additions & 7 deletions build/int.cloudbuild.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

timeout: 4200s
timeout: 5400s
steps:
- id: swap-module-refs
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
Expand All @@ -27,15 +27,61 @@ steps:
- id: create
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
args: ['/bin/bash', '-c', 'cft test run all --stage init --verbose --test-dir test/integration']
- id: converge
- id: converge-TestMinimalModule
waitFor:
- create
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
args: ['/bin/bash', '-c', 'cft test run all --stage apply --verbose --test-dir test/integration']
- id: verify
args: ['/bin/bash', '-c', 'cft test run TestMinimalModule --stage apply --verbose --test-dir test/integration']
- id: verify-TestMinimalModule
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
args: ['/bin/bash', '-c', 'cft test run all --stage verify --verbose --test-dir test/integration']
- id: destroy
args: ['/bin/bash', '-c', 'cft test run TestMinimalModule --stage verify --verbose --test-dir test/integration']
- id: destroy-TestMinimalModule
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
args: ['/bin/bash', '-c', 'cft test run all --stage teardown --verbose --test-dir test/integration']
args: ['/bin/bash', '-c', 'cft test run TestMinimalModule --stage teardown --verbose --test-dir test/integration']
- id: converge-TestMemcache
waitFor:
- create
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
args: ['/bin/bash', '-c', 'cft test run TestMemcache --stage apply --verbose --test-dir test/integration']
- id: verify-TestMemcache
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
args: ['/bin/bash', '-c', 'cft test run TestMemcache --stage verify --verbose --test-dir test/integration']
- id: destroy-TestMemcache
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
args: ['/bin/bash', '-c', 'cft test run TestMemcache --stage teardown --verbose --test-dir test/integration']
- id: converge-TestRedis
waitFor:
- create
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
args: ['/bin/bash', '-c', 'cft test run TestRedis --stage apply --verbose --test-dir test/integration']
- id: verify-TestRedis
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
args: ['/bin/bash', '-c', 'cft test run TestRedis --stage verify --verbose --test-dir test/integration']
- id: destroy-TestRedis
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
args: ['/bin/bash', '-c', 'cft test run TestRedis --stage teardown --verbose --test-dir test/integration']
- id: converge-TestRedisCluster
waitFor:
- create
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
args: ['/bin/bash', '-c', 'cft test run TestRedisCluster --stage apply --verbose --test-dir test/integration']
- id: verify-TestRedisCluster
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
args: ['/bin/bash', '-c', 'cft test run TestRedisCluster --stage verify --verbose --test-dir test/integration']
- id: destroy-TestRedisCluster
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
args: ['/bin/bash', '-c', 'cft test run TestRedisCluster --stage teardown --verbose --test-dir test/integration']
- id: converge-TestValkeyCluster
waitFor:
- destroy-TestRedisCluster
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
args: ['/bin/bash', '-c', 'cft test run TestValkeyCluster --stage apply --verbose --test-dir test/integration']
- id: verify-TestValkeyCluster
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
args: ['/bin/bash', '-c', 'cft test run TestValkeyCluster --stage verify --verbose --test-dir test/integration']
- id: destroy-TestValkeyCluster
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
args: ['/bin/bash', '-c', 'cft test run TestValkeyCluster --stage teardown --verbose --test-dir test/integration']
tags:
- 'ci'
- 'integration'
Expand Down
6 changes: 5 additions & 1 deletion examples/redis-cluster/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,9 @@ module "redis_cluster" {
maxmemory-policy = "volatile-ttl"
}

depends_on = [module.test_vpc]
depends_on = [
module.test_vpc,
module.enable_apis,
google_project_iam_member.network_connectivity_sa,
]
}
27 changes: 27 additions & 0 deletions examples/valkey/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Valkey Test

This test will create a new valkey cluster.

<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
## Inputs

| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| project\_id | Google cloud project id to create valkey cluster. | `string` | n/a | yes |

## Outputs

| Name | Description |
|------|-------------|
| authorization\_mode | The valkey cluster authorization mode |
| cluster | The valkey cluster created |
| cluster\_id | The valkey cluster instance ID |
| cluster\_name | The valkey cluster name |
| cluster\_region | The valkey cluster region |
| node\_type | The valkey cluster node type |
| replica\_count | The valkey cluster replica count |
| shard\_count | The valkey cluster shard count |
| size\_gb | The valkey cluster size |
| transit\_encryption\_mode | The valkey cluster transit encryption mode |

<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
31 changes: 31 additions & 0 deletions examples/valkey/iam.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/**
* Copyright 2024 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

## Enable Service Identity and assign Network Connectivity Service Agent role
## https://cloud.google.com/vpc/docs/configure-service-connection-policies#configure-service-project

resource "google_project_service_identity" "network_connectivity_sa" {
provider = google-beta

project = var.project_id
service = "networkconnectivity.googleapis.com"
}

resource "google_project_iam_member" "network_connectivity_sa" {
project = var.project_id
role = "roles/networkconnectivity.serviceAgent"
member = "serviceAccount:${google_project_service_identity.network_connectivity_sa.email}"
}
76 changes: 76 additions & 0 deletions examples/valkey/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/**
* Copyright 2024 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

module "enable_apis" {
source = "terraform-google-modules/project-factory/google//modules/project_services"
version = "~> 17.0"

project_id = var.project_id
enable_apis = true

disable_services_on_destroy = false
disable_dependent_services = false

activate_apis = [
"memorystore.googleapis.com",
"serviceconsumermanagement.googleapis.com",
"networkconnectivity.googleapis.com",
"compute.googleapis.com",
]
}


module "valkey_cluster" {
source = "terraform-google-modules/memorystore/google//modules/valkey"
version = "~> 11.0"


instance_id = "test-valkey-cluster"
project_id = var.project_id
location = "us-central1"
node_type = "HIGHMEM_MEDIUM"
deletion_protection_enabled = false
engine_version = "VALKEY_8_0"

network = local.network_name

service_connection_policies = {
test-net-valkey-cluster-scp = {
subnet_names = [
"valkey-subnet-100",
"valkey-subnet-101",
]
}
}

persistence_config = {
mode = "RDB"
rdb_config = {
rdb_snapshot_period = "ONE_HOUR"
rdb_snapshot_start_time = "2024-10-02T15:01:23Z"
}
}

engine_configs = {
maxmemory-policy = "volatile-ttl"
}

depends_on = [
module.test_vpc,
module.enable_apis,
google_project_iam_member.network_connectivity_sa,
]
}
45 changes: 45 additions & 0 deletions examples/valkey/network.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/**
* Copyright 2024 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

locals {
network_name = "test-valkey-network"
}

module "test_vpc" {
source = "terraform-google-modules/network/google"
version = "~> 9.2"
project_id = var.project_id
network_name = local.network_name
mtu = 1460

subnets = [
{
subnet_name = "valkey-subnet-100"
subnet_ip = "10.10.100.0/24"
subnet_region = "us-central1"
},
{
subnet_name = "valkey-subnet-101"
subnet_ip = "10.10.101.0/24"
subnet_region = "us-central1"
},
{
subnet_name = "valkey-subnet-102"
subnet_ip = "10.10.102.0/24"
subnet_region = "us-east1"
},
]
}
65 changes: 65 additions & 0 deletions examples/valkey/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/**
* Copyright 2024 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

output "cluster_id" {
description = "The valkey cluster instance ID"
value = module.valkey_cluster.id
}

output "size_gb" {
description = "The valkey cluster size"
value = module.valkey_cluster.valkey_cluster.node_config[0].size_gb
}

output "cluster_region" {
description = "The valkey cluster region"
value = module.valkey_cluster.valkey_cluster.location
}

output "replica_count" {
description = "The valkey cluster replica count"
value = module.valkey_cluster.valkey_cluster.replica_count
}

output "transit_encryption_mode" {
description = "The valkey cluster transit encryption mode"
value = module.valkey_cluster.valkey_cluster.transit_encryption_mode
}

output "cluster_name" {
description = "The valkey cluster name"
value = module.valkey_cluster.valkey_cluster.instance_id
}

output "shard_count" {
description = "The valkey cluster shard count"
value = module.valkey_cluster.valkey_cluster.shard_count
}

output "authorization_mode" {
description = "The valkey cluster authorization mode"
value = module.valkey_cluster.valkey_cluster.authorization_mode
}

output "node_type" {
description = "The valkey cluster node type"
value = module.valkey_cluster.valkey_cluster.node_type
}

output "cluster" {
description = "The valkey cluster created"
value = module.valkey_cluster
}
20 changes: 20 additions & 0 deletions examples/valkey/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/**
* Copyright 2024 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

variable "project_id" {
description = "Google cloud project id to create valkey cluster."
type = string
}
Loading

0 comments on commit 9c3c3f3

Please sign in to comment.