Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Terraform module to create AWS ElastiCache resources 🇺🇦

License

NotificationsYou must be signed in to change notification settings

terraform-aws-modules/terraform-aws-elasticache

Terraform module which creates AWS ElastiCache resources.

SWUbanner

Usage

Seeexamples directory for working examples to reference:

Memcached Cluster

module"elasticache" {source="terraform-aws-modules/elasticache/aws"cluster_id="example-memcached"create_cluster=truecreate_replication_group=falseengine="memcached"engine_version="1.6.17"node_type="cache.t4g.small"num_cache_nodes=2az_mode="cross-az"maintenance_window="sun:05:00-sun:09:00"apply_immediately=true# Security groupvpc_id=module.vpc.vpc_idsecurity_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 Groupsubnet_ids=module.vpc.private_subnets# Parameter Groupcreate_parameter_group=trueparameter_group_family="memcached1.6"parameters=[    {      name="idle_timeout"      value=60    }  ]tags={    Terraform="true"    Environment="dev"  }}

Redis Cluster

module"elasticache" {source="terraform-aws-modules/elasticache/aws"cluster_id="example-redis"create_cluster=truecreate_replication_group=falseengine_version="7.1"node_type="cache.t4g.small"maintenance_window="sun:05:00-sun:09:00"apply_immediately=true# Security groupvpc_id=module.vpc.vpc_idsecurity_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 Groupsubnet_ids=module.vpc.private_subnets# Parameter Groupcreate_parameter_group=trueparameter_group_family="redis7"parameters=[    {      name="latency-tracking"      value="yes"    }  ]tags={    Terraform="true"    Environment="dev"  }}

Redis Cluster Mode

module"elasticache" {source="terraform-aws-modules/elasticache/aws"replication_group_id="example-redis-cluster"# Cluster modecluster_mode_enabled=truenum_node_groups=2replicas_per_node_group=3automatic_failover_enabled=truemulti_az_enabled=truemaintenance_window="sun:05:00-sun:09:00"apply_immediately=true# Security groupvpc_id=module.vpc.vpc_idsecurity_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 Groupsubnet_ids=module.vpc.private_subnets# Parameter Groupcreate_parameter_group=trueparameter_group_family="redis7"parameters=[    {      name="latency-tracking"      value="yes"    }  ]tags={    Terraform="true"    Environment="dev"  }}

Redis Global Replication Group

module"elasticache_primary" {source="terraform-aws-modules/elasticache/aws"replication_group_id="example-redis-global-replication-group"create_primary_global_replication_group=trueengine_version="7.1"node_type="cache.r7g.large"# Security groupvpc_id=module.vpc.vpc_idsecurity_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 Groupsubnet_ids=module.vpc.private_subnets# Parameter Groupcreate_parameter_group=trueparameter_group_family="redis7"tags={    Terraform="true"    Environment="dev"  }}module"elasticache_secondary" {source="terraform-aws-modules/elasticache/aws"providers={    aws= aws.other_region  }replication_group_id="example-redis-global-replication-group"global_replication_group_id=module.elasticache_primary.global_replication_group_id# Security groupvpc_id=module.vpc.vpc_idsecurity_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 Groupsubnet_ids=module.vpc.private_subnetstags={    Terraform="true"    Environment="dev"  }}

Redis Replication Group

module"elasticache" {source="terraform-aws-modules/elasticache/aws"replication_group_id="example-redis-replication-group"engine_version="7.1"node_type="cache.t4g.small"transit_encryption_enabled=trueauth_token="PickSomethingMoreSecure123!"maintenance_window="sun:05:00-sun:09:00"apply_immediately=true# Security groupvpc_id=module.vpc.vpc_idsecurity_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 Groupsubnet_ids=module.vpc.private_subnets# Parameter Groupcreate_parameter_group=trueparameter_group_family="redis7"parameters=[    {      name="latency-tracking"      value="yes"    }  ]tags={    Terraform="true"    Environment="dev"  }}

Serverless Cache

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.arnmajor_engine_version="7"security_group_ids=[module.sg.security_group_id]snapshot_retention_limit=7subnet_ids=module.vpc.private_subnetsuser_group_id=module.cache_user_group.group_id}

Valkey Replication Group

module"elasticache" {source="terraform-aws-modules/elasticache/aws"replication_group_id=local.nameengine="valkey"engine_version="7.2"node_type="cache.t4g.small"transit_encryption_enabled=trueauth_token="PickSomethingMoreSecure123!"maintenance_window="sun:05:00-sun:09:00"apply_immediately=true# Security Groupvpc_id=module.vpc.vpc_idsecurity_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 Groupsubnet_group_name=local.namesubnet_group_description="Valkey replication group subnet group"subnet_ids=module.vpc.private_subnets# Parameter Groupcreate_parameter_group=trueparameter_group_name=local.nameparameter_group_family="valkey7"parameter_group_description="Valkey replication group parameter group"parameters=[    {      name="latency-tracking"      value="yes"    }  ]tags=local.tags}

Examples

Examples codified under theexamples 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!

Requirements

NameVersion
terraform>= 1.0
aws>= 5.93
random>= 3.0

Providers

NameVersion
aws>= 5.93
random>= 3.0

Modules

No modules.

Resources

NameType
aws_cloudwatch_log_group.thisresource
aws_elasticache_cluster.thisresource
aws_elasticache_global_replication_group.thisresource
aws_elasticache_parameter_group.thisresource
aws_elasticache_replication_group.globalresource
aws_elasticache_replication_group.thisresource
aws_elasticache_subnet_group.thisresource
aws_security_group.thisresource
aws_vpc_security_group_egress_rule.thisresource
aws_vpc_security_group_ingress_rule.thisresource
random_id.thisresource

Inputs

NameDescriptionTypeDefaultRequired
apply_immediatelyWhether any database modifications are applied immediately, or during the next maintenance window. Default isfalseboolnullno
at_rest_encryption_enabledWhether to enable encryption at restbooltrueno
auth_tokenThe password used to access a password protected server. Can be specified only iftransit_encryption_enabled = truestringnullno
auth_token_update_strategyStrategy to use when updating theauth_token. Valid values areSET,ROTATE, andDELETE. Defaults toROTATEstringnullno
auto_minor_version_upgradeSpecifies whether minor version engine upgrades will be applied automatically to the underlying Cache Cluster instances during the maintenance window. Only supported for engine typeredis andvalkey and if the engine version is 6 or higher. Defaults totrueboolnullno
automatic_failover_enabledSpecifies 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 groupsboolnullno
availability_zoneAvailability Zone for the cache cluster. If you want to create cache nodes in multi-az, usepreferred_availability_zones insteadstringnullno
az_modeWhether 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 aresingle-az orcross-az, default issingle-azstringnullno
cluster_idGroup identifier. ElastiCache converts this name to lowercase. Changing this value will re-create the resourcestring""no
cluster_modeSpecifies whether cluster mode is enabled or disabled. Valid values are enabled or disabled or compatiblestringnullno
cluster_mode_enabledWhether to enable Redis [cluster modehttps://docs.aws.amazon.com/AmazonElastiCache/latest/red-ug/Replication.Redis-RedisCluster.html]boolfalseno
createDetermines whether resources will be created (affects all resources)booltrueno
create_clusterDetermines whether an ElastiCache cluster will be created or notboolfalseno
create_parameter_groupDetermines whether the ElastiCache parameter group will be created or notboolfalseno
create_primary_global_replication_groupDetermines whether an primary ElastiCache global replication group will be createdboolfalseno
create_replication_groupDetermines whether an ElastiCache replication group will be created or notbooltrueno
create_secondary_global_replication_groupDetermines whether an secondary ElastiCache global replication group will be createdboolfalseno
create_security_groupDetermines if a security group is createdbooltrueno
create_subnet_groupDetermines whether the Elasticache subnet group will be created or notbooltrueno
data_tiering_enabledEnables data tiering. Data tiering is only supported for replication groups using ther6gd node type. This parameter must be set to true when usingr6gd nodesboolnullno
descriptionUser-created description for the replication groupstringnullno
engineName of the cache engine to be used for this cache cluster. Valid values arememcached,redis, orvalkeystring"redis"no
engine_versionVersion number of the cache engine to be used. If not set, defaults to the latest versionstringnullno
final_snapshot_identifier(Redis only) Name of your final cluster snapshot. If omitted, no final snapshot will be madestringnullno
global_replication_group_idThe ID of the global replication group to which this replication group should belongstringnullno
global_replication_group_id_suffixThe ID suffix of the global replication groupstringnullno
ip_discoveryThe IP version to advertise in the discovery protocol. Valid values areipv4 oripv6stringnullno
kms_key_arnThe ARN of the key that you wish to use if encrypting at rest. If not supplied, uses service managed encryption. Can be specified only ifat_rest_encryption_enabled = truestringnullno
log_delivery_configuration(Redis OSS or Valkey) Specifies the destination and format of Redis OSS/Valkey SLOWLOG or Redis OSS/Valkey Engine Logany
{
"slow-log": {
"destination_type": "cloudwatch-logs",
"log_format": "json"
}
}
no
maintenance_windowSpecifies the weekly time range for when maintenance on the cache cluster is performed. The format isddd:hh24:mi-ddd:hh24:mi (24H Clock UTC)stringnullno
multi_az_enabledSpecifies whether to enable Multi-AZ Support for the replication group. If true,automatic_failover_enabled must also be enabled. Defaults tofalseboolfalseno
network_typeThe IP versions for cache cluster connections. Valid values areipv4,ipv6 ordual_stackstringnullno
node_typeThe instance class used. For Memcached, changing this value will re-create the resourcestringnullno
notification_topic_arnARN of an SNS topic to send ElastiCache notifications tostringnullno
num_cache_clustersNumber of cache clusters (primary and replicas) this replication group will have. If Multi-AZ is enabled, the value of this parameter must be at least 2. Updates will occur before other modifications. Conflicts withnum_node_groups. Defaults to1numbernullno
num_cache_nodesThe initial number of cache nodes that the cache cluster will have. For Redis, this value must be 1. For Memcached, this value must be between 1 and 40. If this number is reduced on subsequent runs, the highest numbered nodes will be removednumber1no
num_node_groupsNumber of node groups (shards) for this Redis replication group. Changing this number will trigger a resizing operation before other settings modificationsnumbernullno
outpost_modeSpecify the outpost mode that will apply to the cache cluster creation. Valid values aresingle-outpost andcross-outpost, however AWS currently only supportssingle-outpost modestringnullno
parameter_group_descriptionThe description of the ElastiCache parameter group. Defaults toManaged by Terraformstringnullno
parameter_group_familyThe family of the ElastiCache parameter groupstring""no
parameter_group_nameThe name of the parameter group. Ifcreate_parameter_group istrue, this is the name assigned to the parameter group created. Otherwise, this is the name of an existing parameter groupstringnullno
parametersList of ElastiCache parameters to applylist(map(string))[]no
portThe port number on which each of the cache nodes will accept connections. For Memcached the default is11211, and for Redis the default port is6379numbernullno
preferred_availability_zonesList of the Availability Zones in which cache nodes are createdlist(string)[]no
preferred_cache_cluster_azsList of EC2 availability zones in which the replication group's cache clusters will be created. The order of the availability zones in the list is considered. The first item in the list will be the primary node. Ignored when updatinglist(string)[]no
preferred_outpost_arn(Required ifoutpost_mode is specified) The outpost ARN in which the cache cluster will be createdstringnullno
replicas_per_node_groupNumber of replica nodes in each node group. Changing this number will trigger a resizing operation before other settings modifications. Valid values are 0 to 5numbernullno
replication_group_idReplication group identifier. Whencreate_replication_group is set totrue, this is the ID assigned to the replication group created. Whencreate_replication_group is set tofalse, this is the ID of an externally created replication groupstringnullno
security_group_descriptionDescription of the security group createdstringnullno
security_group_idsOne or more VPC security groups associated with the cache clusterlist(string)[]no
security_group_nameName to use on security group createdstringnullno
security_group_namesNames of one or more Amazon VPC security groups associated with this replication grouplist(string)[]no
security_group_rulesSecurity group ingress and egress rules to add to the security group createdany{}no
security_group_tagsA map of additional tags to add to the security group createdmap(string){}no
security_group_use_name_prefixDetermines whether the security group name (security_group_name) is used as a prefixbooltrueno
snapshot_arns(Redis only) Single-element string list containing an Amazon Resource Name (ARN) of a Redis RDB snapshot file stored in Amazon S3list(string)[]no
snapshot_name(Redis only) Name of a snapshot from which to restore data into the new node group. Changingsnapshot_name forces a new resourcestringnullno
snapshot_retention_limit(Redis only) Number of days for which ElastiCache will retain automatic cache cluster snapshots before deleting themnumbernullno
snapshot_window(Redis only) Daily time range (in UTC) during which ElastiCache will begin taking a daily snapshot of your cache cluster. Example:05:00-09:00stringnullno
subnet_group_descriptionDescription for the Elasticache subnet groupstringnullno
subnet_group_nameThe name of the subnet group. Ifcreate_subnet_group istrue, this is the name assigned to the subnet group created. Otherwise, this is the name of an existing subnet groupstringnullno
subnet_idsList of VPC Subnet IDs for the Elasticache subnet grouplist(string)[]no
tagsA map of tags to add to all resourcesmap(string){}no
timeoutsDefine maximum timeout for creating, updating, and deleting cluster resourcemap(string){}no
transit_encryption_enabledEnable encryption in-transitbooltrueno
transit_encryption_modeA setting that enables clients to migrate to in-transit encryption with no downtime. Valid values arepreferred andrequiredstringnullno
user_group_idsUser Group ID to associate with the replication group. Only a maximum of one (1) user group ID is validlist(string)nullno
vpc_idIdentifier of the VPC where the security group will be createdstringnullno

Outputs

NameDescription
cloudwatch_log_group_arnArn of cloudwatch log group created
cloudwatch_log_group_nameName of cloudwatch log group created
cloudwatch_log_groupsMap of CloudWatch log groups created and their attributes
cluster_address(Memcached only) DNS name of the cache cluster without the port appended
cluster_arnThe ARN of the ElastiCache Cluster
cluster_cache_nodesList of node objects includingid,address,port andavailability_zone
cluster_configuration_endpoint(Memcached only) Configuration endpoint to allow host discovery
cluster_engine_version_actualBecause ElastiCache pulls the latest minor or patch for a version, this attribute returns the running version of the cache engine
global_replication_group_arnARN of the created ElastiCache Global Replication Group
global_replication_group_engine_version_actualThe full version number of the cache engine running on the members of this global replication group
global_replication_group_idID of the ElastiCache Global Replication Group
global_replication_group_node_groupsSet of node groups (shards) on the global replication group
parameter_group_arnThe AWS ARN associated with the parameter group
parameter_group_idThe ElastiCache parameter group name
replication_group_arnARN of the created ElastiCache Replication Group
replication_group_configuration_endpoint_addressAddress of the replication group configuration endpoint when cluster mode is enabled
replication_group_engine_version_actualBecause ElastiCache pulls the latest minor or patch for a version, this attribute returns the running version of the cache engine
replication_group_idID of the ElastiCache Replication Group
replication_group_member_clustersIdentifiers of all the nodes that are part of this replication group
replication_group_portPort of the primary node in the replication group, if the cluster mode is disabled
replication_group_primary_endpoint_addressAddress of the endpoint for the primary node in the replication group, if the cluster mode is disabled
replication_group_reader_endpoint_addressAddress of the endpoint for the reader node in the replication group, if the cluster mode is disabled
security_group_arnAmazon Resource Name (ARN) of the security group
security_group_idID of the security group
subnet_group_nameThe ElastiCache subnet group name

License

Apache-2.0 Licensed. SeeLICENSE.

Sponsor this project

  •  

Packages

No packages published

Contributors18

Languages


[8]ページ先頭

©2009-2025 Movatter.jp