diff --git a/.github/workflows/pr-title.yml b/.github/workflows/pr-title.yml index 3973df4..1e50760 100644 --- a/.github/workflows/pr-title.yml +++ b/.github/workflows/pr-title.yml @@ -14,7 +14,7 @@ jobs: steps: # Please look up the latest version from # https://github.com/amannn/action-semantic-pull-request/releases - - uses: amannn/action-semantic-pull-request@v5.4.0 + - uses: amannn/action-semantic-pull-request@v5.5.3 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml index c2632d1..a19ff83 100644 --- a/.github/workflows/pre-commit.yml +++ b/.github/workflows/pre-commit.yml @@ -7,8 +7,8 @@ on: - master env: - TERRAFORM_DOCS_VERSION: v0.16.0 - TFLINT_VERSION: v0.50.3 + TERRAFORM_DOCS_VERSION: v0.19.0 + TFLINT_VERSION: v0.53.0 jobs: collectInputs: @@ -45,14 +45,14 @@ jobs: - name: Terraform min/max versions id: minMax - uses: clowdhaus/terraform-min-max@v1.3.0 + uses: clowdhaus/terraform-min-max@v1.3.1 with: directory: ${{ matrix.directory }} - name: Pre-commit Terraform ${{ steps.minMax.outputs.minVersion }} # Run only validate pre-commit check on min version supported if: ${{ matrix.directory != '.' }} - uses: clowdhaus/terraform-composite-actions/pre-commit@v1.9.0 + uses: clowdhaus/terraform-composite-actions/pre-commit@v1.11.1 with: terraform-version: ${{ steps.minMax.outputs.minVersion }} tflint-version: ${{ env.TFLINT_VERSION }} @@ -61,7 +61,7 @@ jobs: - name: Pre-commit Terraform ${{ steps.minMax.outputs.minVersion }} # Run only validate pre-commit check on min version supported if: ${{ matrix.directory == '.' }} - uses: clowdhaus/terraform-composite-actions/pre-commit@v1.9.0 + uses: clowdhaus/terraform-composite-actions/pre-commit@v1.11.1 with: terraform-version: ${{ steps.minMax.outputs.minVersion }} tflint-version: ${{ env.TFLINT_VERSION }} @@ -88,10 +88,10 @@ jobs: - name: Terraform min/max versions id: minMax - uses: clowdhaus/terraform-min-max@v1.3.0 + uses: clowdhaus/terraform-min-max@v1.3.1 - name: Pre-commit Terraform ${{ steps.minMax.outputs.maxVersion }} - uses: clowdhaus/terraform-composite-actions/pre-commit@v1.9.0 + uses: clowdhaus/terraform-composite-actions/pre-commit@v1.11.1 with: terraform-version: ${{ steps.minMax.outputs.maxVersion }} tflint-version: ${{ env.TFLINT_VERSION }} diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index ade44ff..a6cd369 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,6 +1,6 @@ repos: - repo: https://github.com/antonbabenko/pre-commit-terraform - rev: v1.88.2 + rev: v1.96.1 hooks: - id: terraform_fmt - id: terraform_docs @@ -21,10 +21,9 @@ repos: - '--args=--only=terraform_required_providers' - '--args=--only=terraform_standard_module_structure' - '--args=--only=terraform_workspace_remote' - - '--args=--only=terraform_unused_required_providers' - id: terraform_validate - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.5.0 + rev: v5.0.0 hooks: - id: check-merge-conflict - id: end-of-file-fixer diff --git a/CHANGELOG.md b/CHANGELOG.md index 7cdca13..afcc12d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,67 @@ All notable changes to this project will be documented in this file. +## [1.6.0](https://github.com/terraform-aws-modules/terraform-aws-elasticache/compare/v1.5.0...v1.6.0) (2025-03-30) + + +### Features + +* Set `create_before_destroy` on subnet group ([#29](https://github.com/terraform-aws-modules/terraform-aws-elasticache/issues/29)) ([9133f1e](https://github.com/terraform-aws-modules/terraform-aws-elasticache/commit/9133f1ec80c4cefef8dd5a763f6f6d9e4526276e)) + +## [1.5.0](https://github.com/terraform-aws-modules/terraform-aws-elasticache/compare/v1.4.1...v1.5.0) (2025-03-29) + + +### Features + +* Add elasticache cluster timeouts ([#33](https://github.com/terraform-aws-modules/terraform-aws-elasticache/issues/33)) ([41e5c75](https://github.com/terraform-aws-modules/terraform-aws-elasticache/commit/41e5c75b2ea15a8631f8bb9f7f73ad5d868eeddf)) + +## [1.4.1](https://github.com/terraform-aws-modules/terraform-aws-elasticache/compare/v1.4.0...v1.4.1) (2024-12-02) + + +### Bug Fixes + +* Change cloudwatch log group output to include all created log groups ([#19](https://github.com/terraform-aws-modules/terraform-aws-elasticache/issues/19)) ([cdc870e](https://github.com/terraform-aws-modules/terraform-aws-elasticache/commit/cdc870e425fd34a93f3e38adccf8eb4c8fd1ef1a)) + +## [1.4.0](https://github.com/terraform-aws-modules/terraform-aws-elasticache/compare/v1.3.0...v1.4.0) (2024-11-29) + + +### Features + +* Support Valkey ([#26](https://github.com/terraform-aws-modules/terraform-aws-elasticache/issues/26)) ([6b1b5aa](https://github.com/terraform-aws-modules/terraform-aws-elasticache/commit/6b1b5aa4576942bad13a6c8a8420e958a7327fad)) + +## [1.3.0](https://github.com/terraform-aws-modules/terraform-aws-elasticache/compare/v1.2.4...v1.3.0) (2024-10-17) + + +### Features + +* Support `aws_elasticache_user_group_association.timeouts` and `aws_elasticache_replication_group.cluster_mode` ([#21](https://github.com/terraform-aws-modules/terraform-aws-elasticache/issues/21)) ([1135640](https://github.com/terraform-aws-modules/terraform-aws-elasticache/commit/1135640455df0ee16ef76bb5b0c6c3f069483b98)) + + +### Bug Fixes + +* Update CI workflow versions to latest ([#20](https://github.com/terraform-aws-modules/terraform-aws-elasticache/issues/20)) ([1bd81be](https://github.com/terraform-aws-modules/terraform-aws-elasticache/commit/1bd81beec317d4b05fc847c4e3b41bbbcc8460ea)) + +## [1.2.4](https://github.com/terraform-aws-modules/terraform-aws-elasticache/compare/v1.2.3...v1.2.4) (2024-10-01) + + +### Bug Fixes + +* Correct output attribute mis-spelling ([#18](https://github.com/terraform-aws-modules/terraform-aws-elasticache/issues/18)) ([a4940aa](https://github.com/terraform-aws-modules/terraform-aws-elasticache/commit/a4940aa5d8d3f6f9427c050c57b4cda90bf09856)) + +## [1.2.3](https://github.com/terraform-aws-modules/terraform-aws-elasticache/compare/v1.2.2...v1.2.3) (2024-09-09) + + +### Bug Fixes + +* Fix cache_usage_limits issue when empty map (default value) is provided. ([#13](https://github.com/terraform-aws-modules/terraform-aws-elasticache/issues/13)) ([2a02a2c](https://github.com/terraform-aws-modules/terraform-aws-elasticache/commit/2a02a2cf0fa4d62cee9a56f5be727b1bab7808cd)) + +## [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) diff --git a/README.md b/README.md index 9444046..e437ed6 100644 --- a/README.md +++ b/README.md @@ -268,6 +268,86 @@ module "elasticache" { } ``` +### Serverless Cache + +```hcl +module "elasticache" { + source = "terraform-aws-modules/elasticache/aws//modules/serverless-cache" + + engine = "redis" + cache_name = "example-serverless-cache" + + cache_usage_limits = { + data_storage = { + maximum = 2 + } + ecpu_per_second = { + maximum = 1000 + } + } + + daily_snapshot_time = "22:00" + description = "example-serverless-cache serverless cluster" + kms_key_id = aws_kms_key.this.arn + major_engine_version = "7" + security_group_ids = [module.sg.security_group_id] + + snapshot_retention_limit = 7 + subnet_ids = module.vpc.private_subnets + + user_group_id = module.cache_user_group.group_id +} +``` + +### Valkey Replication Group + +```hcl +module "elasticache" { + source = "terraform-aws-modules/elasticache/aws" + + replication_group_id = local.name + + engine = "valkey" + engine_version = "7.2" + 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 = local.name + subnet_group_description = "Valkey replication group subnet group" + subnet_ids = module.vpc.private_subnets + + # Parameter Group + create_parameter_group = true + parameter_group_name = local.name + parameter_group_family = "valkey7" + parameter_group_description = "Valkey replication group parameter group" + parameters = [ + { + name = "latency-tracking" + value = "yes" + } + ] + + tags = local.tags +} +``` + ## Examples Examples codified under the [`examples`](https://github.com/terraform-aws-modules/terraform-aws-elasticache/tree/master/examples) are intended to give users references for how to use the module(s) as well as testing/validating changes to the source code of the module. If contributing to the project, please be sure to make any appropriate updates to the relevant examples to allow maintainers to test your changes and to keep the examples up to date for users. Thank you! @@ -277,21 +357,23 @@ Examples codified under the [`examples`](https://github.com/terraform-aws-module - [Redis Cluster Mode](https://github.com/terraform-aws-modules/terraform-aws-elasticache/tree/master/examples/redis-cluster-mode) - [Redis Global Replication Group](https://github.com/terraform-aws-modules/terraform-aws-elasticache/tree/master/examples/redis-global-replication-group) - [Redis Replication Group](https://github.com/terraform-aws-modules/terraform-aws-elasticache/tree/master/examples/redis-replication-group) +- [Serverless Cache](https://github.com/terraform-aws-modules/terraform-aws-elasticache/tree/master/examples/serverless-cache) +- [Valkey Replication Group](https://github.com/terraform-aws-modules/terraform-aws-elasticache/tree/master/examples/valkey-replication-group) - + ## Requirements | Name | Version | |------|---------| | [terraform](#requirement\_terraform) | >= 1.0 | -| [aws](#requirement\_aws) | >= 5.47 | +| [aws](#requirement\_aws) | >= 5.93 | | [random](#requirement\_random) | >= 3.0 | ## Providers | Name | Version | |------|---------| -| [aws](#provider\_aws) | >= 5.47 | +| [aws](#provider\_aws) | >= 5.93 | | [random](#provider\_random) | >= 3.0 | ## Modules @@ -322,11 +404,12 @@ No modules. | [at\_rest\_encryption\_enabled](#input\_at\_rest\_encryption\_enabled) | Whether to enable encryption at rest | `bool` | `true` | no | | [auth\_token](#input\_auth\_token) | The password used to access a password protected server. Can be specified only if `transit_encryption_enabled = true` | `string` | `null` | no | | [auth\_token\_update\_strategy](#input\_auth\_token\_update\_strategy) | Strategy to use when updating the `auth_token`. Valid values are `SET`, `ROTATE`, and `DELETE`. Defaults to `ROTATE` | `string` | `null` | no | -| [auto\_minor\_version\_upgrade](#input\_auto\_minor\_version\_upgrade) | Specifies whether minor version engine upgrades will be applied automatically to the underlying Cache Cluster instances during the maintenance window. Only supported for engine type `redis` and if the engine version is 6 or higher. Defaults to `true` | `bool` | `null` | no | +| [auto\_minor\_version\_upgrade](#input\_auto\_minor\_version\_upgrade) | Specifies whether minor version engine upgrades will be applied automatically to the underlying Cache Cluster instances during the maintenance window. Only supported for engine type `redis` and `valkey` and if the engine version is 6 or higher. Defaults to `true` | `bool` | `null` | no | | [automatic\_failover\_enabled](#input\_automatic\_failover\_enabled) | Specifies whether a read-only replica will be automatically promoted to read/write primary if the existing primary fails. If true, Multi-AZ is enabled for this replication group. If false, Multi-AZ is disabled for this replication group. Must be enabled for Redis (cluster mode enabled) replication groups | `bool` | `null` | no | | [availability\_zone](#input\_availability\_zone) | Availability Zone for the cache cluster. If you want to create cache nodes in multi-az, use `preferred_availability_zones` instead | `string` | `null` | no | | [az\_mode](#input\_az\_mode) | Whether the nodes in this Memcached node group are created in a single Availability Zone or created across multiple Availability Zones in the cluster's region. Valid values for this parameter are `single-az` or `cross-az`, default is `single-az` | `string` | `null` | no | | [cluster\_id](#input\_cluster\_id) | Group identifier. ElastiCache converts this name to lowercase. Changing this value will re-create the resource | `string` | `""` | no | +| [cluster\_mode](#input\_cluster\_mode) | Specifies whether cluster mode is enabled or disabled. Valid values are enabled or disabled or compatible | `string` | `null` | no | | [cluster\_mode\_enabled](#input\_cluster\_mode\_enabled) | Whether to enable Redis [cluster mode https://docs.aws.amazon.com/AmazonElastiCache/latest/red-ug/Replication.Redis-RedisCluster.html] | `bool` | `false` | no | | [create](#input\_create) | Determines whether resources will be created (affects all resources) | `bool` | `true` | no | | [create\_cluster](#input\_create\_cluster) | Determines whether an ElastiCache cluster will be created or not | `bool` | `false` | no | @@ -338,13 +421,13 @@ No modules. | [create\_subnet\_group](#input\_create\_subnet\_group) | Determines whether the Elasticache subnet group will be created or not | `bool` | `true` | no | | [data\_tiering\_enabled](#input\_data\_tiering\_enabled) | Enables data tiering. Data tiering is only supported for replication groups using the `r6gd` node type. This parameter must be set to true when using `r6gd` nodes | `bool` | `null` | no | | [description](#input\_description) | User-created description for the replication group | `string` | `null` | no | -| [engine](#input\_engine) | Name of the cache engine to be used for this cache cluster. Valid values are `memcached` or `redis` | `string` | `"redis"` | no | +| [engine](#input\_engine) | Name of the cache engine to be used for this cache cluster. Valid values are `memcached`, `redis`, or `valkey` | `string` | `"redis"` | no | | [engine\_version](#input\_engine\_version) | Version number of the cache engine to be used. If not set, defaults to the latest version | `string` | `null` | no | | [final\_snapshot\_identifier](#input\_final\_snapshot\_identifier) | (Redis only) Name of your final cluster snapshot. If omitted, no final snapshot will be made | `string` | `null` | no | | [global\_replication\_group\_id](#input\_global\_replication\_group\_id) | The ID of the global replication group to which this replication group should belong | `string` | `null` | no | | [ip\_discovery](#input\_ip\_discovery) | The IP version to advertise in the discovery protocol. Valid values are `ipv4` or `ipv6` | `string` | `null` | no | | [kms\_key\_arn](#input\_kms\_key\_arn) | The ARN of the key that you wish to use if encrypting at rest. If not supplied, uses service managed encryption. Can be specified only if `at_rest_encryption_enabled = true` | `string` | `null` | no | -| [log\_delivery\_configuration](#input\_log\_delivery\_configuration) | (Redis only) Specifies the destination and format of Redis SLOWLOG or Redis Engine Log | `any` |
{| no | +| [log\_delivery\_configuration](#input\_log\_delivery\_configuration) | (Redis OSS or Valkey) Specifies the destination and format of Redis OSS/Valkey SLOWLOG or Redis OSS/Valkey Engine Log | `any` |
"slow-log": {
"destination_type": "cloudwatch-logs",
"log_format": "json"
}
}
{| no | | [maintenance\_window](#input\_maintenance\_window) | Specifies the weekly time range for when maintenance on the cache cluster is performed. The format is `ddd:hh24:mi-ddd:hh24:mi` (24H Clock UTC) | `string` | `null` | no | | [multi\_az\_enabled](#input\_multi\_az\_enabled) | Specifies whether to enable Multi-AZ Support for the replication group. If true, `automatic_failover_enabled` must also be enabled. Defaults to `false` | `bool` | `false` | no | | [network\_type](#input\_network\_type) | The IP versions for cache cluster connections. Valid values are `ipv4`, `ipv6` or `dual_stack` | `string` | `null` | no | @@ -379,6 +462,7 @@ No modules. | [subnet\_group\_name](#input\_subnet\_group\_name) | The name of the subnet group. If `create_subnet_group` is `true`, this is the name assigned to the subnet group created. Otherwise, this is the name of an existing subnet group | `string` | `null` | no | | [subnet\_ids](#input\_subnet\_ids) | List of VPC Subnet IDs for the Elasticache subnet group | `list(string)` | `[]` | no | | [tags](#input\_tags) | A map of tags to add to all resources | `map(string)` | `{}` | no | +| [timeouts](#input\_timeouts) | Define maximum timeout for creating, updating, and deleting cluster resource | `map(string)` | `{}` | no | | [transit\_encryption\_enabled](#input\_transit\_encryption\_enabled) | Enable encryption in-transit. Supported only with Memcached versions `1.6.12` and later, running in a VPC | `bool` | `true` | no | | [transit\_encryption\_mode](#input\_transit\_encryption\_mode) | A setting that enables clients to migrate to in-transit encryption with no downtime. Valid values are preferred and required | `string` | `null` | no | | [user\_group\_ids](#input\_user\_group\_ids) | User Group ID to associate with the replication group. Only a maximum of one (1) user group ID is valid | `list(string)` | `null` | no | @@ -390,6 +474,7 @@ No modules. |------|-------------| | [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 | +| [cloudwatch\_log\_groups](#output\_cloudwatch\_log\_groups) | Map of CloudWatch log groups created and their attributes | | [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` | @@ -402,7 +487,7 @@ No modules. | [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\_configuration\_endpoint\_address](#output\_replication\_group\_configuration\_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 | @@ -411,7 +496,7 @@ No modules. | [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 | - + ## License diff --git a/examples/memcached-cluster/README.md b/examples/memcached-cluster/README.md index bdd38fb..7c93f16 100644 --- a/examples/memcached-cluster/README.md +++ b/examples/memcached-cluster/README.md @@ -14,19 +14,19 @@ $ 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 | +| [aws](#requirement\_aws) | >= 5.73 | ## Providers | Name | Version | |------|---------| -| [aws](#provider\_aws) | >= 5.47 | +| [aws](#provider\_aws) | >= 5.73 | ## Modules @@ -50,8 +50,7 @@ No inputs. | 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 | +| [cloudwatch\_log\_groups](#output\_cloudwatch\_log\_groups) | Map of CloudWatch log groups created and their attributes | | [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` | @@ -64,7 +63,7 @@ No inputs. | [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\_configuration\_endpoint\_address](#output\_replication\_group\_configuration\_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 | @@ -73,6 +72,6 @@ No inputs. | [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/memcached-cluster/outputs.tf b/examples/memcached-cluster/outputs.tf index cd5faef..ccf51c7 100644 --- a/examples/memcached-cluster/outputs.tf +++ b/examples/memcached-cluster/outputs.tf @@ -41,9 +41,9 @@ output "replication_group_engine_version_actual" { value = module.elasticache.replication_group_engine_version_actual } -output "replication_group_coniguration_endpoint_address" { +output "replication_group_configuration_endpoint_address" { description = "Address of the replication group configuration endpoint when cluster mode is enabled" - value = module.elasticache.replication_group_coniguration_endpoint_address + value = module.elasticache.replication_group_configuration_endpoint_address } output "replication_group_id" { @@ -94,14 +94,9 @@ output "global_replication_group_node_groups" { # CloudWatch Log Group ################################################################################ -output "cloudwatch_log_group_name" { - description = "Name of cloudwatch log group created" - value = module.elasticache.cloudwatch_log_group_name -} - -output "cloudwatch_log_group_arn" { - description = "Arn of cloudwatch log group created" - value = module.elasticache.cloudwatch_log_group_arn +output "cloudwatch_log_groups" { + description = "Map of CloudWatch log groups created and their attributes" + value = module.elasticache.cloudwatch_log_groups } ################################################################################ diff --git a/examples/memcached-cluster/versions.tf b/examples/memcached-cluster/versions.tf index 407a955..0f48a6c 100644 --- a/examples/memcached-cluster/versions.tf +++ b/examples/memcached-cluster/versions.tf @@ -4,7 +4,7 @@ terraform { required_providers { aws = { source = "hashicorp/aws" - version = ">= 5.47" + version = ">= 5.73" } } } diff --git a/examples/redis-cluster-mode/README.md b/examples/redis-cluster-mode/README.md index d6b4f87..8453466 100644 --- a/examples/redis-cluster-mode/README.md +++ b/examples/redis-cluster-mode/README.md @@ -16,19 +16,19 @@ $ 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 | +| [aws](#requirement\_aws) | >= 5.73 | ## Providers | Name | Version | |------|---------| -| [aws](#provider\_aws) | >= 5.47 | +| [aws](#provider\_aws) | >= 5.73 | ## Modules @@ -52,8 +52,7 @@ No inputs. | 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 | +| [cloudwatch\_log\_groups](#output\_cloudwatch\_log\_groups) | Map of CloudWatch log groups created and their attributes | | [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` | @@ -66,7 +65,7 @@ No inputs. | [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\_configuration\_endpoint\_address](#output\_replication\_group\_configuration\_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 | @@ -75,6 +74,6 @@ No inputs. | [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-cluster-mode/outputs.tf b/examples/redis-cluster-mode/outputs.tf index cd5faef..ccf51c7 100644 --- a/examples/redis-cluster-mode/outputs.tf +++ b/examples/redis-cluster-mode/outputs.tf @@ -41,9 +41,9 @@ output "replication_group_engine_version_actual" { value = module.elasticache.replication_group_engine_version_actual } -output "replication_group_coniguration_endpoint_address" { +output "replication_group_configuration_endpoint_address" { description = "Address of the replication group configuration endpoint when cluster mode is enabled" - value = module.elasticache.replication_group_coniguration_endpoint_address + value = module.elasticache.replication_group_configuration_endpoint_address } output "replication_group_id" { @@ -94,14 +94,9 @@ output "global_replication_group_node_groups" { # CloudWatch Log Group ################################################################################ -output "cloudwatch_log_group_name" { - description = "Name of cloudwatch log group created" - value = module.elasticache.cloudwatch_log_group_name -} - -output "cloudwatch_log_group_arn" { - description = "Arn of cloudwatch log group created" - value = module.elasticache.cloudwatch_log_group_arn +output "cloudwatch_log_groups" { + description = "Map of CloudWatch log groups created and their attributes" + value = module.elasticache.cloudwatch_log_groups } ################################################################################ diff --git a/examples/redis-cluster-mode/versions.tf b/examples/redis-cluster-mode/versions.tf index 407a955..0f48a6c 100644 --- a/examples/redis-cluster-mode/versions.tf +++ b/examples/redis-cluster-mode/versions.tf @@ -4,7 +4,7 @@ terraform { required_providers { aws = { source = "hashicorp/aws" - version = ">= 5.47" + version = ">= 5.73" } } } diff --git a/examples/redis-cluster/README.md b/examples/redis-cluster/README.md index 4a01212..7afc24d 100644 --- a/examples/redis-cluster/README.md +++ b/examples/redis-cluster/README.md @@ -14,19 +14,19 @@ $ 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 | +| [aws](#requirement\_aws) | >= 5.73 | ## Providers | Name | Version | |------|---------| -| [aws](#provider\_aws) | >= 5.47 | +| [aws](#provider\_aws) | >= 5.73 | ## Modules @@ -50,8 +50,7 @@ No inputs. | 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 | +| [cloudwatch\_log\_groups](#output\_cloudwatch\_log\_groups) | Map of CloudWatch log groups created and their attributes | | [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` | @@ -64,7 +63,7 @@ No inputs. | [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\_configuration\_endpoint\_address](#output\_replication\_group\_configuration\_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 | @@ -73,6 +72,6 @@ No inputs. | [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-cluster/main.tf b/examples/redis-cluster/main.tf index d2fa6fc..9e1e504 100644 --- a/examples/redis-cluster/main.tf +++ b/examples/redis-cluster/main.tf @@ -64,6 +64,12 @@ module "elasticache" { ] tags = local.tags + + timeouts = { + create = "1h" + update = "2h" + delete = "1h" + } } module "elasticache_disabled" { diff --git a/examples/redis-cluster/outputs.tf b/examples/redis-cluster/outputs.tf index cd5faef..ccf51c7 100644 --- a/examples/redis-cluster/outputs.tf +++ b/examples/redis-cluster/outputs.tf @@ -41,9 +41,9 @@ output "replication_group_engine_version_actual" { value = module.elasticache.replication_group_engine_version_actual } -output "replication_group_coniguration_endpoint_address" { +output "replication_group_configuration_endpoint_address" { description = "Address of the replication group configuration endpoint when cluster mode is enabled" - value = module.elasticache.replication_group_coniguration_endpoint_address + value = module.elasticache.replication_group_configuration_endpoint_address } output "replication_group_id" { @@ -94,14 +94,9 @@ output "global_replication_group_node_groups" { # CloudWatch Log Group ################################################################################ -output "cloudwatch_log_group_name" { - description = "Name of cloudwatch log group created" - value = module.elasticache.cloudwatch_log_group_name -} - -output "cloudwatch_log_group_arn" { - description = "Arn of cloudwatch log group created" - value = module.elasticache.cloudwatch_log_group_arn +output "cloudwatch_log_groups" { + description = "Map of CloudWatch log groups created and their attributes" + value = module.elasticache.cloudwatch_log_groups } ################################################################################ diff --git a/examples/redis-cluster/versions.tf b/examples/redis-cluster/versions.tf index 407a955..0f48a6c 100644 --- a/examples/redis-cluster/versions.tf +++ b/examples/redis-cluster/versions.tf @@ -4,7 +4,7 @@ terraform { required_providers { aws = { source = "hashicorp/aws" - version = ">= 5.47" + version = ">= 5.73" } } } diff --git a/examples/redis-global-replication-group/README.md b/examples/redis-global-replication-group/README.md index 118361a..f512f47 100644 --- a/examples/redis-global-replication-group/README.md +++ b/examples/redis-global-replication-group/README.md @@ -18,20 +18,20 @@ $ 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 | +| [aws](#requirement\_aws) | >= 5.73 | ## Providers | Name | Version | |------|---------| -| [aws](#provider\_aws) | >= 5.47 | -| [aws.euwest1](#provider\_aws.euwest1) | >= 5.47 | +| [aws](#provider\_aws) | >= 5.73 | +| [aws.euwest1](#provider\_aws.euwest1) | >= 5.73 | ## Modules @@ -57,8 +57,7 @@ No inputs. | 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 | +| [cloudwatch\_log\_groups](#output\_cloudwatch\_log\_groups) | Map of CloudWatch log groups created and their attributes | | [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` | @@ -71,7 +70,7 @@ No inputs. | [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\_configuration\_endpoint\_address](#output\_replication\_group\_configuration\_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 | @@ -80,6 +79,6 @@ No inputs. | [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-global-replication-group/outputs.tf b/examples/redis-global-replication-group/outputs.tf index bde8c9d..85300ce 100644 --- a/examples/redis-global-replication-group/outputs.tf +++ b/examples/redis-global-replication-group/outputs.tf @@ -41,9 +41,9 @@ output "replication_group_engine_version_actual" { value = module.elasticache_primary.replication_group_engine_version_actual } -output "replication_group_coniguration_endpoint_address" { +output "replication_group_configuration_endpoint_address" { description = "Address of the replication group configuration endpoint when cluster mode is enabled" - value = module.elasticache_primary.replication_group_coniguration_endpoint_address + value = module.elasticache_primary.replication_group_configuration_endpoint_address } output "replication_group_id" { @@ -94,14 +94,9 @@ output "global_replication_group_node_groups" { # CloudWatch Log Group ################################################################################ -output "cloudwatch_log_group_name" { - description = "Name of cloudwatch log group created" - value = module.elasticache_primary.cloudwatch_log_group_name -} - -output "cloudwatch_log_group_arn" { - description = "Arn of cloudwatch log group created" - value = module.elasticache_primary.cloudwatch_log_group_arn +output "cloudwatch_log_groups" { + description = "Map of CloudWatch log groups created and their attributes" + value = module.elasticache_primary.cloudwatch_log_groups } ################################################################################ diff --git a/examples/redis-global-replication-group/versions.tf b/examples/redis-global-replication-group/versions.tf index 407a955..0f48a6c 100644 --- a/examples/redis-global-replication-group/versions.tf +++ b/examples/redis-global-replication-group/versions.tf @@ -4,7 +4,7 @@ terraform { required_providers { aws = { source = "hashicorp/aws" - version = ">= 5.47" + version = ">= 5.73" } } } 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..48f8674 --- /dev/null +++ b/examples/redis-replication-group-with-cluster-replica/README.md @@ -0,0 +1,78 @@ +# 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.73 | + +## Providers + +| Name | Version | +|------|---------| +| [aws](#provider\_aws) | >= 5.73 | + +## 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\_groups](#output\_cloudwatch\_log\_groups) | Map of CloudWatch log groups created and their attributes | +| [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\_configuration\_endpoint\_address](#output\_replication\_group\_configuration\_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..c649115 --- /dev/null +++ b/examples/redis-replication-group-with-cluster-replica/outputs.tf @@ -0,0 +1,137 @@ +################################################################################ +# 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_configuration_endpoint_address" { + description = "Address of the replication group configuration endpoint when cluster mode is enabled" + value = module.replication_group_with_cluster_replica.replication_group_configuration_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_groups" { + description = "Map of CloudWatch log groups created and their attributes" + value = module.replication_group_with_cluster_replica.cloudwatch_log_groups +} + +################################################################################ +# 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..0f48a6c --- /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.73" + } + } +} diff --git a/examples/redis-replication-group/README.md b/examples/redis-replication-group/README.md index fa179db..e4e2312 100644 --- a/examples/redis-replication-group/README.md +++ b/examples/redis-replication-group/README.md @@ -14,19 +14,19 @@ $ 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 | +| [aws](#requirement\_aws) | >= 5.73 | ## Providers | Name | Version | |------|---------| -| [aws](#provider\_aws) | >= 5.47 | +| [aws](#provider\_aws) | >= 5.73 | ## Modules @@ -49,8 +49,7 @@ No inputs. | 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 | +| [cloudwatch\_log\_groups](#output\_cloudwatch\_log\_groups) | Map of CloudWatch log groups created and their attributes | | [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` | @@ -63,7 +62,7 @@ No inputs. | [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\_configuration\_endpoint\_address](#output\_replication\_group\_configuration\_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 | @@ -72,6 +71,6 @@ No inputs. | [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/outputs.tf b/examples/redis-replication-group/outputs.tf index cd5faef..ccf51c7 100644 --- a/examples/redis-replication-group/outputs.tf +++ b/examples/redis-replication-group/outputs.tf @@ -41,9 +41,9 @@ output "replication_group_engine_version_actual" { value = module.elasticache.replication_group_engine_version_actual } -output "replication_group_coniguration_endpoint_address" { +output "replication_group_configuration_endpoint_address" { description = "Address of the replication group configuration endpoint when cluster mode is enabled" - value = module.elasticache.replication_group_coniguration_endpoint_address + value = module.elasticache.replication_group_configuration_endpoint_address } output "replication_group_id" { @@ -94,14 +94,9 @@ output "global_replication_group_node_groups" { # CloudWatch Log Group ################################################################################ -output "cloudwatch_log_group_name" { - description = "Name of cloudwatch log group created" - value = module.elasticache.cloudwatch_log_group_name -} - -output "cloudwatch_log_group_arn" { - description = "Arn of cloudwatch log group created" - value = module.elasticache.cloudwatch_log_group_arn +output "cloudwatch_log_groups" { + description = "Map of CloudWatch log groups created and their attributes" + value = module.elasticache.cloudwatch_log_groups } ################################################################################ diff --git a/examples/redis-replication-group/versions.tf b/examples/redis-replication-group/versions.tf index 407a955..0f48a6c 100644 --- a/examples/redis-replication-group/versions.tf +++ b/examples/redis-replication-group/versions.tf @@ -4,7 +4,7 @@ terraform { required_providers { aws = { source = "hashicorp/aws" - version = ">= 5.47" + version = ">= 5.73" } } } diff --git a/examples/serverless-cache/main.tf b/examples/serverless-cache/main.tf index aa29dd4..6a0a9d7 100644 --- a/examples/serverless-cache/main.tf +++ b/examples/serverless-cache/main.tf @@ -45,6 +45,33 @@ module "serverless" { user_group_id = module.cache_user_group.group_id } +module "valkey_serverless" { + source = "../../modules/serverless-cache" + + engine = "valkey" + cache_name = "${local.name}-valkey" + + cache_usage_limits = { + data_storage = { + maximum = 2 + } + ecpu_per_second = { + maximum = 1000 + } + } + + daily_snapshot_time = "22:00" + description = "${local.name} valkey serverless cluster" + kms_key_id = aws_kms_key.this.arn + major_engine_version = "7" + security_group_ids = [module.sg.security_group_id] + + snapshot_retention_limit = 7 + subnet_ids = module.vpc.private_subnets + + user_group_id = module.cache_user_group.group_id +} + module "cache_user_group" { source = "../../modules/user-group" @@ -63,6 +90,9 @@ module "cache_user_group" { authentication_mode = { type = "no-password-required" } + timeouts = { + create = "20m" + } } } diff --git a/examples/serverless-cache/versions.tf b/examples/serverless-cache/versions.tf index 407a955..0f48a6c 100644 --- a/examples/serverless-cache/versions.tf +++ b/examples/serverless-cache/versions.tf @@ -4,7 +4,7 @@ terraform { required_providers { aws = { source = "hashicorp/aws" - version = ">= 5.47" + version = ">= 5.73" } } } diff --git a/examples/valkey-replication-group/README.md b/examples/valkey-replication-group/README.md new file mode 100644 index 0000000..6e6a98a --- /dev/null +++ b/examples/valkey-replication-group/README.md @@ -0,0 +1,77 @@ +# ElastiCache example for Valkey Replication Group + +Configuration in this directory creates set of ElastiCaChe resources including replication group, subnet group and parameter 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.73 | + +## Providers + +| Name | Version | +|------|---------| +| [aws](#provider\_aws) | >= 5.73 | + +## Modules + +| Name | Source | Version | +|------|--------|---------| +| [elasticache](#module\_elasticache) | ../../ | 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\_configuration\_endpoint\_address](#output\_replication\_group\_configuration\_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/valkey-replication-group/main.tf b/examples/valkey-replication-group/main.tf new file mode 100644 index 0000000..0cba188 --- /dev/null +++ b/examples/valkey-replication-group/main.tf @@ -0,0 +1,86 @@ +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" + } +} + +################################################################################ +# ElastiCache Module +################################################################################ + +module "elasticache" { + source = "../../" + + replication_group_id = local.name + + engine = "valkey" + engine_version = "7.2" + 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 = local.name + subnet_group_description = "${title(local.name)} subnet group" + subnet_ids = module.vpc.private_subnets + + # Parameter Group + create_parameter_group = true + parameter_group_name = local.name + parameter_group_family = "valkey7" + parameter_group_description = "${title(local.name)} parameter group" + parameters = [ + { + name = "latency-tracking" + value = "yes" + } + ] + + tags = local.tags +} + +################################################################################ +# 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/valkey-replication-group/outputs.tf b/examples/valkey-replication-group/outputs.tf new file mode 100644 index 0000000..a3a563b --- /dev/null +++ b/examples/valkey-replication-group/outputs.tf @@ -0,0 +1,142 @@ +################################################################################ +# Cluster +################################################################################ + +output "cluster_arn" { + description = "The ARN of the ElastiCache Cluster" + value = module.elasticache.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.elasticache.cluster_engine_version_actual +} + +output "cluster_cache_nodes" { + description = "List of node objects including `id`, `address`, `port` and `availability_zone`" + value = module.elasticache.cluster_cache_nodes +} + +output "cluster_address" { + description = "(Memcached only) DNS name of the cache cluster without the port appended" + value = module.elasticache.cluster_address +} + +output "cluster_configuration_endpoint" { + description = "(Memcached only) Configuration endpoint to allow host discovery" + value = module.elasticache.cluster_configuration_endpoint +} + +################################################################################ +# Replication Group +################################################################################ + +output "replication_group_arn" { + description = "ARN of the created ElastiCache Replication Group" + value = module.elasticache.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.elasticache.replication_group_engine_version_actual +} + +output "replication_group_configuration_endpoint_address" { + description = "Address of the replication group configuration endpoint when cluster mode is enabled" + value = module.elasticache.replication_group_configuration_endpoint_address +} + +output "replication_group_id" { + description = "ID of the ElastiCache Replication Group" + value = module.elasticache.replication_group_id +} + +output "replication_group_member_clusters" { + description = "Identifiers of all the nodes that are part of this replication group" + value = module.elasticache.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.elasticache.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.elasticache.replication_group_reader_endpoint_address +} + +################################################################################ +# Global Replication Group +################################################################################ + +output "global_replication_group_id" { + description = "ID of the ElastiCache Global Replication Group" + value = module.elasticache.global_replication_group_id +} + +output "global_replication_group_arn" { + description = "ARN of the created ElastiCache Global Replication Group" + value = module.elasticache.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.elasticache.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.elasticache.global_replication_group_node_groups +} + +################################################################################ +# CloudWatch Log Group +################################################################################ + +output "cloudwatch_log_group_name" { + description = "Name of cloudwatch log group created" + value = module.elasticache.cloudwatch_log_group_name +} + +output "cloudwatch_log_group_arn" { + description = "Arn of cloudwatch log group created" + value = module.elasticache.cloudwatch_log_group_arn +} + +################################################################################ +# Parameter Group +################################################################################ + +output "parameter_group_arn" { + description = "The AWS ARN associated with the parameter group" + value = module.elasticache.parameter_group_arn +} + +output "parameter_group_id" { + description = "The ElastiCache parameter group name" + value = module.elasticache.parameter_group_id +} + +################################################################################ +# Subnet Group +################################################################################ + +output "subnet_group_name" { + description = "The ElastiCache subnet group name" + value = module.elasticache.subnet_group_name +} + +################################################################################ +# Security Group +################################################################################ + +output "security_group_arn" { + description = "Amazon Resource Name (ARN) of the security group" + value = module.elasticache.security_group_arn +} + +output "security_group_id" { + description = "ID of the security group" + value = module.elasticache.security_group_id +} diff --git a/examples/valkey-replication-group/variables.tf b/examples/valkey-replication-group/variables.tf new file mode 100644 index 0000000..e69de29 diff --git a/examples/valkey-replication-group/versions.tf b/examples/valkey-replication-group/versions.tf new file mode 100644 index 0000000..0f48a6c --- /dev/null +++ b/examples/valkey-replication-group/versions.tf @@ -0,0 +1,10 @@ +terraform { + required_version = ">= 1.0" + + required_providers { + aws = { + source = "hashicorp/aws" + version = ">= 5.73" + } + } +} diff --git a/main.tf b/main.tf index b91055f..98cbbb0 100644 --- a/main.tf +++ b/main.tf @@ -2,6 +2,11 @@ locals { # https://github.com/hashicorp/terraform-provider-aws/blob/3c4cb52c5dc2c09e10e5a717f73d1d8bc4186e87/internal/service/elasticache/cluster.go#L271 in_replication_group = var.replication_group_id != null + # elasticache clusters currently do not support engine type valkey + # TODO: remove this local `create_cluster` conditional once this bug is addressed: + # https://github.com/hashicorp/terraform-provider-aws/issues/39905 + create_cluster = var.create_cluster && var.engine != "valkey" ? true : false + security_group_ids = local.create_security_group ? concat(var.security_group_ids, [aws_security_group.this[0].id]) : var.security_group_ids port = var.engine == "memcached" ? 11211 : 6379 @@ -13,20 +18,20 @@ locals { ################################################################################ resource "aws_elasticache_cluster" "this" { - count = var.create && var.create_cluster ? 1 : 0 + count = var.create && local.create_cluster ? 1 : 0 apply_immediately = var.apply_immediately auto_minor_version_upgrade = var.auto_minor_version_upgrade 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 @@ -56,6 +61,12 @@ resource "aws_elasticache_cluster" "this" { transit_encryption_enabled = var.engine == "memcached" ? var.transit_encryption_enabled : null tags = local.tags + + timeouts { + create = try(var.timeouts.create, null) + update = try(var.timeouts.update, null) + delete = try(var.timeouts.delete, null) + } } ################################################################################ @@ -75,6 +86,7 @@ resource "aws_elasticache_replication_group" "this" { auth_token_update_strategy = var.auth_token_update_strategy auto_minor_version_upgrade = var.auto_minor_version_upgrade automatic_failover_enabled = var.multi_az_enabled || var.cluster_mode_enabled ? true : var.automatic_failover_enabled + cluster_mode = var.cluster_mode data_tiering_enabled = var.data_tiering_enabled description = coalesce(var.description, "Replication group") engine = var.engine @@ -85,7 +97,7 @@ resource "aws_elasticache_replication_group" "this" { kms_key_id = var.at_rest_encryption_enabled ? var.kms_key_arn : null dynamic "log_delivery_configuration" { - for_each = { for k, v in var.log_delivery_configuration : k => v if var.engine == "redis" } + for_each = { for k, v in var.log_delivery_configuration : k => v if var.engine != "memcached" } 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 @@ -152,6 +164,7 @@ resource "aws_elasticache_replication_group" "global" { auth_token_update_strategy = var.auth_token_update_strategy auto_minor_version_upgrade = var.auto_minor_version_upgrade automatic_failover_enabled = var.multi_az_enabled || var.cluster_mode_enabled ? true : var.automatic_failover_enabled + cluster_mode = var.cluster_mode data_tiering_enabled = var.data_tiering_enabled description = coalesce(var.description, "Global replication group") engine = var.create_secondary_global_replication_group ? null : var.engine @@ -279,6 +292,10 @@ resource "aws_elasticache_subnet_group" "this" { subnet_ids = var.subnet_ids tags = local.tags + + lifecycle { + create_before_destroy = true + } } ################################################################################ diff --git a/modules/serverless-cache/README.md b/modules/serverless-cache/README.md index 2e9a5c0..fb644c2 100644 --- a/modules/serverless-cache/README.md +++ b/modules/serverless-cache/README.md @@ -29,7 +29,7 @@ module "elasticache_serverless_cache" { kms_key_id = aws_kms_key.this.arn major_engine_version = "7" - security_group_rules = [module.sg.security_group_id] + security_group_ids = [module.sg.security_group_id] snapshot_retention_limit = 7 subnet_ids = module.vpc.private_subnets @@ -54,19 +54,19 @@ Examples codified under the [`examples`](https://github.com/terraform-aws-module - [Redis Replication Group](https://github.com/terraform-aws-modules/terraform-aws-elasticache/tree/master/examples/redis-replication-group) - [Serverless Cache](https://github.com/terraform-aws-modules/terraform-aws-elasticache/tree/master/examples/serverless-cache) - + ## Requirements | Name | Version | |------|---------| | [terraform](#requirement\_terraform) | >= 1.0 | -| [aws](#requirement\_aws) | >= 5.47 | +| [aws](#requirement\_aws) | >= 5.73 | ## Providers | Name | Version | |------|---------| -| [aws](#provider\_aws) | >= 5.47 | +| [aws](#provider\_aws) | >= 5.73 | ## Modules @@ -109,7 +109,7 @@ No modules. | [serverless\_cache\_major\_engine\_version](#output\_serverless\_cache\_major\_engine\_version) | The version number of the engine the serverless cache is compatible with | | [serverless\_cache\_reader\_endpoint](#output\_serverless\_cache\_reader\_endpoint) | Represents the information required for client programs to connect to a cache node | | [serverless\_cache\_status](#output\_serverless\_cache\_status) | The current status of the serverless cache. The allowed values are CREATING, AVAILABLE, DELETING, CREATE-FAILED and MODIFYING | - + ## License diff --git a/modules/serverless-cache/main.tf b/modules/serverless-cache/main.tf index 9a08d92..729d103 100644 --- a/modules/serverless-cache/main.tf +++ b/modules/serverless-cache/main.tf @@ -5,7 +5,7 @@ resource "aws_elasticache_serverless_cache" "this" { name = var.cache_name dynamic "cache_usage_limits" { - for_each = try([var.cache_usage_limits], []) + for_each = length(var.cache_usage_limits) > 0 ? [var.cache_usage_limits] : [] content { dynamic "data_storage" { diff --git a/modules/serverless-cache/versions.tf b/modules/serverless-cache/versions.tf index 407a955..0f48a6c 100644 --- a/modules/serverless-cache/versions.tf +++ b/modules/serverless-cache/versions.tf @@ -4,7 +4,7 @@ terraform { required_providers { aws = { source = "hashicorp/aws" - version = ">= 5.47" + version = ">= 5.73" } } } diff --git a/modules/user-group/README.md b/modules/user-group/README.md index e4be0de..6e4305e 100644 --- a/modules/user-group/README.md +++ b/modules/user-group/README.md @@ -60,19 +60,19 @@ Examples codified under the [`examples`](https://github.com/terraform-aws-module - [Redis Global Replication Group](https://github.com/terraform-aws-modules/terraform-aws-elasticache/tree/master/examples/redis-global-replication-group) - [Redis Replication Group](https://github.com/terraform-aws-modules/terraform-aws-elasticache/tree/master/examples/redis-replication-group) - + ## Requirements | Name | Version | |------|---------| | [terraform](#requirement\_terraform) | >= 1.0 | -| [aws](#requirement\_aws) | >= 5.47 | +| [aws](#requirement\_aws) | >= 5.73 | ## Providers | Name | Version | |------|---------| -| [aws](#provider\_aws) | >= 5.47 | +| [aws](#provider\_aws) | >= 5.73 | ## Modules @@ -108,7 +108,7 @@ No modules. | [group\_arn](#output\_group\_arn) | The ARN that identifies the user group | | [group\_id](#output\_group\_id) | The user group identifier | | [users](#output\_users) | A map of users created and their attributes | - + ## License diff --git a/modules/user-group/main.tf b/modules/user-group/main.tf index 7919fb7..d21e509 100644 --- a/modules/user-group/main.tf +++ b/modules/user-group/main.tf @@ -74,4 +74,12 @@ resource "aws_elasticache_user_group_association" "this" { user_group_id = var.create && var.create_group ? aws_elasticache_user_group.this[0].user_group_id : each.value.user_group_id user_id = aws_elasticache_user.this[each.key].user_id + + dynamic "timeouts" { + for_each = try([each.value.timeouts], []) + content { + create = try(timeouts.value.create, null) + delete = try(timeouts.value.delete, null) + } + } } diff --git a/modules/user-group/versions.tf b/modules/user-group/versions.tf index 407a955..0f48a6c 100644 --- a/modules/user-group/versions.tf +++ b/modules/user-group/versions.tf @@ -4,7 +4,7 @@ terraform { required_providers { aws = { source = "hashicorp/aws" - version = ">= 5.47" + version = ">= 5.73" } } } diff --git a/outputs.tf b/outputs.tf index 17f7120..e015a78 100644 --- a/outputs.tf +++ b/outputs.tf @@ -41,7 +41,7 @@ output "replication_group_engine_version_actual" { value = try(aws_elasticache_replication_group.this[0].engine_version_actual, aws_elasticache_replication_group.global[0].engine_version_actual, null) } -output "replication_group_coniguration_endpoint_address" { +output "replication_group_configuration_endpoint_address" { description = "Address of the replication group configuration endpoint when cluster mode is enabled" value = try(aws_elasticache_replication_group.this[0].configuration_endpoint_address, aws_elasticache_replication_group.global[0].configuration_endpoint_address, null) } @@ -94,11 +94,18 @@ output "global_replication_group_node_groups" { # CloudWatch Log Group ################################################################################ +output "cloudwatch_log_groups" { + description = "Map of CloudWatch log groups created and their attributes" + value = aws_cloudwatch_log_group.this +} + +# TODO - remove at next breaking change output "cloudwatch_log_group_name" { description = "Name of cloudwatch log group created" value = try(aws_cloudwatch_log_group.this[0].name, null) } +# TODO - remove at next breaking change output "cloudwatch_log_group_arn" { description = "Arn of cloudwatch log group created" value = try(aws_cloudwatch_log_group.this[0].arn, null) diff --git a/variables.tf b/variables.tf index 2ff4aff..f4049d6 100644 --- a/variables.tf +++ b/variables.tf @@ -27,7 +27,7 @@ variable "apply_immediately" { } variable "auto_minor_version_upgrade" { - description = "Specifies whether minor version engine upgrades will be applied automatically to the underlying Cache Cluster instances during the maintenance window. Only supported for engine type `redis` and if the engine version is 6 or higher. Defaults to `true`" + description = "Specifies whether minor version engine upgrades will be applied automatically to the underlying Cache Cluster instances during the maintenance window. Only supported for engine type `redis` and `valkey` and if the engine version is 6 or higher. Defaults to `true`" type = bool default = null } @@ -57,7 +57,7 @@ variable "cluster_id" { } variable "engine" { - description = "Name of the cache engine to be used for this cache cluster. Valid values are `memcached` or `redis`" + description = "Name of the cache engine to be used for this cache cluster. Valid values are `memcached`, `redis`, or `valkey`" type = string default = "redis" } @@ -81,7 +81,7 @@ variable "ip_discovery" { } variable "log_delivery_configuration" { - description = "(Redis only) Specifies the destination and format of Redis SLOWLOG or Redis Engine Log" + description = "(Redis OSS or Valkey) Specifies the destination and format of Redis OSS/Valkey SLOWLOG or Redis OSS/Valkey Engine Log" type = any default = { slow-log = { @@ -187,6 +187,12 @@ variable "transit_encryption_mode" { default = null } +variable "timeouts" { + description = "Define maximum timeout for creating, updating, and deleting cluster resource" + type = map(string) + default = {} +} + ################################################################################ # Replication Group ################################################################################ @@ -269,6 +275,12 @@ variable "replicas_per_node_group" { default = null } +variable "cluster_mode" { + description = "Specifies whether cluster mode is enabled or disabled. Valid values are enabled or disabled or compatible" + type = string + default = null +} + variable "replication_group_id" { description = "Replication group identifier. When `create_replication_group` is set to `true`, this is the ID assigned to the replication group created. When `create_replication_group` is set to `false`, this is the ID of an externally created replication group" type = string diff --git a/versions.tf b/versions.tf index 7cd9c04..6dda813 100644 --- a/versions.tf +++ b/versions.tf @@ -4,7 +4,7 @@ terraform { required_providers { aws = { source = "hashicorp/aws" - version = ">= 5.47" + version = ">= 5.93" } random = { source = "hashicorp/random"
"slow-log": {
"destination_type": "cloudwatch-logs",
"log_format": "json"
}
}