-
Notifications
You must be signed in to change notification settings - Fork 107
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add sub-module memorystore for Valkey (#239)
- Loading branch information
1 parent
75222fc
commit 9c3c3f3
Showing
17 changed files
with
812 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 --> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
}, | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
Oops, something went wrong.