Is there anyone who know the way that make single master redis to master-slave ?

326 views
Skip to first unread message

Hyeongseob Kim

unread,
Dec 11, 2017, 10:36:31 AM12/11/17
to Terraform

Hi everyone!

I'm using terraform for my project.
and I met critical problem with terraform.


First, I created redis using following terraform modules few monthes ago.
- aws_elasticache_parameter_group
- aws_elasticache_cluster


the redis has only master node. ( 0 shard , 1 node, no replica, cluster mode not enabled )


last week, I decided to make the redis master-replica for safe.
There are a lot of data in the redis. so, I must change the structure without data lost.
I want to make the redis as following( 1 shard, 2 node, multi AZ automatic fail over, cluster mode not enabled)


On the AWS console, I'm able to change the redis through following process.
- add replica
- add node ( different AZ with Master node )
- enable Muti AZ

Next, I tried to do same job using terraform but I met problems so, couldn't
following are the ways that I tried


1st. way

As I found, following modules are used for master-replica redis.
- aws_elasticache_parameter_group
- aws_elasticache_replication_group


I used same aws_elasticache_parameter_group.
And use aws_elasticache_replication_group instead of aws_elasticache_cluster.
then 'Terraform plan' says, existed redis will be deleted and new redis will be created.
I think terraform recreate redis because existing redis and new redis structure use different terraform moules.
I can't use this.


2nd. way
Next, I decided to change the redis on aws and modify terraform.tfstate manually.
I created a redis ( 0 shard , 1 node, no replica, cluster mode not enabled ) for test.
and changed the redis structure to ( 1 shard, 2 node, multi AZ automatic fail over, cluster mode not enabled) on the aws console
then 'terraform plan' 
but it says nothing changed.
there are different points between terraform.tfstate and real aws component because I changed it.
but Terraform cant' recongnized it.

There are one more problem. 
in spite of ablove problem, I tried to proceed this way.
and I found 'terraform import' doesn't support 'aws_elasticache_replication_group'
so, I can't import the modified redis.
I gave up this way.


3nd way

In terraform document, I found that there is 'replication_group_id' in aws_elasticache_cluster module
so, I tried to use all of 3 modules below

- aws_elasticache_parameter_group
- aws_elasticache_cluster
- aws_elasticache_replication_group

add replication_group_id in the aws_elasticache_cluster module and give "aws_elasticache_replication_group.EXAMPLE.replication_group_id" as the value
then 'terraform plan'
it says "Error: aws_elasticache_cluster.redis_petertest: "replication_group_id": this field cannot be set"
also fail. 
The parameter isn't able to use. I couldn't find the reason.


My questions are...

1. Is there any way to make existing redis ( 0 shard , 1 node, no replica, cluster mode not enabled ) 
to ( 1 shard, 2 node, multi AZ automatic fail over, cluster mode not enabled) without data lost using terraform?
2. Is 'replication_group_id' in 'aws_elasticache_cluster' module available? I can't find the way.
3. If there is a way for 2nd question, Could you give me the example script to created redis using all of three modules below?
aws_elasticache_parameter_group, aws_elasticache_cluster and aws_elasticache_replication_group.


If there is anyway to make redis master slave stucture without data lost, please help me.

Reply all
Reply to author
Forward
0 new messages