Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

aws_elasticache_cluster does not correctly handle deleted clusters #3689

Closed
apparentlymart opened this issue Oct 29, 2015 · 3 comments
Closed

Comments

@apparentlymart
Copy link
Contributor

If the cluster associated with an aws_elasticache_cluster resource is deleted outside of Terraform, a subsequent terraform refresh will fail:

Error refreshing state: 1 error(s) occurred:

* aws_elasticache_cluster.web: CacheClusterNotFound: CacheCluster not found: omt-jsmith-dev
    status code: 404, request id: (elided)

The expected behavior is that it would call d.SetId("") to tell Terraform that the resource no longer exists, so that plan can know to create a fresh instance of the resource.

In the code we can see that it doesn't have any special handling for the 404 case, and it looks like it was instead expecting to get a 200 OK response with an empty set of CacheClusters. However, even if an empty set had been returned I think this would have still behaved improperly since it doesn't call d.SetId("") even in that case.

@stack72
Copy link
Contributor

stack72 commented Nov 5, 2015

@apparentlymart you are indeed correct , PR is on it's way. I just ran the following test:

  1. Created a elasticache cluster as follows:
provider "aws" {
    region = "us-east-1"
}
resource "aws_security_group" "bar" {
    name = "tf-test-security-group"
    description = "tf-test-security-group-descr"
    ingress {
        from_port = -1
        to_port = -1
        protocol = "icmp"
        cidr_blocks = ["0.0.0.0/0"]
    }
}

resource "aws_elasticache_security_group" "bar" {
    name = "tf-test-security-group"
    description = "tf-test-security-group-descr"
    security_group_names = ["${aws_security_group.bar.name}"]
}

resource "aws_elasticache_cluster" "bar" {
    cluster_id = "tf-test-sdsdfsffwfqw"
    engine = "memcached"
    node_type = "cache.m1.small"
    num_cache_nodes = 2
    port = 11211
    parameter_group_name = "default.memcached1.4"
    security_group_names = ["${aws_elasticache_security_group.bar.name}"]
}

I then went to the AWS UI and destroyed it. When running terraform refresh, I got the following:

Error refreshing state: 1 error(s) occurred:

* aws_elasticache_cluster.bar: CacheClusterNotFound: CacheCluster not found: tf-test-sdsdfsffwfqw
    status code: 404, request id: eb7b246f-83c5-11e5-9d16-9150d7bfbe93

I changed the code of the Read method as follows:

    res, err := conn.DescribeCacheClusters(req)
    if err != nil {
        if eccErr, ok := err.(awserr.Error); ok && eccErr.Code() == "CacheClusterNotFound" {
            d.SetId("")
            return nil
        }

        return err
    }

I was then able to refresh the state as required

@apparentlymart
Copy link
Contributor Author

Fixed in #3767!

omeid pushed a commit to omeid/terraform that referenced this issue Mar 30, 2018
@ghost
Copy link

ghost commented Apr 30, 2020

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@ghost ghost locked and limited conversation to collaborators Apr 30, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
2 participants