Giter Club home page Giter Club logo

terraform-aws-elasticache-redis's Introduction

terraform-aws-elasticache-redis

Latest ReleaseLast UpdatedSlack Community

Terraform module to provision an ElastiCache Redis Cluster

Tip

๐Ÿ‘ฝ Use Atmos with Terraform

Cloud Posse uses atmos to easily orchestrate multiple environments using Terraform.
Works with Github Actions, Atlantis, or Spacelift.

Watch demo of using Atmos with Terraform
Example of running atmos to manage infrastructure from our Quick Start tutorial.

Usage

Disruptive changes introduced at version 0.41.0. If upgrading from an earlier version, see migration notes for details.

Note that this uses secure defaults. One of the ways this module can trip users up is with transit_encryption_enabled which is true by default. With this enabled, one does not simply redis-cli in without setting up an stunnel. Amazon provides good documentation on how to connect with it enabled. If this is not desired behavior, set transit_encryption_enabled=false.

This module creates, by default, a new security group for the Elasticache Redis Cluster. When a configuration change (for example, a different security group name) cannot be applied to the security group, Terraform will replace that security group with a new one with the new configuration. In order to allow Terraform to fully manage the security group, you should not place any other resources in (or associate any other resources with) the security group this module creates. Also, in order to keep things from breaking when this module replaces the security group, you should not reference the created security group anywhere else (such as in rules in other security groups). If you want to associate the cluster with a more stable security group that you can reference elsewhere, create that security group outside this module (perhaps with terraform-aws-security-group) and pass the security group ID in via associated_security_group_ids.

Note about zone_id: Previously, zone_id was a string. This caused problems (see #82). Now zone_id should be supplied as a list(string), either empty or with exactly 1 zone ID in order to avoid the problem.

For a complete example, see examples/complete.

For automated tests of the complete example using bats and Terratest (which tests and deploys the example on AWS), see test.

provider "aws" {
  region = var.region
}

module "this" {
  source  = "cloudposse/label/null"
  # Cloud Posse recommends pinning every module to a specific version
  # version = "x.x.x"
  namespace  = var.namespace
  stage      = var.stage
  name       = var.name
}

module "vpc" {
  source = "cloudposse/vpc/aws"
  # Cloud Posse recommends pinning every module to a specific version
  # version = "x.x.x"

  cidr_block = "172.16.0.0/16"

  context = module.this.context
}

module "subnets" {
  source = "cloudposse/dynamic-subnets/aws"
  # Cloud Posse recommends pinning every module to a specific version
  # version = "x.x.x"

  availability_zones   = var.availability_zones
  vpc_id               = module.vpc.vpc_id
  igw_id               = module.vpc.igw_id
  cidr_block           = module.vpc.vpc_cidr_block
  nat_gateway_enabled  = true
  nat_instance_enabled = false

  context = module.this.context
}

module "redis" {
  source = "cloudposse/elasticache-redis/aws"
  # Cloud Posse recommends pinning every module to a specific version
  # version = "x.x.x"

  availability_zones         = var.availability_zones
  zone_id                    = var.zone_id
  vpc_id                     = module.vpc.vpc_id
  allowed_security_group_ids = [module.vpc.vpc_default_security_group_id]
  subnets                    = module.subnets.private_subnet_ids
  cluster_size               = var.cluster_size
  instance_type              = var.instance_type
  apply_immediately          = true
  automatic_failover_enabled = false
  engine_version             = var.engine_version
  family                     = var.family
  at_rest_encryption_enabled = var.at_rest_encryption_enabled
  transit_encryption_enabled = var.transit_encryption_enabled

  parameter = [
    {
      name  = "notify-keyspace-events"
      value = "lK"
    }
  ]

  context = module.this.context
}

Important

In Cloud Posse's examples, we avoid pinning modules to specific versions to prevent discrepancies between the documentation and the latest released versions. However, for your own projects, we strongly advise pinning each module to the exact version you're using. This practice ensures the stability of your infrastructure. Additionally, we recommend implementing a systematic approach for updating versions to avoid unexpected changes.

Examples

Review the complete example to see how to use this module.

Makefile Targets

Available targets:

  help                                Help screen
  help/all                            Display help for all targets
  help/short                          This help short screen
  lint                                Lint terraform code

Requirements

Name Version
terraform >= 1.3
aws >= 4.18

Providers

Name Version
aws >= 4.18

Modules

Name Source Version
aws_security_group cloudposse/security-group/aws 2.2.0
dns cloudposse/route53-cluster-hostname/aws 0.13.0
this cloudposse/label/null 0.25.0

Resources

Name Type
aws_cloudwatch_metric_alarm.cache_cpu resource
aws_cloudwatch_metric_alarm.cache_memory resource
aws_elasticache_parameter_group.default resource
aws_elasticache_replication_group.default resource
aws_elasticache_subnet_group.default resource

Inputs

Name Description Type Default Required
additional_security_group_rules A list of Security Group rule objects to add to the created security group, in addition to the ones
this module normally creates. (To suppress the module's rules, set create_security_group to false
and supply your own security group via associated_security_group_ids.)
The keys and values of the objects are fully compatible with the aws_security_group_rule resource, except
for security_group_id which will be ignored, and the optional "key" which, if provided, must be unique and known at "plan" time.
To get more info see https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/security_group_rule .
list(any) [] no
additional_tag_map Additional key-value pairs to add to each map in tags_as_list_of_maps. Not added to tags or id.
This is for some rare cases where resources want additional configuration of tags
and therefore take a list of maps with tag key, value, and additional configuration.
map(string) {} no
alarm_actions Alarm action list list(string) [] no
alarm_cpu_threshold_percent CPU threshold alarm level number 75 no
alarm_memory_threshold_bytes Ram threshold alarm level number 10000000 no
allow_all_egress If true, the created security group will allow egress on all ports and protocols to all IP address.
If this is false and no egress rules are otherwise specified, then no egress will be allowed.
Defaults to true unless the deprecated egress_cidr_blocks is provided and is not ["0.0.0.0/0"], in which case defaults to false.
bool null no
allowed_cidr_blocks DEPRECATED: Use additional_security_group_rules instead.
Historical description: List of CIDR blocks that are allowed ingress to the cluster's Security Group created in the module
list(string) [] no
allowed_security_group_ids A list of IDs of Security Groups to allow access to the security group created by this module. list(string) [] no
allowed_security_groups DEPRECATED: Use allowed_security_group_ids instead. list(string) [] no
apply_immediately Apply changes immediately bool true no
associated_security_group_ids A list of IDs of Security Groups to associate the created resource with, in addition to the created security group.
These security groups will not be modified and, if create_security_group is false, must provide all the required access.
list(string) [] no
at_rest_encryption_enabled Enable encryption at rest bool false no
attributes ID element. Additional attributes (e.g. workers or cluster) to add to id,
in the order they appear in the list. New attributes are appended to the
end of the list. The elements of the list are joined by the delimiter
and treated as a single ID element.
list(string) [] no
auth_token Auth token for password protecting redis, transit_encryption_enabled must be set to true. Password must be longer than 16 chars string null no
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 if the engine version is 6 or higher. bool null no
automatic_failover_enabled Automatic failover (Not available for T1/T2 instances) bool false no
availability_zones Availability zone IDs list(string) [] no
cloudwatch_metric_alarms_enabled Boolean flag to enable/disable CloudWatch metrics alarms bool false no
cluster_mode_enabled Flag to enable/disable creation of a native redis cluster. automatic_failover_enabled must be set to true. Only 1 cluster_mode block is allowed bool false no
cluster_mode_num_node_groups Number of node groups (shards) for this Redis replication group. Changing this number will trigger an online resizing operation before other settings modifications number 0 no
cluster_mode_replicas_per_node_group Number of replica nodes in each node group. Valid values are 0 to 5. Changing this number will force a new resource number 0 no
cluster_size Number of nodes in cluster. Ignored when cluster_mode_enabled == true number 1 no
context Single object for setting entire context at once.
See description of individual variables for details.
Leave string and numeric variables as null to use default value.
Individual variable settings (non-null) override settings in context object,
except for attributes, tags, and additional_tag_map, which are merged.
any
{
"additional_tag_map": {},
"attributes": [],
"delimiter": null,
"descriptor_formats": {},
"enabled": true,
"environment": null,
"id_length_limit": null,
"label_key_case": null,
"label_order": [],
"label_value_case": null,
"labels_as_tags": [
"unset"
],
"name": null,
"namespace": null,
"regex_replace_chars": null,
"stage": null,
"tags": {},
"tenant": null
}
no
create_parameter_group Whether new parameter group should be created. Set to false if you want to use existing parameter group bool true no
create_security_group Set true to create and configure a new security group. If false, associated_security_group_ids must be provided. bool true no
data_tiering_enabled Enables data tiering. Data tiering is only supported for replication groups using the r6gd node type. bool false no
delimiter Delimiter to be used between ID elements.
Defaults to - (hyphen). Set to "" to use no delimiter at all.
string null no
description Description of elasticache replication group string null no
descriptor_formats Describe additional descriptors to be output in the descriptors output map.
Map of maps. Keys are names of descriptors. Values are maps of the form
{<br> format = string<br> labels = list(string)<br>}
(Type is any so the map values can later be enhanced to provide additional options.)
format is a Terraform format string to be passed to the format() function.
labels is a list of labels, in order, to pass to format() function.
Label values will be normalized before being passed to format() so they will be
identical to how they appear in id.
Default is {} (descriptors output will be empty).
any {} no
dns_subdomain The subdomain to use for the CNAME record. If not provided then the CNAME record will use var.name. string "" no
egress_cidr_blocks DEPRECATED: Use allow_all_egress and additional_security_group_rules instead.
Historical description: Outbound traffic address.
Historical default: ["0.0.0.0/0"]
list(any) null no
elasticache_subnet_group_name Subnet group name for the ElastiCache instance string "" no
enabled Set to false to prevent the module from creating any resources bool null no
engine_version Redis engine version string "4.0.10" no
environment ID element. Usually used for region e.g. 'uw2', 'us-west-2', OR role 'prod', 'staging', 'dev', 'UAT' string null no
existing_security_groups DEPRECATED: Use associated_security_group_ids instead.
Historical description: List of existing Security Group IDs to place the cluster into.
Set use_existing_security_groups to true to enable using existing_security_groups as Security Groups for the cluster.
list(string) [] no
family Redis family string "redis4.0" no
final_snapshot_identifier The name of your final node group (shard) snapshot. ElastiCache creates the snapshot from the primary node in the cluster. If omitted, no final snapshot will be made. string null no
id_length_limit Limit id to this many characters (minimum 6).
Set to 0 for unlimited length.
Set to null for keep the existing setting, which defaults to 0.
Does not affect id_full.
number null no
inline_rules_enabled NOT RECOMMENDED. Create rules "inline" instead of as separate aws_security_group_rule resources.
See #20046 for one of several issues with inline rules.
See this post for details on the difference between inline rules and rule resources.
bool false no
instance_type Elastic cache instance type string "cache.t2.micro" no
kms_key_id The ARN of the key that you wish to use if encrypting at rest. If not supplied, uses service managed encryption. at_rest_encryption_enabled must be set to true string null no
label_key_case Controls the letter case of the tags keys (label names) for tags generated by this module.
Does not affect keys of tags passed in via the tags input.
Possible values: lower, title, upper.
Default value: title.
string null no
label_order The order in which the labels (ID elements) appear in the id.
Defaults to ["namespace", "environment", "stage", "name", "attributes"].
You can omit any of the 6 labels ("tenant" is the 6th), but at least one must be present.
list(string) null no
label_value_case Controls the letter case of ID elements (labels) as included in id,
set as tag values, and output by this module individually.
Does not affect values of tags passed in via the tags input.
Possible values: lower, title, upper and none (no transformation).
Set this to title and set delimiter to "" to yield Pascal Case IDs.
Default value: lower.
string null no
labels_as_tags Set of labels (ID elements) to include as tags in the tags output.
Default is to include all labels.
Tags with empty values will not be included in the tags output.
Set to [] to suppress all generated tags.
Notes:
The value of the name tag, if included, will be the id, not the name.
Unlike other null-label inputs, the initial setting of labels_as_tags cannot be
changed in later chained modules. Attempts to change it will be silently ignored.
set(string)
[
"default"
]
no
log_delivery_configuration The log_delivery_configuration block allows the streaming of Redis SLOWLOG or Redis Engine Log to CloudWatch Logs or Kinesis Data Firehose. Max of 2 blocks. list(map(any)) [] no
maintenance_window Maintenance window string "wed:03:00-wed:04:00" no
multi_az_enabled Multi AZ (Automatic Failover must also be enabled. If Cluster Mode is enabled, Multi AZ is on by default, and this setting is ignored) bool false no
name ID element. Usually the component or solution name, e.g. 'app' or 'jenkins'.
This is the only ID element not also included as a tag.
The "name" tag is set to the full id string. There is no tag with the value of the name input.
string null no
namespace ID element. Usually an abbreviation of your organization name, e.g. 'eg' or 'cp', to help ensure generated IDs are globally unique string null no
notification_topic_arn Notification topic arn string "" no
ok_actions The list of actions to execute when this alarm transitions into an OK state from any other state. Each action is specified as an Amazon Resource Number (ARN) list(string) [] no
parameter A list of Redis parameters to apply. Note that parameters may differ from one Redis family to another
list(object({
name = string
value = string
}))
[] no
parameter_group_description Managed by Terraform string null no
parameter_group_name Override the default parameter group name string null no
port Redis port number 6379 no
preserve_security_group_id When false and create_before_destroy is true, changes to security group rules
cause a new security group to be created with the new rules, and the existing security group is then
replaced with the new one, eliminating any service interruption.
When true or when changing the value (from false to true or from true to false),
existing security group rules will be deleted before new ones are created, resulting in a service interruption,
but preserving the security group itself.
NOTE: Setting this to true does not guarantee the security group will never be replaced,
it only keeps changes to the security group rules from triggering a replacement.
See the README for further discussion.
bool false no
regex_replace_chars Terraform regular expression (regex) string.
Characters matching the regex will be removed from the ID elements.
If not set, "/[^a-zA-Z0-9-]/" is used to remove all characters other than hyphens, letters and digits.
string null no
replication_group_id Replication group ID with the following constraints:
A name must contain from 1 to 20 alphanumeric characters or hyphens.
The first character must be a letter.
A name cannot end with a hyphen or contain two consecutive hyphens.
string "" no
revoke_rules_on_delete Instruct Terraform to revoke all of the Security Group's attached ingress and egress rules before deleting
the security group itself. This is normally not needed.
bool false no
security_group_create_before_destroy Set true to enable Terraform create_before_destroy behavior on the created security group.
We only recommend setting this false if you are upgrading this module and need to keep
the existing security group from being replaced.
Note that changing this value will always cause the security group to be replaced.
bool true no
security_group_create_timeout How long to wait for the security group to be created. string "10m" no
security_group_delete_timeout How long to retry on DependencyViolation errors during security group deletion. string "15m" no
security_group_description The description to assign to the created Security Group.
Warning: Changing the description causes the security group to be replaced.
Set this to null to maintain parity with releases <= 0.34.0.
string "Security group for Elasticache Redis" no
security_group_name The name to assign to the security group. Must be unique within the VPC.
If not provided, will be derived from the null-label.context passed in.
If create_before_destroy is true, will be used as a name prefix.
list(string) [] no
snapshot_arns A single-element string list containing an Amazon Resource Name (ARN) of a Redis RDB snapshot file stored in Amazon S3. Example: arn:aws:s3:::my_bucket/snapshot1.rdb list(string) [] no
snapshot_name The name of a snapshot from which to restore data into the new node group. Changing the snapshot_name forces a new resource. string null no
snapshot_retention_limit The number of days for which ElastiCache will retain automatic cache cluster snapshots before deleting them. number 0 no
snapshot_window The daily time range (in UTC) during which ElastiCache will begin taking a daily snapshot of your cache cluster. string "06:30-07:30" no
stage ID element. Usually used to indicate role, e.g. 'prod', 'staging', 'source', 'build', 'test', 'deploy', 'release' string null no
subnets Subnet IDs list(string) [] no
tags Additional tags (e.g. {'BusinessUnit': 'XYZ'}).
Neither the tag keys nor the tag values will be modified by this module.
map(string) {} no
target_security_group_id The ID of an existing Security Group to which Security Group rules will be assigned.
The Security Group's name and description will not be changed.
Not compatible with inline_rules_enabled or revoke_rules_on_delete.
If not provided (the default), this module will create a security group.
list(string) [] no
tenant ID element _(Rarely used, not included by default)_. A customer identifier, indicating who this instance of a resource is for string null no
transit_encryption_enabled Set true to enable encryption in transit. Forced true if var.auth_token is set.
If this is enabled, use the following guide to access redis.
bool true no
use_existing_security_groups DEPRECATED: Use create_security_group instead.
Historical description: Flag to enable/disable creation of Security Group in the module.
Set to true to disable Security Group creation and provide a list of existing security Group IDs in existing_security_groups to place the cluster into.
Historical default: false
bool null no
user_group_ids User Group ID to associate with the replication group list(string) null no
vpc_id VPC ID string n/a yes
zone_id Route53 DNS Zone ID as list of string (0 or 1 items). If empty, no custom DNS name will be published.
If the list contains a single Zone ID, a custom DNS name will be pulished in that zone.
Can also be a plain string, but that use is DEPRECATED because of Terraform issues.
any [] no

Outputs

Name Description
arn Elasticache Replication Group ARN
cluster_enabled Indicates if cluster mode is enabled
endpoint Redis primary or configuration endpoint, whichever is appropriate for the given cluster mode
engine_version_actual The running version of the cache engine
host Redis hostname
id Redis cluster ID
member_clusters Redis cluster members
port Redis port
reader_endpoint_address The address of the endpoint for the reader node in the replication group, if the cluster mode is disabled.
security_group_id The ID of the created security group
security_group_name The name of the created security group

Related Projects

Check out these related projects.

  • terraform-aws-security-group - Terraform module to provision an AWS Security Group.
  • terraform-null-label - Terraform module designed to generate consistent names and tags for resources. Use terraform-null-label to implement a strict naming convention.

Tip

Use Terraform Reference Architectures for AWS

Use Cloud Posse's ready-to-go terraform architecture blueprints for AWS to get up and running quickly.

โœ… We build it with you.
โœ… You own everything.
โœ… Your team wins.

Request Quote

๐Ÿ“š Learn More

Cloud Posse is the leading DevOps Accelerator for funded startups and enterprises.

Your team can operate like a pro today.

Ensure that your team succeeds by using Cloud Posse's proven process and turnkey blueprints. Plus, we stick around until you succeed.

Day-0: Your Foundation for Success

  • Reference Architecture. You'll get everything you need from the ground up built using 100% infrastructure as code.
  • Deployment Strategy. Adopt a proven deployment strategy with GitHub Actions, enabling automated, repeatable, and reliable software releases.
  • Site Reliability Engineering. Gain total visibility into your applications and services with Datadog, ensuring high availability and performance.
  • Security Baseline. Establish a secure environment from the start, with built-in governance, accountability, and comprehensive audit logs, safeguarding your operations.
  • GitOps. Empower your team to manage infrastructure changes confidently and efficiently through Pull Requests, leveraging the full power of GitHub Actions.

Request Quote

Day-2: Your Operational Mastery

  • Training. Equip your team with the knowledge and skills to confidently manage the infrastructure, ensuring long-term success and self-sufficiency.
  • Support. Benefit from a seamless communication over Slack with our experts, ensuring you have the support you need, whenever you need it.
  • Troubleshooting. Access expert assistance to quickly resolve any operational challenges, minimizing downtime and maintaining business continuity.
  • Code Reviews. Enhance your teamโ€™s code quality with our expert feedback, fostering continuous improvement and collaboration.
  • Bug Fixes. Rely on our team to troubleshoot and resolve any issues, ensuring your systems run smoothly.
  • Migration Assistance. Accelerate your migration process with our dedicated support, minimizing disruption and speeding up time-to-value.
  • Customer Workshops. Engage with our team in weekly workshops, gaining insights and strategies to continuously improve and innovate.

Request Quote

โœจ Contributing

This project is under active development, and we encourage contributions from our community.

Many thanks to our outstanding contributors:

For ๐Ÿ› bug reports & feature requests, please use the issue tracker.

In general, PRs are welcome. We follow the typical "fork-and-pull" Git workflow.

  1. Review our Code of Conduct and Contributor Guidelines.
  2. Fork the repo on GitHub
  3. Clone the project to your own machine
  4. Commit changes to your own branch
  5. Push your work back up to your fork
  6. Submit a Pull Request so that we can review your changes

NOTE: Be sure to merge the latest changes from "upstream" before making a pull request!

๐ŸŒŽ Slack Community

Join our Open Source Community on Slack. It's FREE for everyone! Our "SweetOps" community is where you get to talk with others who share a similar vision for how to rollout and manage infrastructure. This is the best place to talk shop, ask questions, solicit feedback, and work together as a community to build totally sweet infrastructure.

๐Ÿ“ฐ Newsletter

Sign up for our newsletter and join 3,000+ DevOps engineers, CTOs, and founders who get insider access to the latest DevOps trends, so you can always stay in the know. Dropped straight into your Inbox every week โ€” and usually a 5-minute read.

๐Ÿ“† Office Hours

Join us every Wednesday via Zoom for your weekly dose of insider DevOps trends, AWS news and Terraform insights, all sourced from our SweetOps community, plus a live Q&A that you canโ€™t find anywhere else. It's FREE for everyone!

License

License

Preamble to the Apache License, Version 2.0

Complete license is available in the LICENSE file.

Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements.  See the NOTICE file
distributed with this work for additional information
regarding copyright ownership.  The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License.  You may obtain a copy of the License at

  https://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied.  See the License for the
specific language governing permissions and limitations
under the License.

Trademarks

All other trademarks referenced herein are the property of their respective owners.


Copyright ยฉ 2017-2024 Cloud Posse, LLC

README footer

Beacon

terraform-aws-elasticache-redis's People

Contributors

aknysh avatar barissekerciler avatar cloudpossebot avatar darend avatar dylanbannon avatar goruha avatar gowiem avatar gusse avatar jamengual avatar lienejansone avatar marcuz avatar max-lobur avatar maximmi avatar maxymvlasov avatar mazzy89 avatar moonmoon1919 avatar nitrocode avatar nuru avatar osterman avatar renovate[bot] avatar robusgauli avatar samsullivan avatar solairerove avatar steve-louie-bose avatar sweetops avatar syphernl avatar vadim-hleif avatar varunpalekar avatar woz5999 avatar y3ti avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

terraform-aws-elasticache-redis's Issues

mandating auth_token breaks module for use when not using in-transit encryption

Related to, and a result of the merge of #22, it's now impossible to disable in-transit encryption because of the presence of this line in the aws_elasticache_replication_group default resource. If one tries the supplied example from the module you'll see it's currently broken because of this.

I've had a good look at the module and I cannot think of a way to resolve this cleanly:

  • setting the default value for transit_encryption_enabled to false still fails if auth_token is in the resource as the provider complains: aws_elasticache_replication_group.default: Error creating Elasticache Replication Group: InvalidParameterValue: The AUTH token is only supported when encryption-in-transit is enabled
  • creating a second resource without auth_token is the only way I can think of and then doing some combined magic with count based on var.enabled as well as, say, the length of var.auth_token but even that gets very ugly quickly as all of the dependent resources (e.g. cloudwatch alerts) then break

Any thoughts or a pair of eyes appreciated!

aws_elasticache_replication_group supports auto_minor_version_upgrade parameter

Describe the Feature

auto_minor_version_upgrade - (Optional) Specifies whether a minor engine upgrades will be applied automatically to the underlying Cache Cluster instances during the maintenance window. Defaults to true.

https://registry.terraform.io/providers/hcavarsan/aws/latest/docs/resources/elasticache_replication_group#auto_minor_version_upgrade

Use Case

It's defaults to true which might be not desired under some circumstances.

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies

terraform
examples/complete/main.tf
  • cloudposse/cloudwatch-logs/aws 0.6.8
  • cloudposse/dynamic-subnets/aws 2.4.1
  • cloudposse/vpc/aws 2.2.0
examples/complete/versions.tf
  • aws >= 4.18
  • hashicorp/terraform >= 1.3
main.tf
  • cloudposse/security-group/aws 2.2.0
  • cloudposse/route53-cluster-hostname/aws 0.13.0
versions.tf
  • aws >= 4.18
  • hashicorp/terraform >= 1.3

  • Check this box to trigger a request for Renovate to run again on this repository

subnet_group_name is always created

There are cases where you want to create a new redis instance but attach it to an existing subnet group. However, this is currently not possible with this implementation. You should be able to disable creating the subnet group and instead pass it in as a variable.

Count depends on resource to be created when zone_id is used

Describe the Bug

When i am using this module with zone_id (while zone is not created yet) it results with using terraform-aws-route53-cluster-hostname module, which fails to run as it is using count value which is actually output of another resource to be created.

It results with error:

Error: Invalid count argument

on .terraform/modules/redis.dns/main.tf line 2, in resource "aws_route53_record" "default":
2: count = module.this.enabled ? 1 : 0

The "count" value depends on resource attributes that cannot be determined
until apply, so Terraform cannot predict how many instances will be created.

Expected Behavior

The resource should be able to be created from scratch without count value being unknown at the plan time - it should be possible to create the whole infrastructure at the single run, without using --target to resolve dependencies.

Steps to Reproduce

I believe that using any configuration with this module on version 0.24.0 with zone_id, where zone is to be created will trigger an error.

Environment (please complete the following information):

  • OS:Linux
  • Terraform version 12.23
  • Version: 0.24.0

Issue when creating module without a security group

Describe the Bug

When using the module with associated_security_group_ids and disabled creation of security group, it throws an error about a null value:

โ•ท
โ”‚ Error: Null value found in list
โ”‚ 
โ”‚   with module.elasticache-redis.aws_elasticache_replication_group.default[0],
โ”‚   on .terraform/modules/elasticache-redis/main.tf line 120, in resource "aws_elasticache_replication_group" "default":
โ”‚  120:   security_group_ids         = concat(local.associated_security_group_ids, [module.aws_security_group.id])
โ”‚ 
โ”‚ Null values are not allowed for this attribute value.

Expected Behavior

Should work correctly and add only the associated security groups

Steps to Reproduce

module "elasticache-redis" {
  source = "cloudposse/elasticache-redis/aws"
  version = "~> 0.41"

  name = "redis"
  subnets = var.private_subnets
  vpc_id = var.vpc_id

  associated_security_group_ids = [module.redis_sg.this_security_group_id]
  at_rest_encryption_enabled = true
  create_security_group = false
  kms_key_id = aws_kms_key.redis_key.arn
  instance_type = var.redis_instance_type
  transit_encryption_enabled = false
  zone_id = var.zone_id
}

Setting in transit_encryption_enabled is ignored

Hey guys,

Your latest seems to ignore the setting in transit_encryption_enabled completely. Independently of the actual value, it always creates an instance with Transit encryption set to true. This is not the first version where this happens.

I pinned the module to tag 0.30.0 in my configuration, now. There it's possible to create an instance without transit encryption.

Kind regards
Andrรฉ

Error creating EIP: AddressLimitExceeded: The maximum number of addresses has been reached.

I'm not sure how much control this project has over this, but it seems like the architecture you're choosing does result in a large number of public IPs being created.

I think every availability zone gets its own public IP, so that's multiple EIPs per Redis cache? we definitely filled up our expanded quota of 10 really quickly. with multiple services having their own Redis cache each, and all of them being duplicated as prod and staging, there's just a lot of networking.

Would you recommend a different setup? Just having one elastic cache per AWS account and working with different Redis databases? Or is there maybe a way to reduce the amount of public IPs used? Any feedback appreciated. thanks for the great work you've put into this project, we make good use of it in our small team.

Create DNS for reader endpoint

Describe the Feature

It would be helpful to also create dns for the reader endpoint, same as with dns_subdomain parameter.

Use Case

We are using multiple reader nodes for reading cache from redis in order to avoid straining the master node.

Describe Ideal Solution

Add a new parameter dns_subdomain_reader

Using default value for availability_zones break Terraform

Describe the Bug

When using the default value for availability_zones (i.e: the parameter it's omitted) terraform plan throws the next error:


  on .terraform/modules/redis-dev/main.tf line 91, in resource "aws_elasticache_replication_group" "default":
  91:   availability_zones            = slice(var.availability_zones, 0, var.cluster_size)
    |----------------
    | var.cluster_size is 3

Invalid value for "end_index" parameter: end index must not be greater than
the length of the list.

The problem here is that slice() tries to create a non empty slice of an empty list, thus failing. More information on the slice command here.

Expected Behavior

terraform plan runs.

Steps to Reproduce

Create a file with this content:

  module "redis-dev" {
    source                     = "git::https://github.com/cloudposse/terraform-aws-elasticache-redis.git?ref=tags/0.16.0"
    stage                       = "dev"
    name                       = "voice-eks-dev"
    vpc_id                     = module.vpc.vpc_id
    subnets                   = module.vpc.private_subnets.0
    cluster_size             = 1
    instance_type          = "cache.t3.micro"
    engine_version        = "5.0.0"
    family                       = "redis5.0"
}

Environment (please complete the following information):

Anything that will help us triage the bug will help. Here are some ideas:

  • OS: Linux
  • Version:
 terraform --version
Terraform v0.12.20
+ provider.aws v2.49.0
+ provider.kubernetes v1.11.0
+ provider.local v1.4.0
+ provider.null v2.1.2
+ provider.random v2.2.1

name parameter throws error

for some reason when I include the name parameter in my module config - I get an error thrown. When I remove or comment out the parameter, the error goes away and everything works as expected. I've tried to include the replication_group_id variable - but the same error is thrown as well. I'm using terragrunt and have a simple wrapper around your module. I'm not sure why it would work when the variable is missing but fail when its present?

terraform.tfvars

# ------------------------
# TERRAGRUNT CONFIGURATION
# ------------------------

terragrunt = {
  terraform {
    source = "git::[email protected]:myrepo/terraform-modules.git//aws/
database/elasticache/redis?ref=v1.4.0"
  }

# Include all settings from the root terraform.tfvars file
  include {
    path = "${find_in_parent_folders()}"
  }
}

# -------------------------------------------------------
# MODULE PARAMETERS
# These are the variables we have to pass in to use the
# module specifieid in the terragrunt configuration above
# -------------------------------------------------------

aws_region  = "us-east-1"
environment = "production"
application = "streaming"

automatic_failover = "true"

vpc_remote_state_key = "account-production/us-east-1/prod/vpc/connection/terraform.tfstate"

cluster_size = "2"

route53_hosted_zone_id = "my-zone-id"
availability_zones = ["us-east-1a", "us-east-1b"]

namespace = "foo"
name      = "app-cache"

security_groups = [
  "sg-0123456790abc"
]

variables.tf

...
  variable "name" {
    description = "Elasticache name"
    default     = "redis"
  }

  variable "namespace" {
    description = "Elasticache namespace"
    default     = "global"
  }
...

main.tf

terraform {
  backend "s3" {}
}

provider "aws" {
  version = "~> 1.52.0"
  region  = "${var.aws_region}"
  profile = "${var.aws_profile}"
}

data "terraform_remote_state" "vpc" {
  backend = "s3"

  config {
    bucket  = "${var.tfstate_global_bucket}"
    key     = "${var.vpc_remote_state_key}"
    region  = "${var.tfstate_global_bucket_region}"
    profile = "${var.aws_profile}"
  }
}

locals {
  common_tags = "${map(
    "Terraform", "true",
    "Environment", var.environment,
    "Application", var.application
  )}"
  expanded_common_tags = "${merge(local.common_tags, var.additional_tags)}"
}

// Generate a random string for auth token, no special chars
resource "random_string" "auth_token" {
  length = 64
  special = false
}

module "elasticache-redis" {
  source  = "cloudposse/elasticache-redis/aws"
  version = "0.8.1"

  namespace       = "${var.namespace}"
  name            = "${var.name}"
  stage           = "${var.environment}"
  zone_id         = "${var.route53_hosted_zone_id}"
  security_groups = ["${var.security_groups}"]

  auth_token                   = "${random_string.auth_token.result}"
  vpc_id                       = "${data.terraform_remote_state.vpc.vpc_id}"
  subnets                      = "${data.terraform_remote_state.vpc.elasticache_subnets}"
  maintenance_window           = "${var.maintenance_window}"
  cluster_size                 = "${var.cluster_size}"
  instance_type                = "${var.instance_type}"
  engine_version               = "${var.engine_version}"
  alarm_cpu_threshold_percent  = "${var.alarm_cpu_threshold_percent}"
  alarm_memory_threshold_bytes = "${var.alarm_memory_threshold_bytes}"
  apply_immediately            = "${var.apply_immediately}"
  availability_zones           = "${var.availability_zones}"

  transit_encryption_enabled  = "${var.transit_encryption_enabled}"

  tags = "${local.expanded_common_tags}"

  automatic_failover = "${var.automatic_failover}"
}

ERROR
Error: module.elasticache-redis.aws_elasticache_replication_group.default: "replication_group_id" must contain from 1 to 20 alphanumeric characters or hyphens

Action Required: Fix Renovate Configuration

There is an error with this repository's Renovate configuration that needs to be fixed. As a precaution, Renovate will stop PRs until it is resolved.

Error type: undefined. Note: this is a nested preset so please contact the preset author if you are unable to fix it yourself.

Error evaluating cluster_mode when var.cluster_mode_enabled = true

Found a bug? Maybe our Slack Community can help.

Slack Community

Describe the Bug

Module fails to create Clustered Redis elasticache resource with error:

module.subnets.aws_nat_gateway.default[1]: Still creating... [1m50s elapsed]
module.subnets.aws_nat_gateway.default[0]: Still creating... [1m50s elapsed]
module.subnets.aws_nat_gateway.default[0]: Creation complete after 1m57s [id=]
module.subnets.aws_nat_gateway.default[1]: Creation complete after 1m57s [id=]
module.subnets.aws_route.default[1]: Creating...
module.subnets.aws_route.default[0]: Creating...
module.subnets.aws_route.default[0]: Creation complete after 1s [id=]
module.subnets.aws_route.default[1]: Creation complete after 1s [id=]

Error: Either `number_cache_clusters` or `cluster_mode` must be set

  on ../../main.tf line 81, in resource "aws_elasticache_replication_group" "default":
  81: resource "aws_elasticache_replication_group" "default" {

Expected Behavior

Successful creation of Clustered Redis resource when var.cluster_mode_enabled=true

Steps to Reproduce

Steps to reproduce the behavior:

  1. Clone repo
  2. Update cluster_mode_enabled default=true
  3. Update cluster_mode_replicas_per_node_group default=1
  4. Update cluster_mode_num_node_groups default=3

Screenshots

If applicable, add screenshots or logs to help explain your problem.

Environment (please complete the following information):

Mac OS
Terraform v0.12.23
+ provider.aws v2.53.0
+ provider.local v1.4.0
+ provider.null v2.1.2
+ provider.template v2.1.2

Additional Context

plan.txt
Add any other context about the problem here.

The parameter CacheSubnetGroupName must be provided and must not be blank.

I use the module, https://github.com/cloudposse/terraform-aws-elasticache-redis to provision elasticache redis. Below are the errors when I run terraform apply. I have no clue of these errors.

Terraform version: v0.13.5

module.redis.aws_elasticache_parameter_group.default[0]: Creating...

module.redis.aws_elasticache_subnet_group.default[0]: Creating...

Error: Error creating CacheSubnetGroup: InvalidParameterValue: The parameter CacheSubnetGroupName must be provided and must not be blank. status code: 400, request id: a1ab57b1-fa23-491c-aa7b-a2d3804014c9

Error: Error creating Cache Parameter Group: InvalidParameterValue: The parameter CacheParameterGroupName must be provided and must not be blank. status code: 400, request id: 9abc80b6-bd3b-46fd-8b9e-9bf14d1913eb

module "redis" {
  source                     = "git::https://github.com/cloudposse/terraform-aws-elasticache-redis.git?ref=tags/0.25.0"

  availability_zones               = var.azs
  vpc_id                           = module.vpc.vpc_id
  allowed_security_groups          = [data.aws_security_group.default.id]
  subnets                          = module.vpc.private_subnets
  cluster_size                     = var.redis_cluster_size #number_cache_clusters
  instance_type                    = var.redis_instance_type
  apply_immediately                = true
  automatic_failover_enabled       = false
  engine_version                   = var.engine_version
  family                           = var.family
  replication_group_id             = var.replication_group_id

  #at-rest encryption is to increase data security by encrypting on-disk data.
  at_rest_encryption_enabled       = var.at_rest_encryption_enabled

  #in-transit encryption protects data when it is moving from one location to another.
  transit_encryption_enabled       = var.transit_encryption_enabled

  cloudwatch_metric_alarms_enabled = var.cloudwatch_metric_alarms_enabled

  parameter = [
    {
      #Keyspace notifications send events for every operation affecting the Redis data space.
      name  = "notify-keyspace-events"
      value = "lK"
    }
  ]
  context = module.this.context
}

User Group Access Control List (instead of redis AUTH default)

Have a question? Please checkout our Slack Community or visit our Slack Archive.

Slack Community

Describe the Feature

For
https://github.com/cloudposse/terraform-aws-elasticache-redis
it would be great if there was a way to specify Access control option, and set User Group Access Control List
in order to use users other than the default

Expected Behavior

creation of a redis cluster with Access control option = User Group Access Control List (where the user group and user have already been created)

Use Case

security

Describe Ideal Solution

add Access _control_option resource, which can be set to User Group Access Control List
add User_Group_Access_Control_List resource set to a string (name of the list)

Alternatives Considered

Destroy command not removing parameter-group and subnet groups.

Hello,

I am using the plugin on our development platform, daily at night we want to destroy the redis cluster, and in morning start it back again. But the destroy command is not removing parameter-group and subnet-groups, created by the plugin. I get an error when running create after destroy

`
Error: Invalid index

on .terraform/modules/redis/main.tf line 56, in locals:
56: elasticache_member_clusters = module.this.enabled ? tolist(aws_elasticache_replication_group.default.0.member_clusters) : []
|----------------
| aws_elasticache_replication_group.default is empty tuple

The given key does not identify an element in this collection value.
`

When I manually delete it, and remove the tfstate file as well, then only it works.

Code:

`

module "redis" {
source = "git::https://github.com/cloudposse/terraform-aws-elasticache-redis.git?ref=master"
availability_zones = var.availability_zones
namespace = var.namespace
stage = var.stage
name = var.redis-name
vpc_id = data.aws_vpc.selected.id
allowed_security_groups = ["${aws_security_group.redis.id}","${data.aws_security_group.default.id}"]
subnets = [local.subnet_ids_list[0],local.subnet_ids_list[1]]
cluster_size = var.cluster_size
instance_type = var.instance_type
apply_immediately = true
engine_version = var.engine_version
family = var.family
at_rest_encryption_enabled = var.at_rest_encryption_enabled
transit_encryption_enabled = var.transit_encryption_enabled

parameter = [
  {
    name  = "notify-keyspace-events"
    value = "lK"
  }
]

}
`

What am I doing wrong?

v0.40.0 vs v0.39.0 security group behavior

With 0.40.0 the setup process of this module has become a little more complex.
Prior to 0.40.0 (e.g. with 0.39.0) one could simply tell the module to allow which SG's like so:

  allowed_security_groups = [
    module.api.ecs_service_security_group_id,
    join(",", module.bastion.security_group_ids)
  ]

It would allow any of these SG's to connect to var.port. Easy.

With v0.40.0 this has changed and now requires explicit declaration of rules like this:

  security_group_rules = [
    {
      type                     = "egress"
      from_port                = 0
      to_port                  = 65535
      protocol                 = "-1"
      cidr_blocks              = ["0.0.0.0/0"]
      source_security_group_id = null
      description              = "Allow all outbound traffic"
    },
    {
      type                     = "ingress"
      from_port                = 6379
      to_port                  = 6379
      protocol                 = "tcp"
      cidr_blocks              = []
      source_security_group_id = module.api.ecs_service_security_group_id
      description              = "Allow inbound Redis traffic from ECS"
    },
    {
      type                     = "ingress"
      from_port                = 6379
      to_port                  = 6379
      protocol                 = "tcp"
      cidr_blocks              = []
      source_security_group_id = join(",", module.bastion.security_group_ids)
      description              = "Allow inbound Redis traffic from Bastion"
    },
  ]

I have tried to define them as such:

  security_groups = [
    module.api.ecs_service_security_group_id,
    join(",", module.bastion.security_group_ids)
  ]

While they do get added to the Redis instance, it does not allow to connect from them.

The README shows a nice "allow all outbound" and a "allow all from VPC" example but the default value of the security_group_rules only contains the former.

Am I using this module the wrong way or is this actually they way it is supposed to work (now)? If so, is there something we can do to improve this behavior?

Add Example Usage

what

  • Add example invocation

why

  • We need this so we can soon enable automated continuous integration testing of module

Destroying resources fails

Error: Error in function call

on .terraform/modules/redis/outputs.tf line 17, in output "host":
17: value = coalesce(
18:
19:
20:
21:
22:
23:
|----------------
| aws_elasticache_replication_group.default is empty tuple
| module.dns.hostname is ""

Call to function "coalesce" failed: no non-null, non-empty-string arguments.

Use name_prefix and create_before_destroy on security groups

Found a bug? Maybe our Slack Community can help.

Slack Community

Describe the Bug

It can be a pain when the security group name changes as it would not be able to destroy - potentially using this pattern would work - https://github.com/terraform-aws-modules/terraform-aws-security-group/blob/master/main.tf#L34

Expected Behavior

Able to create new security group and assign it prior to destroy

Steps to Reproduce

Steps to reproduce the behavior:

  1. Go to '...'
  2. Run '....'
  3. Enter '....'
  4. See error

Screenshots

If applicable, add screenshots or logs to help explain your problem.

Environment (please complete the following information):

Anything that will help us triage the bug will help. Here are some ideas:

  • OS: [e.g. Linux, OSX, WSL, etc]
  • Version [e.g. 10.15]

Additional Context

Add any other context about the problem here.

'aws_elasticache_replication_group.default' does not have attribute 'primary_endpoint_address'

what

seeing this weird issue when I'm trying to use the terraform-aws-elasticache-redis

Error: Error running plan: 2 error(s) occurred:

* module.elasticache_redis.module.dns.var.records: Resource 'aws_elasticache_replication_group.default' does not have attribute 'primary_endpoint_address' for variable 'aws_elasticache_replication_group.default.*.primary_endpoint_address'
* module.elasticache_redis.output.id: Resource 'aws_elasticache_replication_group.default' does not have attribute 'id' for variable 'aws_elasticache_replication_group.default.*.id'

Additional outputs for the Redis Replication Group

Have a question? Please checkout our Slack Community or visit our Slack Archive.

Slack Community

Describe the Feature

Adding all of available outputs for the aws_elasticache_replication_group resource.

Expected Behavior

As an example for one of the missing outputs, reader_endpoint_address:
When using the module and referencing the module.EXAMPLE. reader_endpoint_address I would expect to receive the DNS endpoint for the reader node in the replication group.

Use Case

I am currently using your module to provide cache for Kong EE API Gateway and having it store session tokens as part of a plugin. I need some of the data planes to be able to read from the cache using the Reader Endpoint which at the moment they are not able to do.

Describe Ideal Solution

I would like all of the remaining available outputs from the aws_elasticache_replication_group to be made available. These include; arn, cluster_enabled, reader_endpoint_address and member_clusters

Alternatives Considered

At present, I don't believe there are any alternatives.

Additional Context

No additional context to add.

Thanks guys and keep up the awesome work!

0.42.0 - Error: CacheParameterGroupNotFound:

Hi there thanks for this great set of tooling. I appear to have run into a small issue with the cacheparamgroup

Found a bug? Maybe our Slack Community can help.

Slack Community

Describe the Bug

On use of latest 0.42.0 simple implementation can be provided on apply errors out


โ”‚ Error: CacheParameterGroupNotFound: CacheParameterGroup ps-prod-redis-cache not found.
โ”‚ 	status code: 404, request id: ccbf450d-4b2d-410e-95a9-2797c6d184d2
โ”‚

Expected Behavior

create a redis service

zone_id input listed as not required, throws error if not defined

I might be missing something here, but the 'zone_id' input is listed as not required with a default value of 'false' thus if it's not defined, TF throws an error:

Error: Error applying plan:

1 error(s) occurred:

  • module.elasticache.module.elasticache-redis.module.dns.aws_route53_record.default: 1 error(s) occurred:

  • aws_route53_record.default: NoSuchHostedZone: No hosted zone found with ID: false
    status code: 404, request id: a98d55b6-a9ca-11e8-87cd-a1203e2fe555

If it is set to empty literals:

Error: module.elasticache.module.elasticache-redis.module.dns.aws_route53_record.default: zone_id must not be empty

Support restoring from a snapshot

Have a question? Please checkout our Slack Community or visit our Slack Archive.

Slack Community

Describe the Feature

The elasticache replication group resource allows an optional parameter to restore from a snapshot. This module should support this parameter.

Expected Behavior

When snapshot_arns passed into the module, the created cluster is created from the snapshot. By default this should just be an empty list.

Use Case

From recovering from an older version of the redis cluster

Describe Ideal Solution

New variable snapshot_arns added and passed to the replication group resource

Alternatives Considered

Explain what alternative solutions or features you've considered.

Additional Context

Add any other context or screenshots about the feature request here.

Cloudwatch alarms insufficient data

I've created a redis without enabling the automatic_failover, only one node. The problem is that alarms at cloudwatch shows insufficient data.
The configured dimension value for CacheClusterId in the alarm is "myredis" and if I see in cloudwatch the current metrics having data are in dimension value "myredis-001".

Invalid function argument on v0.41.6

Describe the Bug

On version 0.41.6 of the module, when I attempt to import pre-existing items into my state that are unrelated to this module, I receive the following error:

โ”‚ Error: Invalid function argument
โ”‚
โ”‚   on .terraform/modules/redis_queue.aws_security_group/normalize.tf line 27, in locals:
โ”‚   27:     source_security_group_id = lookup(rule, "source_security_group_id", null)
โ”‚
โ”‚ Invalid value for "inputMap" parameter: lookup() requires a map as the first argument.

I am on version 1.1.2 of the Terraform CLI.

Expected Behavior

No failures due to module code failing to parse.

Steps to Reproduce

Create a terraform configuration that uses the module, like:

module "redis_queue" {
  count = local.environment == "staging" ? 0 : 1

  source                     = "cloudposse/elasticache-redis/aws"
  version                    = "0.41.6"
  availability_zones         = var.elasticache_availability_zones
  stage                      = local.environment
  name                       = var.elasticache_queue_name
  id_length_limit            = 40
  vpc_id                     = module.vpc.vpc_id
  allowed_cidr_blocks        = [module.vpc.vpc_cidr_block]
  subnets                    = module.vpc.database_subnets
  cluster_mode_enabled       = false
  cluster_size               = var.elasticache_cluster_size
  instance_type              = var.elasticache_queue_instance_size
  apply_immediately          = true
  automatic_failover_enabled = var.elasticache_cluster_size == 1 ? false : true
  multi_az_enabled           = var.elasticache_multi_az_enabled
  engine_version             = "6.x"
  family                     = "redis6.x"
  at_rest_encryption_enabled = false
  transit_encryption_enabled = false
  snapshot_window            = "05:00-06:00"
  snapshot_retention_limit   = var.elasticache_snapshot_retention_limit
  maintenance_window         = "wed:12:00-wed:14:00"
  tags                       = local.tags
}

Ensure you're on the noted version of the terraform CLI and Elasticache module.
Attempt to run "terraform import".
Observe the error.

Environment (please complete the following information):

  • Terraform v1.1.2
  • OS: Mac, Big Sur, no m1 processor
  • Module 0.41.6

Thank you for looking at this! Much appreciated.

Add option for auth_token

What

Add auth_token parameter to aws_elasticache_replication_group resource.

Why

Elasticache Redis supports Auth with versions 3.2.6 and 4.0.10+, now that this module's default family is 4.0 and version is 4.0.10 it would benefit users using this module for production clusters to be able to set an auth_token to follow security best practices.

Minutiae

Requires transit_encryption_enabled = true. Would not be compatible with users wanting to use this module with redis versions < 3.2.6.

security_groups input description is slightly misleading

The current description of the security_groups input is "AWS security group ids", which originally made me think that I should provide the module with pre-created security group ids. Since the module generates its own security groups, I believe that a more accurate description would be along the lines of "List of security group IDs to be allowed to connect to the cluster" (in line with your Elasticsearch's module secgroup input description)

Oh and thank you cloudposse people for the quality modules!

v0.40.0 requires two runs to create & apply security group

Describe the Bug

The v0.40.0 release requires two plan/apply stages to be executed to be fully useful.

In the first run, the security group is created:

  # module.redis.module.security_group.aws_security_group.default[0] will be created
  + resource "aws_security_group" "default" {
      + arn                    = (known after apply)
      + description            = "ElastiCache Security Group"
      + egress                 = (known after apply)
      + id                     = (known after apply)
      + ingress                = (known after apply)
      + name                   = "PROJECT-prod-redis"
      + name_prefix            = (known after apply)
      + owner_id               = (known after apply)
      + revoke_rules_on_delete = false
      + tags                   = {
          + "Name"      = "PROJECT-prod-redis"
          + "Namespace" = "PROJECT"
          + "Stage"     = "prod"
        }
      + tags_all               = {
          + "Name"      = "PROJECT-prod-redis"
          + "Namespace" = "PROJECT"
          + "Stage"     = "prod"
        }
      + vpc_id                 = "vpc-xxxxxxxxxxxxxxxxx"
    }

This security group is however not applied until the second run:

  # module.redis.aws_elasticache_replication_group.default[0] will be updated in-place
  ~ resource "aws_elasticache_replication_group" "default" {
        id                            = "PROJECT-prod-redis"
      ~ security_group_ids            = [
          - "sg-xxxxxxxxxxxx",
          + "sg-xxxxxxxxxxxx",
          - "sg-xxxxxxxxxxxx",
        ]
        tags                          = {
            "Name"      = "PROJECT-prod-redis"
            "Namespace" = "PROJECT"
            "Stage"     = "prod"
        }
        # (28 unchanged attributes hidden)

        # (1 unchanged block hidden)
    }

Expected Behavior

Security Group to be created & assigned in the same run.

Configuration

module "redis" {
  source        = "git::https://github.com/cloudposse/terraform-aws-elasticache-redis.git?ref=0.40.0"
  namespace     = local.label.namespace
  stage         = local.label.stage
  name          = "redis"
  zone_id       = aws_route53_zone.private.zone_id
  dns_subdomain = "redis"

  security_group_rules = [
    {
      type                     = "egress"
      from_port                = 0
      to_port                  = 65535
      protocol                 = "-1"
      cidr_blocks              = ["0.0.0.0/0"]
      source_security_group_id = null
      description              = "Allow all outbound traffic"
    },
    {
      type                     = "ingress"
      from_port                = 6379
      to_port                  = 6379
      protocol                 = "tcp"
      cidr_blocks              = []
      source_security_group_id = module.api.ecs_service_security_group_id
      description              = "Allow inbound Redis traffic from ECS"
    },
    {
      type                     = "ingress"
      from_port                = 6379
      to_port                  = 6379
      protocol                 = "tcp"
      cidr_blocks              = []
      source_security_group_id = join(",", module.bastion.security_group_ids)
      description              = "Allow inbound Redis traffic from Bastion"
    },
  ]

  auth_token                       = random_string.redis_auth_token.result
  vpc_id                           = module.vpc.vpc_id
  subnets                          = module.dynamic_subnets.private_subnet_ids
  cluster_size                     = "1"
  instance_type                    = "cache.t3.micro"
  engine_version                   = "5.0.6"
  family                           = "redis5.0"
  apply_immediately                = true
  availability_zones               = local.availability_zones
  automatic_failover_enabled       = false
  cloudwatch_metric_alarms_enabled = true
}

Environment (please complete the following information):

Anything that will help us triage the bug will help. Here are some ideas:

  • OS: Linux
  • Version v0.40.0

Additional Context

Add any other context about the problem here.

Issue managing 6.x clusters

When creating a cluster you have to specify 6.x as the engine_version otherwise you get this error:

Error creating Elasticache Replication Group: InvalidParameterValue: Specific version selection is not allowed for '6.0.5', please use '6.x'

After creating the cluster using 6.x subsiquent runs fail with the following error until you update engine_version to 6.0.5:

error updating Elasticache Replication Group (harbor-cache): InvalidParameterCombination: Upgrading minor engine version for redis '6.x' using modify API is not allowed, please use Service Updates

Allow passing in a map of parameters

Have a question? Please checkout our Slack Community or visit our Slack Archive.

Slack Community

Describe the Feature

Instead of passing in parameters like this

  parameters = [
    {
      name  = "activedefrag"
      value = "no"
    }
  ]

Use this

  map_parameters = {
    activedefrag = "no"
  }

Perhaps we can use an alternate variable like map_parameters

See https://github.com/cloudposse/terraform-aws-ecs-container-definition#input_map_environment for an example in another repo

Note: The values should also be trimmed or AWS API will throw errors

additional_security_group_rules parameter doesn't accept a list

Describe the Bug

Giving a list as a value to the additional_security_group_rules parameter causes a fail.

Expected Behavior

It should accept a list and the module should run smoothly.

Steps to Reproduce

Steps to reproduce the behavior:

  1. Give a list as a parameter to the additional_security_group_rules parameter and run the module, such as

additional_security_group_rules  = ["20.0.0.0/24", "20.0.1.0/24"]

Error log

โ•ท
โ”‚ Error: Invalid function argument
โ”‚ 
โ”‚   on .terraform/modules/aws_security_group/normalize.tf line 15, in locals:
โ”‚   15:     key         = coalesce(lookup(rule, "key", null), "${k}[${i}]")
โ”‚ 
โ”‚ Invalid value for "inputMap" parameter: lookup() requires a map as the
โ”‚ first argument.
โ•ต

Environment (please complete the following information):

  • Terraform v1.1.3

Solution

Give the parameter as a list of objects, such as:


additional_security_group_rules  = [{type = "ingress", from_port = 0, to_port = 6379, protocol = "tcp", cidr_blocks =  ["20.0.0.0/24", "20.0.1.0/24"]}]

Support Data Tiering

Describe the Feature

Variable to enable / disable data_tiering_enabled

Error: error creating ElastiCache Replication Group (REDIS-NAME): InvalidParameterCombination: When using the cache.r6gd.2xlarge node type, you must enable data tiering.

Expected Behavior

When using r6gd nodes, engine version 6.x, and tiering enabled it should create the ElastiCache Redis instance.

Describe Ideal Solution

Add a bool variable to control the feature

Invalid function argument in reader_endpoint_address output

Describe the Bug

Error during plan and apply

โ”‚ Error: Invalid function argument
โ”‚ 
โ”‚   on .terraform/modules/status-api-redis-prod/outputs.tf line 27, in output "reader_endpoint_address":
โ”‚   27:   value       = join("", aws_elasticache_replication_group.default.*.reader_endpoint_address)
โ”‚     โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
โ”‚     โ”‚ aws_elasticache_replication_group.default is tuple with 1 element
โ”‚ 
โ”‚ Invalid value for "lists" parameter: element 0 is null; cannot concatenate null values.

Expected Behavior

Plan and apply should not error

Steps to Reproduce

It seems that these are the parameters that make it fail, I have another cluster with cluster_mode_enabled set to false that doesn't have the issue

  cluster_mode_enabled                 = true
  cluster_mode_num_node_groups         = 1
  cluster_mode_replicas_per_node_group = 2

Environment:

Anything that will help us triage the bug will help. Here are some ideas:

  • OS: Debian GNU/Linux 11
  • version = "0.41.0" and "0.41.1"
  • tf version = Terraform v1.0.9

Issues getting started: Sub-dependencies call variable errors

Hi there!

Looks great with this module, looking forward to trying it out, but I am struggling to get started. It calls a few errors on me in the sub-dependencies, and help would be appreciated. Am I choking up in my versions? (my terraform-lock provided in the end)

Error 1:

โ”‚ Error: Unsupported argument
โ”‚ 
โ”‚   on .terraform/modules/redis/main.tf line 92, in resource "aws_elasticache_replication_group" "default":
โ”‚   92:   multi_az_enabled              = var.multi_az_enabled
โ”‚ 
โ”‚ An argument named "multi_az_enabled" is not expected here.

Error 2:

โ”‚ Error: Unsupported argument
โ”‚ 
โ”‚   on .terraform/modules/redis/main.tf line 105, in resource "aws_elasticache_replication_group" "default":
โ”‚  105:   final_snapshot_identifier     = var.final_snapshot_identifier
โ”‚ 
โ”‚ An argument named "final_snapshot_identifier" is not expected here.

Context:

I try to spin up the module with the example provided + adding my own vpc/subnets. See below:

module "redis" {
  source = "cloudposse/elasticache-redis/aws"
  # Cloud Posse recommends pinning every module to a specific version
  version = "0.39.0"
  availability_zones         = [var.availability_zone]
  namespace                  = var.namespace
  stage                      = var.env_name
  name                       = var.name
  vpc_id                     = data.terraform_remote_state.vpc.outputs.vpc_id
  subnets                    = data.terraform_remote_state.vpc.outputs.database_subnets_ids
  cluster_size               = var.cluster_size
  instance_type              = var.instance_type
  apply_immediately          = true
  automatic_failover_enabled = false
  engine_version             = var.engine_version
  family                     = var.family
  at_rest_encryption_enabled = var.at_rest_encryption_enabled
  transit_encryption_enabled = var.transit_encryption_enabled

  allowed_security_groups    = [data.terraform_remote_state.service.outputs.security_group_id]

  parameter = [
    {
      name  = "notify-keyspace-events"
      value = "lK"
    }
  ]
}

Versions I have in the environment:

Terraform v1.0.5
on darwin_amd64
provider "registry.terraform.io/hashicorp/aws" {
  version     = "2.70.0"
  constraints = ">= 2.0.0, ~> 2.0"
}

provider "registry.terraform.io/hashicorp/local" {
  version     = "2.1.0"
  constraints = ">= 1.2.0"

}

provider "registry.terraform.io/hashicorp/null" {
  version     = "3.1.0"
  constraints = ">= 2.0.0"
}

I am not a super-user of terraform, but not a "newbie" either โ€“ although it feels a bit like I might be making a noob mistake here. Any help would be appreciated!

Module is not idempotent

I believe this is because of the say the security group resource works. I've resolved this same issue in several modules (both CP and my own). If the SG resource defines an ingress rule, it "changes" every apply. Also, this makes it so that you can't add additional ingress rules from another module because when this one runs it will remove them.

Moving the ingress rule to a security_group_rule resouce resolves these issues.

Not supported with latest aws provider

Looks like latest aws provider doesn't accept empty auth token. Getting below exception when the auth token is not passed to the module

Error: module.elasticache_redis.aws_elasticache_replication_group.default: "auth_token" must contain from 16 to 128 alphanumeric characters or symbols (excluding @, ", and /)

Error: module.elasticache_redis.aws_elasticache_replication_group.default: only alphanumeric characters or symbols (excluding @, ", and /) allowed in "auth_token"

v0.41.3: Unable to apply new Parameter Group with existing resources

Describe the Bug

The changes done in v0.41.3 (#141) causes issues with existing resources.
Since it re-uses the same name Terraform will try to remove it. But since it is in use, it will fail:

โ”‚ Error: error deleting ElastiCache Parameter Group (PROJECT-staging-redis): InvalidCacheParameterGroupState: One or more cache clusters are still members of this parameter group PROJECT-staging-redis, so the group cannot be deleted.
โ”‚ 	status code: 400, request id: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

Expected Behavior

No errors when applying changes.

Potential solution

  • The parameter group needs to be create_before_destroy
  • A unique name should be used. In the RDS module we can use name_prefix for a similar issue but unfortunately the aws_elasticache_parameter_group resource does not support this.

If this is not possible we can work around this by making the description of the parameter group configurable, so that the Managed by Terraform value can be used for existing resources.

Why isn't cluster_mode configurable

Hello,

I saw that the cluster_mode block isn't exposed as part of the configuration. Is there an intention for this? Is this meant to be used only as a "cache cluster"? By "cache-cluster" I mean 1 write node and 0-5 replica read nodes, but no sharding (or node-groups).

EDIT: I was wondering if the idea of the module is to only deploy the replication group and the other shards (node-groups) have to be attached manually.

Argument is deprecated [elasticache_replication_group]

Found a bug? Maybe our Slack Community can help.

Slack Community

Describe the Bug

When planning an elasticache redis instance with a cluster_size = 2 and cluster_mode_enabled = false, using v0.42.0, a deprecation warning is issued.

Expected Behavior

No deprecation warnings are issued and a you have a clean plan.

Steps to Reproduce

Steps to reproduce the behavior:

  1. Create a redis instance with a cluster size of 2 and cluster mode disabled.
  2. Run 'terraform plan'
  3. See error
โ”‚ Warning: Argument is deprecated
โ”‚ 
โ”‚   with aws_elasticache_replication_group.default,
โ”‚   on main.tf line 116, in resource "aws_elasticache_replication_group" "default":
โ”‚  116: resource "aws_elasticache_replication_group" "default" {
โ”‚ 
โ”‚ Use num_node_groups and replicas_per_node_group instead
โ”‚ 
โ”‚ (and 4 more similar warnings elsewhere)

Screenshots

N/A

Environment (please complete the following information):

Anything that will help us triage the bug will help. Here are some ideas:

  • OS: OSx
  • Version 12.1

Additional Context

N/A

There should be a possibility to use your own security group

Hi,

Currently this module always creates a security group and there's no possibility to use my own (it is not allowed to create our own security groups in our organization).

Is it possible to add such option? I could easily overcome it by disabling the creation of it and changed in "aws_elasticache_replication_group" to use it from var.security_groups.

How to activate Multi-AZ option.

Describe the Bug

By default, I create a redis cluster, but I can't find how to active the Multi-Az option.
image

Expected Behavior

How can I do it , Thanks a lot !

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.