Command used: terraform import aws_elasticache_cluster.cache-redis cache-redis
In AWS env: cache-redis already exists
Config on terraform (if i run this config and apply it, it works fine)
resource “aws_elasticache_cluster” “cache-redis” {
cluster_id = “cache-redis”
engine = “redis”
engine_version = “6.2”
maintenance_window = “sun:05:00-sun:07:00”
node_type = var.aws_elasticache_cluster_node_type_t3
num_cache_nodes = 1
port = 6379
parameter_group_name = “default.redis6.x”
subnet_group_name = aws_elasticache_subnet_group.cache.name
availability_zone = “${var.aws_region}a”
security_group_ids = [aws_security_group.cache-sg.id]
}
Error: resource address “aws_elasticache_cluster.cache-redis” does not exist in the configuration.
Before importing this resource, please create its configuration in the root module. For example:
resource “aws_elasticache_cluster” “cache-redis” {
** # (resource arguments)**
}
Terraform v0.12.4
- provider.aws v2.70.0
- provider.template v2.1.2
FOR ANYONE IN THE FUTURE HAVING THE SAME ISSUE, HERE IS THE ANSWER AS I WAS NOT ABLE TO FIND ANY ONLINE
if you have nested modules you need to import it in the following way
terraform import module.aws_elasticache_cluster.cache-redis-other cache-redis
Get the cluster id by using the following command:
aws elasticache describe-cache-clusters --region=us-west-2 (your region)