From 77c02075ac6145162d2bc979b151858bb471c8a4 Mon Sep 17 00:00:00 2001 From: Imran Nayer Date: Mon, 16 Sep 2024 14:00:40 -0500 Subject: [PATCH] feat(TPG>=6.0)!: Added deletion protection support in Redis cluster (#233) --- README.md | 13 ++++++------ docs/upgrading_to_v11.0.md | 9 ++++++++ examples/basic/memorystore.tf | 2 +- examples/memcache/main.tf | 6 +++--- examples/memcache/network.tf | 2 +- examples/memcache/outputs.tf | 2 +- examples/memcache/variables.tf | 2 +- examples/minimal/main.tf | 4 ++-- examples/minimal/network.tf | 2 +- examples/minimal/outputs.tf | 2 +- examples/minimal/variables.tf | 2 +- examples/redis-cluster/main.tf | 34 ++++++++++++++++++++++++------ examples/redis-cluster/network.tf | 2 +- examples/redis/main.tf | 4 ++-- examples/redis/network.tf | 2 +- examples/redis/outputs.tf | 2 +- examples/redis/variables.tf | 2 +- main.tf | 2 +- modules/memcache/versions.tf | 2 +- modules/redis-cluster/README.md | 5 +++-- modules/redis-cluster/main.tf | 23 ++++++++++---------- modules/redis-cluster/variables.tf | 6 ++++++ modules/redis-cluster/versions.tf | 6 +----- outputs.tf | 2 +- test/setup/iam.tf | 2 +- test/setup/main.tf | 4 ++-- test/setup/outputs.tf | 2 +- test/setup/variables.tf | 2 +- variables.tf | 2 +- versions.tf | 4 ++-- 30 files changed, 94 insertions(+), 60 deletions(-) create mode 100644 docs/upgrading_to_v11.0.md diff --git a/README.md b/README.md index dc90e39e..71910006 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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" diff --git a/docs/upgrading_to_v11.0.md b/docs/upgrading_to_v11.0.md new file mode 100644 index 00000000..1bd0c043 --- /dev/null +++ b/docs/upgrading_to_v11.0.md @@ -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`. diff --git a/examples/basic/memorystore.tf b/examples/basic/memorystore.tf index 8d50df69..838994a1 100644 --- a/examples/basic/memorystore.tf +++ b/examples/basic/memorystore.tf @@ -16,7 +16,7 @@ module "memorystore" { source = "terraform-google-modules/memorystore/google" - version = "~> 9.0" + version = "~> 11.0" name = "memorystore" project = "memorystore" diff --git a/examples/memcache/main.tf b/examples/memcache/main.tf index 385d38c4..559404ee 100644 --- a/examples/memcache/main.tf +++ b/examples/memcache/main.tf @@ -1,5 +1,5 @@ /** - * Copyright 2019 Google LLC + * 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. @@ -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 = [ @@ -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 diff --git a/examples/memcache/network.tf b/examples/memcache/network.tf index aa6e7945..416269ea 100644 --- a/examples/memcache/network.tf +++ b/examples/memcache/network.tf @@ -1,5 +1,5 @@ /** - * Copyright 2022 Google LLC + * 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. diff --git a/examples/memcache/outputs.tf b/examples/memcache/outputs.tf index 38ed63da..fc35727c 100644 --- a/examples/memcache/outputs.tf +++ b/examples/memcache/outputs.tf @@ -1,5 +1,5 @@ /** - * Copyright 2019 Google LLC + * 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. diff --git a/examples/memcache/variables.tf b/examples/memcache/variables.tf index 9f0febaa..d608c4bc 100644 --- a/examples/memcache/variables.tf +++ b/examples/memcache/variables.tf @@ -1,5 +1,5 @@ /** - * Copyright 2019 Google LLC + * 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. diff --git a/examples/minimal/main.tf b/examples/minimal/main.tf index bea83439..3dba3202 100644 --- a/examples/minimal/main.tf +++ b/examples/minimal/main.tf @@ -1,5 +1,5 @@ /** - * Copyright 2019 Google LLC + * 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. @@ -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 diff --git a/examples/minimal/network.tf b/examples/minimal/network.tf index d7723068..fac6c91f 100644 --- a/examples/minimal/network.tf +++ b/examples/minimal/network.tf @@ -1,5 +1,5 @@ /** - * Copyright 2022 Google LLC + * 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. diff --git a/examples/minimal/outputs.tf b/examples/minimal/outputs.tf index 29a0186a..96cb1c2a 100644 --- a/examples/minimal/outputs.tf +++ b/examples/minimal/outputs.tf @@ -1,5 +1,5 @@ /** - * Copyright 2019 Google LLC + * 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. diff --git a/examples/minimal/variables.tf b/examples/minimal/variables.tf index 483af0ea..22751b9c 100644 --- a/examples/minimal/variables.tf +++ b/examples/minimal/variables.tf @@ -1,5 +1,5 @@ /** - * Copyright 2019 Google LLC + * 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. diff --git a/examples/redis-cluster/main.tf b/examples/redis-cluster/main.tf index 7e579d42..fb6c01d1 100644 --- a/examples/redis-cluster/main.tf +++ b/examples/redis-cluster/main.tf @@ -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 = { diff --git a/examples/redis-cluster/network.tf b/examples/redis-cluster/network.tf index d3bb3bed..dbea8b37 100644 --- a/examples/redis-cluster/network.tf +++ b/examples/redis-cluster/network.tf @@ -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 diff --git a/examples/redis/main.tf b/examples/redis/main.tf index 55d5fd7c..ad4c11bd 100644 --- a/examples/redis/main.tf +++ b/examples/redis/main.tf @@ -1,5 +1,5 @@ /** - * Copyright 2019 Google LLC + * 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. @@ -16,7 +16,7 @@ module "memstore" { source = "terraform-google-modules/memorystore/google" - version = "~> 10.0" + version = "~> 11.0" name = "test-redis" diff --git a/examples/redis/network.tf b/examples/redis/network.tf index cc88073d..2b8e4845 100644 --- a/examples/redis/network.tf +++ b/examples/redis/network.tf @@ -1,5 +1,5 @@ /** - * Copyright 2022 Google LLC + * 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. diff --git a/examples/redis/outputs.tf b/examples/redis/outputs.tf index a6456b00..c970abeb 100644 --- a/examples/redis/outputs.tf +++ b/examples/redis/outputs.tf @@ -1,5 +1,5 @@ /** - * Copyright 2019 Google LLC + * 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. diff --git a/examples/redis/variables.tf b/examples/redis/variables.tf index 483af0ea..22751b9c 100644 --- a/examples/redis/variables.tf +++ b/examples/redis/variables.tf @@ -1,5 +1,5 @@ /** - * Copyright 2019 Google LLC + * 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. diff --git a/main.tf b/main.tf index 1467bd86..42296c61 100644 --- a/main.tf +++ b/main.tf @@ -1,5 +1,5 @@ /** - * Copyright 2019 Google LLC + * 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. diff --git a/modules/memcache/versions.tf b/modules/memcache/versions.tf index ddcc5e51..c591e44e 100644 --- a/modules/memcache/versions.tf +++ b/modules/memcache/versions.tf @@ -15,7 +15,7 @@ */ terraform { - required_version = ">= 0.13" + required_version = ">= 1.3" required_providers { google = { diff --git a/modules/redis-cluster/README.md b/modules/redis-cluster/README.md index 5db8f10d..9a741fc1 100644 --- a/modules/redis-cluster/README.md +++ b/modules/redis-cluster/README.md @@ -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 @@ -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 | @@ -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 diff --git a/modules/redis-cluster/main.tf b/modules/redis-cluster/main.tf index 2efa5c8c..35defff6 100644 --- a/modules/redis-cluster/main.tf +++ b/modules/redis-cluster/main.tf @@ -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 @@ -44,7 +45,6 @@ resource "google_redis_cluster" "redis_cluster" { google_network_connectivity_service_connection_policy.service_connection_policies, module.enable_apis, ] - } resource "google_network_connectivity_service_connection_policy" "service_connection_policies" { @@ -64,10 +64,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 diff --git a/modules/redis-cluster/variables.tf b/modules/redis-cluster/variables.tf index 146eb4f3..8240941c 100644 --- a/modules/redis-cluster/variables.tf +++ b/modules/redis-cluster/variables.tf @@ -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 +} diff --git a/modules/redis-cluster/versions.tf b/modules/redis-cluster/versions.tf index d940016c..7057084a 100644 --- a/modules/redis-cluster/versions.tf +++ b/modules/redis-cluster/versions.tf @@ -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" } } diff --git a/outputs.tf b/outputs.tf index c008deb9..f1d26271 100644 --- a/outputs.tf +++ b/outputs.tf @@ -1,5 +1,5 @@ /** - * Copyright 2019 Google LLC + * 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. diff --git a/test/setup/iam.tf b/test/setup/iam.tf index 9255735b..aaeacac4 100644 --- a/test/setup/iam.tf +++ b/test/setup/iam.tf @@ -1,5 +1,5 @@ /** - * Copyright 2019 Google LLC + * 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. diff --git a/test/setup/main.tf b/test/setup/main.tf index ee82550c..4eb66408 100644 --- a/test/setup/main.tf +++ b/test/setup/main.tf @@ -1,5 +1,5 @@ /** - * Copyright 2019 Google LLC + * 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. @@ -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 diff --git a/test/setup/outputs.tf b/test/setup/outputs.tf index 3a72d631..a21fbc2a 100644 --- a/test/setup/outputs.tf +++ b/test/setup/outputs.tf @@ -1,5 +1,5 @@ /** - * Copyright 2019 Google LLC + * 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. diff --git a/test/setup/variables.tf b/test/setup/variables.tf index 84134fe3..4a221f8c 100644 --- a/test/setup/variables.tf +++ b/test/setup/variables.tf @@ -1,5 +1,5 @@ /** - * Copyright 2019 Google LLC + * 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. diff --git a/variables.tf b/variables.tf index db6e9ff5..f06c242c 100644 --- a/variables.tf +++ b/variables.tf @@ -1,5 +1,5 @@ /** - * Copyright 2019 Google LLC + * 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. diff --git a/versions.tf b/versions.tf index 41da72d3..c76b187d 100644 --- a/versions.tf +++ b/versions.tf @@ -1,5 +1,5 @@ /** - * Copyright 2021 Google LLC + * 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. @@ -15,7 +15,7 @@ */ terraform { - required_version = ">= 0.13" + required_version = ">= 1.3" required_providers { google = {