Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(TPG>=6.0)!: Added deletion protection support in Redis cluster #233

Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,17 @@ A Terraform module for creating a fully functional Google Memorystore Redis inst

## 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.
If you haven't
[upgraded](https://www.terraform.io/upgrade-guides/0-13.html) and need a Terraform
0.12.x-compatible version of this module, the last released version
intended for Terraform 0.12.x is [v2.0.0](https://registry.terraform.io/modules/terraform-google-modules/-memorystore/google/v2.0.0).

If you haven't [upgraded](https://www.terraform.io/upgrade-guides/0-13.html) and need a Terraform
0.12.x-compatible version of this module, the last released version intended for Terraform 0.12.x is [v2.0.0](https://registry.terraform.io/modules/terraform-google-modules/-memorystore/google/v2.0.0).

## Version

Current version is 8.0. Upgrade guides:
Current version is 11.0. Upgrade guides:

- [7.X -> 8.0](/docs/upgrading_to_v8.0.md)
- [8.X -> 9.0](/docs/upgrading_to_v9.0.md)
- [10.X -> 11.0](/docs/upgrading_to_v11.0.md)

## Usage

Expand All @@ -23,7 +24,7 @@ Check the [examples/](./examples/) directory for more.
```hcl
module "memorystore" {
source = "terraform-google-modules/memorystore/google"
version = "~> 10.0"
version = "~> 11.0"

name = "memorystore"
project = "memorystore"
Expand Down
9 changes: 9 additions & 0 deletions docs/upgrading_to_v11.0.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Upgrading to v11.0

The v11.0 release contains backwards-incompatible changes.

## Minimum Provider Version
This update requires upgrading the terraform provider version to `6+` for redis cluster sub-module.

## Parameter deletion_protection_enabled default value in redis cluster
Added support for [deletion_protection](https://registry.terraform.io/providers/hashicorp/google/latest/docs/guides/version_6_upgrade#resource-google_redis_cluster). Default value for `deletion_protection_enabled` is set to `true`.
2 changes: 1 addition & 1 deletion examples/basic/memorystore.tf
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

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

name = "memorystore"
project = "memorystore"
Expand Down
4 changes: 2 additions & 2 deletions examples/memcache/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

module "private-service-access" {
source = "GoogleCloudPlatform/sql-db/google//modules/private_service_access"
version = "~> 20.0"
version = "~> 22.0"
project_id = var.project_id
vpc_network = module.test-vpc-module.network_name
depends_on = [
Expand All @@ -26,7 +26,7 @@ module "private-service-access" {

module "memcache" {
source = "terraform-google-modules/memorystore/google//modules/memcache"
version = "~> 9.0"
version = "~> 11.0"

name = "example-memcache"
project = var.project_id
Expand Down
2 changes: 1 addition & 1 deletion examples/minimal/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

module "memstore" {
source = "terraform-google-modules/memorystore/google"
version = "~> 9.0"
version = "~> 11.0"

name = "test-minimal"
project = var.project_id
Expand Down
34 changes: 28 additions & 6 deletions examples/redis-cluster/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,37 @@
* 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 = [
"redis.googleapis.com",
"serviceconsumermanagement.googleapis.com",
"networkconnectivity.googleapis.com",
"compute.googleapis.com",
]
}


module "redis_cluster" {
source = "terraform-google-modules/memorystore/google//modules/redis-cluster"
version = "~> 9.0"
version = "~> 11.0"

name = "test-redis-cluster"
project = var.project_id
region = "us-central1"
network = ["projects/${var.project_id}/global/networks/${local.network_name}"]
node_type = "REDIS_STANDARD_SMALL"
deletion_protection_enabled = false
enable_apis = false

name = "test-redis-cluster"
project = var.project_id
region = "us-central1"
network = ["projects/${var.project_id}/global/networks/${local.network_name}"]
node_type = "REDIS_STANDARD_SMALL"

service_connection_policies = {
test-net-redis-cluster-scp = {
Expand Down
2 changes: 1 addition & 1 deletion examples/redis-cluster/network.tf
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ locals {

module "test_vpc" {
source = "terraform-google-modules/network/google"
version = "~> 9.0"
version = "~> 9.2"
project_id = var.project_id
network_name = local.network_name
mtu = 1460
Expand Down
2 changes: 1 addition & 1 deletion examples/redis/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

module "memstore" {
source = "terraform-google-modules/memorystore/google"
version = "~> 10.0"
version = "~> 11.0"

name = "test-redis"

Expand Down
5 changes: 3 additions & 2 deletions modules/redis-cluster/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ This module is meant for use with Terraform 1.3+ and tested using Terraform 1.3+
```
module "redis_cluster" {
source = "terraform-google-modules/memorystore/google//modules/redis-cluster"
version = "~> 10.0"
version = "~> 11.0"

name = "test-redis-cluster"
project = var.project_id
Expand All @@ -31,6 +31,7 @@ module "redis_cluster" {
| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| authorization\_mode | The authorization mode of the Redis cluster. If not provided, auth feature is disabled for the cluster. Default value is AUTH\_MODE\_DISABLED. Possible values are: AUTH\_MODE\_UNSPECIFIED, AUTH\_MODE\_IAM\_AUTH, AUTH\_MODE\_DISABLED | `string` | `"AUTH_MODE_DISABLED"` | no |
| deletion\_protection\_enabled | Indicates if the cluster is deletion protected or not. If the value if set to true, any delete cluster operation will fail. Default value is true | `bool` | `true` | no |
| enable\_apis | Flag for enabling memcache.googleapis.com in your project | `bool` | `true` | no |
| name | The ID of the instance or a fully qualified identifier for the instance. must be 1 to 63 characters and use only lowercase letters, numbers, or hyphens. It must start with a lowercase letter and end with a lowercase letter or number | `string` | n/a | yes |
| network | List of consumer network where the network address of the discovery endpoint will be reserved, in the form of projects/{network\_project\_id\_or\_number}/global/networks/{network\_id}. Currently, only one item is supported | `list(string)` | n/a | yes |
Expand Down Expand Up @@ -65,7 +66,7 @@ These sections describe requirements for using this module.
The following dependencies must be available:

- [Terraform][terraform] v1.3+
- [Terraform Provider for GCP][terraform-provider-gcp] plugin v5.28+
- [Terraform Provider for GCP][terraform-provider-gcp] plugin v6.0+

### Service Account

Expand Down
23 changes: 12 additions & 11 deletions modules/redis-cluster/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,16 @@
*/

resource "google_redis_cluster" "redis_cluster" {
project = var.project
name = var.name
shard_count = var.shard_count
region = var.region
replica_count = var.replica_count
transit_encryption_mode = var.transit_encryption_mode
authorization_mode = var.authorization_mode
node_type = var.node_type
redis_configs = var.redis_configs
project = var.project
name = var.name
shard_count = var.shard_count
region = var.region
replica_count = var.replica_count
transit_encryption_mode = var.transit_encryption_mode
authorization_mode = var.authorization_mode
node_type = var.node_type
redis_configs = var.redis_configs
deletion_protection_enabled = var.deletion_protection_enabled

dynamic "psc_configs" {
for_each = var.network
Expand All @@ -40,6 +41,7 @@ resource "google_redis_cluster" "redis_cluster" {
}
}


imrannayer marked this conversation as resolved.
Show resolved Hide resolved
depends_on = [
google_network_connectivity_service_connection_policy.service_connection_policies,
module.enable_apis,
Expand All @@ -64,10 +66,9 @@ resource "google_network_connectivity_service_connection_policy" "service_connec

}


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

project_id = var.project
enable_apis = var.enable_apis
Expand Down
6 changes: 6 additions & 0 deletions modules/redis-cluster/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,9 @@ variable "zone_distribution_config_zone" {
type = string
default = null
}

variable "deletion_protection_enabled" {
description = " Indicates if the cluster is deletion protected or not. If the value if set to true, any delete cluster operation will fail. Default value is true"
type = bool
default = true
}
6 changes: 1 addition & 5 deletions modules/redis-cluster/versions.tf
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,7 @@ terraform {

google = {
source = "hashicorp/google"
version = ">= 5.33, < 7"
}
google-beta = {
source = "hashicorp/google-beta"
version = ">= 5.33, < 7"
version = ">= 6.0, < 7"
}
}

Expand Down
2 changes: 1 addition & 1 deletion test/setup/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

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

name = "ci-memory-store"
random_project_id = true
Expand Down