From 97bc4b5dbab8d2ea78ffd6aaf5716ab271f11f59 Mon Sep 17 00:00:00 2001 From: Melissa Greenbaum <69476188+magreenbaum@users.noreply.github.com> Date: Sun, 4 Aug 2024 09:36:08 -0400 Subject: [PATCH 1/2] fix: Argument `replication_group_id` conflicts with `engine` and `log_delivery_configuration` (#10) --- .../README.md | 79 +++++++++ .../main.tf | 155 ++++++++++++++++++ .../outputs.tf | 142 ++++++++++++++++ .../variables.tf | 0 .../versions.tf | 10 ++ main.tf | 4 +- 6 files changed, 388 insertions(+), 2 deletions(-) create mode 100644 examples/redis-replication-group-with-cluster-replica/README.md create mode 100644 examples/redis-replication-group-with-cluster-replica/main.tf create mode 100644 examples/redis-replication-group-with-cluster-replica/outputs.tf create mode 100644 examples/redis-replication-group-with-cluster-replica/variables.tf create mode 100644 examples/redis-replication-group-with-cluster-replica/versions.tf diff --git a/examples/redis-replication-group-with-cluster-replica/README.md b/examples/redis-replication-group-with-cluster-replica/README.md new file mode 100644 index 0000000..58565af --- /dev/null +++ b/examples/redis-replication-group-with-cluster-replica/README.md @@ -0,0 +1,79 @@ +# ElastiCache example for Redis replication group with cluster replica + +Configuration in this directory creates a replication group with a cluster replica both in a single module and separate modules as well to show adding a cluster replica to an existing replication group. + +## Usage + +To run this example you need to execute: + +```bash +$ terraform init +$ terraform plan +$ terraform apply +``` + +Note that this example may create resources which will incur monetary charges on your AWS bill. Run `terraform destroy` when you no longer need these resources. + + +## Requirements + +| Name | Version | +|------|---------| +| [terraform](#requirement\_terraform) | >= 1.0 | +| [aws](#requirement\_aws) | >= 5.47 | + +## Providers + +| Name | Version | +|------|---------| +| [aws](#provider\_aws) | >= 5.47 | + +## Modules + +| Name | Source | Version | +|------|--------|---------| +| [cluster\_replica](#module\_cluster\_replica) | ../../ | n/a | +| [replication\_group](#module\_replication\_group) | ../../ | n/a | +| [replication\_group\_with\_cluster\_replica](#module\_replication\_group\_with\_cluster\_replica) | ../../ | n/a | +| [vpc](#module\_vpc) | terraform-aws-modules/vpc/aws | ~> 5.0 | + +## Resources + +| Name | Type | +|------|------| +| [aws_availability_zones.available](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/availability_zones) | data source | + +## Inputs + +No inputs. + +## Outputs + +| Name | Description | +|------|-------------| +| [cloudwatch\_log\_group\_arn](#output\_cloudwatch\_log\_group\_arn) | Arn of cloudwatch log group created | +| [cloudwatch\_log\_group\_name](#output\_cloudwatch\_log\_group\_name) | Name of cloudwatch log group created | +| [cluster\_address](#output\_cluster\_address) | (Memcached only) DNS name of the cache cluster without the port appended | +| [cluster\_arn](#output\_cluster\_arn) | The ARN of the ElastiCache Cluster | +| [cluster\_cache\_nodes](#output\_cluster\_cache\_nodes) | List of node objects including `id`, `address`, `port` and `availability_zone` | +| [cluster\_configuration\_endpoint](#output\_cluster\_configuration\_endpoint) | (Memcached only) Configuration endpoint to allow host discovery | +| [cluster\_engine\_version\_actual](#output\_cluster\_engine\_version\_actual) | Because ElastiCache pulls the latest minor or patch for a version, this attribute returns the running version of the cache engine | +| [global\_replication\_group\_arn](#output\_global\_replication\_group\_arn) | ARN of the created ElastiCache Global Replication Group | +| [global\_replication\_group\_engine\_version\_actual](#output\_global\_replication\_group\_engine\_version\_actual) | The full version number of the cache engine running on the members of this global replication group | +| [global\_replication\_group\_id](#output\_global\_replication\_group\_id) | ID of the ElastiCache Global Replication Group | +| [global\_replication\_group\_node\_groups](#output\_global\_replication\_group\_node\_groups) | Set of node groups (shards) on the global replication group | +| [parameter\_group\_arn](#output\_parameter\_group\_arn) | The AWS ARN associated with the parameter group | +| [parameter\_group\_id](#output\_parameter\_group\_id) | The ElastiCache parameter group name | +| [replication\_group\_arn](#output\_replication\_group\_arn) | ARN of the created ElastiCache Replication Group | +| [replication\_group\_coniguration\_endpoint\_address](#output\_replication\_group\_coniguration\_endpoint\_address) | Address of the replication group configuration endpoint when cluster mode is enabled | +| [replication\_group\_engine\_version\_actual](#output\_replication\_group\_engine\_version\_actual) | Because ElastiCache pulls the latest minor or patch for a version, this attribute returns the running version of the cache engine | +| [replication\_group\_id](#output\_replication\_group\_id) | ID of the ElastiCache Replication Group | +| [replication\_group\_member\_clusters](#output\_replication\_group\_member\_clusters) | Identifiers of all the nodes that are part of this replication group | +| [replication\_group\_primary\_endpoint\_address](#output\_replication\_group\_primary\_endpoint\_address) | Address of the endpoint for the primary node in the replication group, if the cluster mode is disabled | +| [replication\_group\_reader\_endpoint\_address](#output\_replication\_group\_reader\_endpoint\_address) | Address of the endpoint for the reader node in the replication group, if the cluster mode is disabled | +| [security\_group\_arn](#output\_security\_group\_arn) | Amazon Resource Name (ARN) of the security group | +| [security\_group\_id](#output\_security\_group\_id) | ID of the security group | +| [subnet\_group\_name](#output\_subnet\_group\_name) | The ElastiCache subnet group name | + + +Apache-2.0 Licensed. See [LICENSE](https://github.com/terraform-aws-modules/terraform-aws-elasticache/blob/master/LICENSE). diff --git a/examples/redis-replication-group-with-cluster-replica/main.tf b/examples/redis-replication-group-with-cluster-replica/main.tf new file mode 100644 index 0000000..c0e790e --- /dev/null +++ b/examples/redis-replication-group-with-cluster-replica/main.tf @@ -0,0 +1,155 @@ +provider "aws" { + region = local.region +} + +data "aws_availability_zones" "available" {} + +locals { + region = "eu-west-1" + name = "ex-${basename(path.cwd)}" + + vpc_cidr = "10.0.0.0/16" + azs = slice(data.aws_availability_zones.available.names, 0, 3) + + tags = { + Name = local.name + Example = local.name + Repository = "https://github.com/terraform-aws-modules/terraform-aws-elasticache" + } +} + +################################################################################ +# Replication Group with Cluster Replica (single module) +################################################################################ +module "replication_group_with_cluster_replica" { + source = "../../" + + cluster_id = "cluster" + create_cluster = true + create_replication_group = true + replication_group_id = "repl-grp-with-cluster-replica" + + log_delivery_configuration = { + slow-log = { + cloudwatch_log_group_name = "repl-grp-with-cluster-replica" + destination_type = "cloudwatch-logs" + log_format = "json" + } + } + + engine_version = "7.1" + node_type = "cache.t4g.small" + + maintenance_window = "sun:05:00-sun:09:00" + apply_immediately = true + + # Security Group + vpc_id = module.vpc.vpc_id + security_group_rules = { + ingress_vpc = { + # Default type is `ingress` + # Default port is based on the default engine port + description = "VPC traffic" + cidr_ipv4 = module.vpc.vpc_cidr_block + } + } + + # Subnet Group + subnet_group_name = "repl-grp-with-cluster-replica" + subnet_group_description = "repl-grp-with-cluster-replica subnet group" + subnet_ids = module.vpc.private_subnets + + # Parameter Group + create_parameter_group = true + parameter_group_name = "repl-grp-with-cluster-replica" + parameter_group_family = "redis7" + parameter_group_description = "repl-grp-with-cluster-replica parameter group" + parameters = [ + { + name = "latency-tracking" + value = "yes" + } + ] + + tags = local.tags +} + +################################################################################ +# Add Cluster Replica to Existing Replication Group (separate modules) +################################################################################ +module "replication_group" { + source = "../../" + + replication_group_id = "ex-replication-group" + + engine_version = "7.1" + node_type = "cache.t4g.small" + + transit_encryption_enabled = true + auth_token = "PickSomethingMoreSecure123!" + maintenance_window = "sun:05:00-sun:09:00" + apply_immediately = true + + # Security Group + vpc_id = module.vpc.vpc_id + security_group_rules = { + ingress_vpc = { + # Default type is `ingress` + # Default port is based on the default engine port + description = "VPC traffic" + cidr_ipv4 = module.vpc.vpc_cidr_block + } + } + + # Subnet Group + subnet_group_name = "ex-replication-group" + subnet_group_description = "${title(local.name)} subnet group" + subnet_ids = module.vpc.private_subnets + + # Parameter Group + create_parameter_group = true + parameter_group_name = "ex-replication-group" + parameter_group_family = "redis7" + parameter_group_description = "${title(local.name)} parameter group" + parameters = [ + { + name = "latency-tracking" + value = "yes" + } + ] + + tags = local.tags +} + +module "cluster_replica" { + source = "../../" + + cluster_id = "ex-cluster-replica" + create_cluster = true + cluster_mode_enabled = false + replication_group_id = module.replication_group.replication_group_id + create_replication_group = false + create_subnet_group = false + + log_delivery_configuration = { + create_cloudwatch_log_group = false + } +} + +################################################################################ +# Supporting Resources +################################################################################ + +module "vpc" { + source = "terraform-aws-modules/vpc/aws" + version = "~> 5.0" + + name = local.name + cidr = local.vpc_cidr + + azs = local.azs + public_subnets = [for k, v in local.azs : cidrsubnet(local.vpc_cidr, 8, k)] + private_subnets = [for k, v in local.azs : cidrsubnet(local.vpc_cidr, 8, k + 10)] + + tags = local.tags +} diff --git a/examples/redis-replication-group-with-cluster-replica/outputs.tf b/examples/redis-replication-group-with-cluster-replica/outputs.tf new file mode 100644 index 0000000..e15b230 --- /dev/null +++ b/examples/redis-replication-group-with-cluster-replica/outputs.tf @@ -0,0 +1,142 @@ +################################################################################ +# Cluster +################################################################################ + +output "cluster_arn" { + description = "The ARN of the ElastiCache Cluster" + value = module.replication_group_with_cluster_replica.cluster_arn +} + +output "cluster_engine_version_actual" { + description = "Because ElastiCache pulls the latest minor or patch for a version, this attribute returns the running version of the cache engine" + value = module.replication_group_with_cluster_replica.cluster_engine_version_actual +} + +output "cluster_cache_nodes" { + description = "List of node objects including `id`, `address`, `port` and `availability_zone`" + value = module.replication_group_with_cluster_replica.cluster_cache_nodes +} + +output "cluster_address" { + description = "(Memcached only) DNS name of the cache cluster without the port appended" + value = module.replication_group_with_cluster_replica.cluster_address +} + +output "cluster_configuration_endpoint" { + description = "(Memcached only) Configuration endpoint to allow host discovery" + value = module.replication_group_with_cluster_replica.cluster_configuration_endpoint +} + +################################################################################ +# Replication Group +################################################################################ + +output "replication_group_arn" { + description = "ARN of the created ElastiCache Replication Group" + value = module.replication_group_with_cluster_replica.replication_group_arn +} + +output "replication_group_engine_version_actual" { + description = "Because ElastiCache pulls the latest minor or patch for a version, this attribute returns the running version of the cache engine" + value = module.replication_group_with_cluster_replica.replication_group_engine_version_actual +} + +output "replication_group_coniguration_endpoint_address" { + description = "Address of the replication group configuration endpoint when cluster mode is enabled" + value = module.replication_group_with_cluster_replica.replication_group_coniguration_endpoint_address +} + +output "replication_group_id" { + description = "ID of the ElastiCache Replication Group" + value = module.replication_group_with_cluster_replica.replication_group_id +} + +output "replication_group_member_clusters" { + description = "Identifiers of all the nodes that are part of this replication group" + value = module.replication_group_with_cluster_replica.replication_group_member_clusters +} + +output "replication_group_primary_endpoint_address" { + description = "Address of the endpoint for the primary node in the replication group, if the cluster mode is disabled" + value = module.replication_group_with_cluster_replica.replication_group_primary_endpoint_address +} + +output "replication_group_reader_endpoint_address" { + description = "Address of the endpoint for the reader node in the replication group, if the cluster mode is disabled" + value = module.replication_group_with_cluster_replica.replication_group_reader_endpoint_address +} + +################################################################################ +# Global Replication Group +################################################################################ + +output "global_replication_group_id" { + description = "ID of the ElastiCache Global Replication Group" + value = module.replication_group_with_cluster_replica.global_replication_group_id +} + +output "global_replication_group_arn" { + description = "ARN of the created ElastiCache Global Replication Group" + value = module.replication_group_with_cluster_replica.global_replication_group_arn +} + +output "global_replication_group_engine_version_actual" { + description = "The full version number of the cache engine running on the members of this global replication group" + value = module.replication_group_with_cluster_replica.global_replication_group_engine_version_actual +} + +output "global_replication_group_node_groups" { + description = "Set of node groups (shards) on the global replication group" + value = module.replication_group_with_cluster_replica.global_replication_group_node_groups +} + +################################################################################ +# CloudWatch Log Group +################################################################################ + +output "cloudwatch_log_group_name" { + description = "Name of cloudwatch log group created" + value = module.replication_group_with_cluster_replica.cloudwatch_log_group_name +} + +output "cloudwatch_log_group_arn" { + description = "Arn of cloudwatch log group created" + value = module.replication_group_with_cluster_replica.cloudwatch_log_group_arn +} + +################################################################################ +# Parameter Group +################################################################################ + +output "parameter_group_arn" { + description = "The AWS ARN associated with the parameter group" + value = module.replication_group_with_cluster_replica.parameter_group_arn +} + +output "parameter_group_id" { + description = "The ElastiCache parameter group name" + value = module.replication_group_with_cluster_replica.parameter_group_id +} + +################################################################################ +# Subnet Group +################################################################################ + +output "subnet_group_name" { + description = "The ElastiCache subnet group name" + value = module.replication_group_with_cluster_replica.subnet_group_name +} + +################################################################################ +# Security Group +################################################################################ + +output "security_group_arn" { + description = "Amazon Resource Name (ARN) of the security group" + value = module.replication_group_with_cluster_replica.security_group_arn +} + +output "security_group_id" { + description = "ID of the security group" + value = module.replication_group_with_cluster_replica.security_group_id +} diff --git a/examples/redis-replication-group-with-cluster-replica/variables.tf b/examples/redis-replication-group-with-cluster-replica/variables.tf new file mode 100644 index 0000000..e69de29 diff --git a/examples/redis-replication-group-with-cluster-replica/versions.tf b/examples/redis-replication-group-with-cluster-replica/versions.tf new file mode 100644 index 0000000..407a955 --- /dev/null +++ b/examples/redis-replication-group-with-cluster-replica/versions.tf @@ -0,0 +1,10 @@ +terraform { + required_version = ">= 1.0" + + required_providers { + aws = { + source = "hashicorp/aws" + version = ">= 5.47" + } + } +} diff --git a/main.tf b/main.tf index b91055f..a4f6c95 100644 --- a/main.tf +++ b/main.tf @@ -20,13 +20,13 @@ resource "aws_elasticache_cluster" "this" { availability_zone = var.availability_zone az_mode = local.in_replication_group ? null : var.az_mode cluster_id = var.cluster_id - engine = var.engine + engine = local.in_replication_group ? null : var.engine engine_version = local.in_replication_group ? null : var.engine_version final_snapshot_identifier = var.final_snapshot_identifier ip_discovery = var.ip_discovery dynamic "log_delivery_configuration" { - for_each = { for k, v in var.log_delivery_configuration : k => v if var.engine != "memcached" } + for_each = { for k, v in var.log_delivery_configuration : k => v if var.engine != "memcached" && !local.in_replication_group } content { destination = try(log_delivery_configuration.value.create_cloudwatch_log_group, true) && log_delivery_configuration.value.destination_type == "cloudwatch-logs" ? aws_cloudwatch_log_group.this[log_delivery_configuration.key].name : log_delivery_configuration.value.destination From 575c3125c7b9af352030dfc07599896332c308f9 Mon Sep 17 00:00:00 2001 From: semantic-release-bot Date: Sun, 4 Aug 2024 13:36:36 +0000 Subject: [PATCH 2/2] chore(release): version 1.2.2 [skip ci] ## [1.2.2](https://github.com/terraform-aws-modules/terraform-aws-elasticache/compare/v1.2.1...v1.2.2) (2024-08-04) ### Bug Fixes * Argument `replication_group_id` conflicts with `engine` and `log_delivery_configuration` ([#10](https://github.com/terraform-aws-modules/terraform-aws-elasticache/issues/10)) ([97bc4b5](https://github.com/terraform-aws-modules/terraform-aws-elasticache/commit/97bc4b5dbab8d2ea78ffd6aaf5716ab271f11f59)) --- CHANGELOG.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7cdca13..6c308cc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,13 @@ All notable changes to this project will be documented in this file. +## [1.2.2](https://github.com/terraform-aws-modules/terraform-aws-elasticache/compare/v1.2.1...v1.2.2) (2024-08-04) + + +### Bug Fixes + +* Argument `replication_group_id` conflicts with `engine` and `log_delivery_configuration` ([#10](https://github.com/terraform-aws-modules/terraform-aws-elasticache/issues/10)) ([97bc4b5](https://github.com/terraform-aws-modules/terraform-aws-elasticache/commit/97bc4b5dbab8d2ea78ffd6aaf5716ab271f11f59)) + ## [1.2.1](https://github.com/terraform-aws-modules/terraform-aws-elasticache/compare/v1.2.0...v1.2.1) (2024-08-03)