feat: elasticache and inplace upgrade from redis to valkey
This commit is contained in:
@@ -0,0 +1,67 @@
|
|||||||
|
<!-- This readme file is generated with terraform-docs -->
|
||||||
|
# Elasticache
|
||||||
|
|
||||||
|
Deploy a test redis replication group and then in-place migrate to Valkey
|
||||||
|
|
||||||
|
## Migration steps (takes around 17m):
|
||||||
|
1. Backup existing instance. Note the version and parameter group
|
||||||
|
2. In the example resource below, change apply-immediately, engine, engine-version, and parameter group.
|
||||||
|
|
||||||
|
## When redis was initially deployed:
|
||||||
|
primary\_endpoint = "lab-cache001.rw4ynm.ng.0001.ape1.cache.amazonaws.com"
|
||||||
|
reader\_endpoint = "lab-cache001-ro.rw4ynm.ng.0001.ape1.cache.amazonaws.com"
|
||||||
|
|
||||||
|
## After in-place migration to Valkey:
|
||||||
|
primary\_endpoint = "lab-cache001.rw4ynm.ng.0001.ape1.cache.amazonaws.com"
|
||||||
|
reader\_endpoint = "lab-cache001-ro.rw4ynm.ng.0001.ape1.cache.amazonaws.com"
|
||||||
|
|
||||||
|
## Fallback
|
||||||
|
Simply reverting the code below will result in a replacement of the replication group. Meaning
|
||||||
|
fallback is not supported. One will need to deploy a new instance and restore from backup
|
||||||
|
|
||||||
|
## Requirements
|
||||||
|
|
||||||
|
| Name | Version |
|
||||||
|
|------|---------|
|
||||||
|
| terraform | >= 1.11.0 |
|
||||||
|
| aws | ~> 6.0 |
|
||||||
|
|
||||||
|
## Providers
|
||||||
|
|
||||||
|
| Name | Version |
|
||||||
|
|------|---------|
|
||||||
|
| aws | 6.37.0 |
|
||||||
|
|
||||||
|
## Modules
|
||||||
|
|
||||||
|
No modules.
|
||||||
|
|
||||||
|
## Resources
|
||||||
|
|
||||||
|
| Name | Type |
|
||||||
|
|------|------|
|
||||||
|
| [aws_elasticache_replication_group.example](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/elasticache_replication_group) | resource |
|
||||||
|
| [aws_elasticache_subnet_group.subnets](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/elasticache_subnet_group) | resource |
|
||||||
|
|
||||||
|
## Inputs
|
||||||
|
|
||||||
|
| Name | Description | Type | Default | Required |
|
||||||
|
|------|-------------|------|---------|:--------:|
|
||||||
|
| application | n/a | `any` | n/a | yes |
|
||||||
|
| aws-region | n/a | `any` | n/a | yes |
|
||||||
|
| customer-name | n/a | `any` | n/a | yes |
|
||||||
|
| environment | n/a | `any` | n/a | yes |
|
||||||
|
| owner | n/a | `any` | n/a | yes |
|
||||||
|
| project | n/a | `any` | n/a | yes |
|
||||||
|
|
||||||
|
## Outputs
|
||||||
|
|
||||||
|
| Name | Description |
|
||||||
|
|------|-------------|
|
||||||
|
| cluster\_endpoint | n/a |
|
||||||
|
| primary\_endpoint | n/a |
|
||||||
|
| reader\_endpoint | n/a |
|
||||||
|
|
||||||
|
---
|
||||||
|
## Authorship
|
||||||
|
This module was developed by xpk.
|
||||||
@@ -0,0 +1,60 @@
|
|||||||
|
/**
|
||||||
|
* # Elasticache
|
||||||
|
*
|
||||||
|
* Deploy a test redis replication group and then in-place migrate to Valkey
|
||||||
|
*
|
||||||
|
* ## Migration steps (takes around 17m):
|
||||||
|
* 1. Backup existing instance. Note the version and parameter group
|
||||||
|
* 2. In the example resource below, change apply-immediately, engine, engine-version, and parameter group.
|
||||||
|
*
|
||||||
|
* ## When redis was initially deployed:
|
||||||
|
* primary_endpoint = "lab-cache001.rw4ynm.ng.0001.ape1.cache.amazonaws.com"
|
||||||
|
* reader_endpoint = "lab-cache001-ro.rw4ynm.ng.0001.ape1.cache.amazonaws.com"
|
||||||
|
*
|
||||||
|
* ## After in-place migration to Valkey:
|
||||||
|
* primary_endpoint = "lab-cache001.rw4ynm.ng.0001.ape1.cache.amazonaws.com"
|
||||||
|
* reader_endpoint = "lab-cache001-ro.rw4ynm.ng.0001.ape1.cache.amazonaws.com"
|
||||||
|
*
|
||||||
|
* ## Fallback
|
||||||
|
* Simply reverting the code below will result in a replacement of the replication group. Meaning
|
||||||
|
* fallback is not supported. One will need to deploy a new instance and restore from backup
|
||||||
|
*/
|
||||||
|
|
||||||
|
resource "aws_elasticache_replication_group" "example" {
|
||||||
|
automatic_failover_enabled = true
|
||||||
|
preferred_cache_cluster_azs = ["ap-east-1a", "ap-east-1b"]
|
||||||
|
replication_group_id = "lab-cache001"
|
||||||
|
description = "Redis to be migrated to Valkey"
|
||||||
|
node_type = "cache.t4g.micro"
|
||||||
|
num_cache_clusters = 2
|
||||||
|
cluster_mode = "enabled"
|
||||||
|
# -------- in-place migration to valkey -------- #
|
||||||
|
# engine_version = "7.1"
|
||||||
|
# engine = "redis"
|
||||||
|
# parameter_group_name = "default.redis7.cluster.on"
|
||||||
|
apply_immediately = true
|
||||||
|
engine = "valkey"
|
||||||
|
engine_version = "8.2"
|
||||||
|
parameter_group_name = "default.valkey8.cluster.on"
|
||||||
|
# -------- in-place migration to valkey -------- #
|
||||||
|
port = 6379
|
||||||
|
subnet_group_name = aws_elasticache_subnet_group.subnets.name
|
||||||
|
}
|
||||||
|
|
||||||
|
resource "aws_elasticache_subnet_group" "subnets" {
|
||||||
|
description = "Lab subnet group"
|
||||||
|
name = "lab-subnetgroup001"
|
||||||
|
subnet_ids = ["subnet-0927ba1b06ccfe6c5", "subnet-0551e96ffd016192a"]
|
||||||
|
}
|
||||||
|
|
||||||
|
output "cluster_endpoint" {
|
||||||
|
value = aws_elasticache_replication_group.example.configuration_endpoint_address
|
||||||
|
}
|
||||||
|
|
||||||
|
output "primary_endpoint" {
|
||||||
|
value = aws_elasticache_replication_group.example.primary_endpoint_address
|
||||||
|
}
|
||||||
|
|
||||||
|
output "reader_endpoint" {
|
||||||
|
value = aws_elasticache_replication_group.example.reader_endpoint_address
|
||||||
|
}
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
provider "aws" {
|
||||||
|
region = var.aws-region
|
||||||
|
|
||||||
|
default_tags {
|
||||||
|
tags = {
|
||||||
|
Environment = var.environment
|
||||||
|
Project = var.project
|
||||||
|
Application = var.application
|
||||||
|
TerraformDir = join("/", reverse(slice(reverse(split("/", path.cwd)), 0, 2)))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
terraform {
|
||||||
|
required_version = ">= 1.11.0"
|
||||||
|
required_providers {
|
||||||
|
aws = {
|
||||||
|
source = "hashicorp/aws"
|
||||||
|
version = "~> 6.0"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
variable "aws-region" {}
|
||||||
|
variable "customer-name" {}
|
||||||
|
variable "environment" {}
|
||||||
|
variable "project" {}
|
||||||
|
variable "application" {}
|
||||||
|
variable "owner" {}
|
||||||
Reference in New Issue
Block a user