hashicorp / terraform-provider-aws

The AWS Provider enables Terraform to manage AWS resources.
https://registry.terraform.io/providers/hashicorp/aws
Mozilla Public License 2.0
9.86k stars 9.2k forks source link

[New Data source]: aws_elasticache_snapshot for automating destroy and recreate of Elasticache clusters or replication sets #28984

Open bdubertret opened 1 year ago

bdubertret commented 1 year ago

Description

When deploying Elasticache clusters or replication group with Terraform, we can't destroy and recreate said cluster or replication set automatically. The PR #15592 introduced the ability to store a final snapshot. But it's impossible to automatically retrieve this final snapshot in a later invocation of the module, because there is no aws_elasticache_snapshot data source.

This behavior is possible with RDS snapshots, as is proposed in the documentation for aws_rds_snapshot resource : https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/db_snapshot#example-usage

The idea is to be able to tear down (destroy) a terraform module, containing an Elasticache cluster or replication group, and later bring it back to life in the same state.

Requested Resource(s) and/or Data Source(s)

Potential Terraform Configuration

resource "random_id" "snapshot_identifier" {
  byte_length = 4
}

resource "aws_elasticache_cluster" "example" {
  cluster_id      = "example-cluster"
  engine          = "redis"
  node_type       = "cache.t3.small"
  final_snapshot  = "example-cluster-final-${random_id.snapshot_identifier.hex}"
  snapshot_name   = data.aws_elasticache_snapshot.latest.snapshot_name
  num_cache_nodes = 1
}

data "aws_elasticache_snapshot" "latest" {
  cluster_id  = aws_elasticache_cluster.test.cluster_id
  most_recent = true
}

References

15592

14959

Would you like to implement a fix?

Yes

github-actions[bot] commented 1 year ago

Community Note

Voting for Prioritization

Volunteering to Work on This Issue

cescobaz commented 2 months ago

Hello, I have the same issue with the ebs volume: when re-creating the volume I'm not able to load the final_snapshot just created during deletion.