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

providers/aws: Add ElastiCache replication group support (fixes #1799) #2945

Closed
wants to merge 6 commits into from

Conversation

saulshanabrook
Copy link

This is based off of @inferiorhumanorgans work in #1799. I fixed some import paths and added a primary_endpoint attribute, so it can be used like this:

resource "aws_elasticache_replication_group" "default" {
    replication_group_id = "redis.fun"

    description = "redis fun"
    engine = "redis"
    cache_node_type = "${var.node_type}"
    num_cache_clusters = 2
    automatic_failover = true
    subnet_group_name = "${var.subnet_group_name}"
    security_group_ids  = ["${var.security_group_id}"]
}

resource "aws_route53_record" "default" {
    zone_id = "${var.zone_id}"
    name = "${var.engine}-${var.name}.${var.zone_name}"
    type = "CNAME"
    ttl = "30"
    records = [
        "${aws_elasticache_replication_group.default.primary_endpoint}."
    ]
}

@saulshanabrook
Copy link
Author

Looks like the tests failed:

builtin/providers/aws/resource_aws_elasticache_replication_group.go:109: undefined: aws.Boolean
builtin/providers/aws/resource_aws_elasticache_replication_group.go:110: undefined: aws.Long
builtin/providers/aws/resource_aws_elasticache_replication_group.go:182: undefined: aws.Boolean
builtin/providers/aws/resource_aws_elasticache_replication_group.go:188: undefined: aws.Boolean

Weird. It builds and passes tests on my local machine.

@dlsniper
Copy link
Contributor

dlsniper commented Aug 5, 2015

It might be that you use a different version of the aws sdk than the project, check it out: https://github.com/hashicorp/terraform/blob/master/deps/v0-6-1.json#L42 . Hope this helps.

@saulshanabrook
Copy link
Author

@dlsniper Those deps look like they are for the 0.6.1 release. Do you know how I update the deps for the next release?

@dlsniper
Copy link
Contributor

dlsniper commented Aug 5, 2015

Sorry, that's something I can't know, maybe someone else does? I've noticed some problems when running against the latest AWS sdk as well so I'm in the dark as well.

@joshgarnett
Copy link

@saulshanabrook Looking at http://docs.aws.amazon.com/sdk-for-go/api/aws.html I don't see aws.Boolean or aws.Long. It looks like there was a breaking change introduced in the SDK. Take a look at 579ccbe for an example where this was fixed in the other resources.

@saulshanabrook
Copy link
Author

@josephholsten That makes sense. OK I am trying to do make updatedeps but it keeps failing:

    imports google.golang.org/api/compute/v0.beta: cannot find package "google.golang.org/api/compute/v0.beta" in any of:
    /usr/local/Cellar/go/1.4.2/libexec/src/google.golang.org/api/compute/v0.beta (from $GOROOT)
    /Users/saul/projects/go/src/google.golang.org/api/compute/v0.beta (from $GOPATH)

@dlsniper
Copy link
Contributor

dlsniper commented Aug 6, 2015

Seems there's that it has been removed in this commit: googleapis/google-api-go-client@18450f4 (warning, it's a bit big). This looks like the new version: https://godoc.org/google.golang.org/api/compute/v1

@saulshanabrook
Copy link
Author

OK I am trying to rebase off of the master branch and then run make updatedeps again to see if that solves it.

Yep it does

@saulshanabrook
Copy link
Author

OK updated with new names.

@josephholsten
Copy link
Contributor

@saulshanabrook pretty sure you meant @joshgarnett, but I could definitely use this stuff. Thanks!

@joshgarnett
Copy link

@catsby any chance this can get merged soon?

@adubkov
Copy link

adubkov commented Aug 7, 2015

It works in general. But AZ distribution works weird. It put 2 boxes in same AZ, however when I create cluster witn AWS Console, it put them in different AZ.

Please add PreferredAvailabilityZone parameter.

resource "aws_elasticache_replication_group" "redis" {
    replication_group_id = "${concat(var.epop, \"-redis\")}"
    description = "test-sjc-redis"
    engine = "redis"
    cache_node_type = "cache.m3.medium"
    num_cache_clusters = 2
    automatic_failover = true
    subnet_group_name = "${aws_elasticache_subnet_group.redis.name}"
    security_group_ids = ["${aws_security_group.redis.id}"]
    depends_on = ["aws_elasticache_subnet_group.redis"]
}

Result:

{
    "ReplicationGroups": [
        {
            "Status": "available",
            "Description": "test-sjc-redis",
            "NodeGroups": [
                {
                    "Status": "available",
                    "NodeGroupMembers": [
                        {
                            "CurrentRole": "primary",
                            "PreferredAvailabilityZone": "us-west-1c",
                            "CacheNodeId": "0001",
                            "ReadEndpoint": {
                                "Port": 6379,
                                "Address": "test-sjc-redis-001.lcuh0x.0001.usw1.cache.amazonaws.com"
                            },
                            "CacheClusterId": "test-sjc-redis-001"
                        },
                        {
                            "CurrentRole": "replica",
                            "PreferredAvailabilityZone": "us-west-1c",
                            "CacheNodeId": "0001",
                            "ReadEndpoint": {
                                "Port": 6379,
                                "Address": "test-sjc-redis-002.lcuh0x.0001.usw1.cache.amazonaws.com"
                            },
                            "CacheClusterId": "test-sjc-redis-002"
                        }
                    ],
                    "NodeGroupId": "0001",
                    "PrimaryEndpoint": {
                        "Port": 6379,
                        "Address": "test-sjc-redis.lcuh0x.ng.0001.usw1.cache.amazonaws.com"
                    }
                }
            ],
            "ReplicationGroupId": "test-sjc-redis",
            "AutomaticFailover": "enabled",
            "MemberClusters": [
                "test-sjc-redis-001",
                "test-sjc-redis-002"
            ],
            "PendingModifiedValues": {}
        }
    ]
}

@adubkov
Copy link

adubkov commented Aug 7, 2015

@saulshanabrook
I made PR with this feature support to your fork.

@saulshanabrook
Copy link
Author

Thanks @blacked, merged. This was his example usage, from his PR:

resource "aws_elasticache_replication_group" "redis" {
    replication_group_id = "${concat(var.epop, \"-redis\")}"
    description = "test-sjc-redis"
    engine = "redis"
    cache_node_type = "cache.m3.medium"
    num_cache_clusters = 2
    automatic_failover = true
    subnet_group_name = "${aws_elasticache_subnet_group.redis.name}"
    security_group_ids = ["${aws_security_group.redis.id}"]

    preferred_cache_cluster_azs = [
        "us-west-1a",
        "us-west-1c",
    ]

    depends_on = [
        "aws_elasticache_subnet_group.redis",
        "aws_security_group.redis"
    ]
}

@catsby
Copy link
Contributor

catsby commented Aug 12, 2015

Hey @saulshanabrook thank you for the code contribution! Would you by chance be willing to add documentation for this new resource while I review the code and try it out?

Thanks!

@catsby catsby added enhancement waiting-response An issue/pull request is waiting for a response from the community provider/aws labels Aug 12, 2015
@catsby
Copy link
Contributor

catsby commented Aug 12, 2015

Am I correct in that this (as it stands) is not meant to create a cluster replication group for an existing ElastiCache Redis Cluster? There's no mention or use of PrimaryClusterId here. It seems that attribute is optional if NumCacheClusters is specified, but I'm wondering if we could add that here and support both cases?

stateConf := &resource.StateChangeConf{
Pending: pending,
Target: "available",
Refresh: ReplicationGroupStateRefreshFunc(conn, d.Id(), "available", pending),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ReplicationGroupStateRefreshFunc should not be exported, right? replicationGroupStateRefreshFunc instead.

Also, you send d.Id() as the id to ReplicationGroupStateRefreshFunc , before setting it with SetId, thus sending "". This causes the function to return false positives in the event that you already have a replication group defined "" will return all, and then you grab the first. In my case, I had two defined, so I got a false positive that my newest one was up and available.

Calling SetId before making the WaitForState() call should fix this 😄

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, just fixed, thank you!

@saulshanabrook
Copy link
Author

@catsby Yeah it looks like there are two ways to create a Replication Group and we should support both.

from the API docs:

PrimaryClusterId
The identifier of the cache cluster that will serve as the primary for this replication group. This cache cluster must already exist and have a status of available.

This parameter is not required if NumCacheClusters is specified.

Also I will add a ReplicationGroupId field to the ElasticacheCluster, which allows you to add individual clusters as read replicas.

@catsby
Copy link
Contributor

catsby commented Aug 31, 2015

Hey @saulshanabrook – sorry for the silence, is this ready for another review? Thanks again!

@saulshanabrook
Copy link
Author

@catsby Yep

@saulshanabrook
Copy link
Author

@catsby Anything else that I should do on my end?

@joshgarnett
Copy link

Any ETA on this?

@thegedge
Copy link
Contributor

Was just about to sit down and whip up a PR to do exactly this, so if there's anything we can do to help move this along to getting merged, let me know.

@saulshanabrook
Copy link
Author

@thegedge Awesome, thanks for taking a look at this. PR's against my branch would be really great, so that I can add your changes easier.

@jamesob
Copy link

jamesob commented Oct 14, 2015

+1. Would like to have this in.

@FlorinAndrei
Copy link

This would be incredibly useful, please merge.

@jgross206
Copy link

+1 would love this

@apparentlymart
Copy link
Contributor

For various other ElastiCache resources we had issues where the AWS API would accept mixed-case names for various things but then normalize them to lowercase and fail if we try to retrieve them using the original mixed-case names. See for example #3235 and #3120.

To make sure a similar bug isn't lurking here it'd be good to make the replication_group_id in the acceptance test include some uppercase characters. If that makes it fail, then the fix is probably similar to that of the two issues I linked above. (Sorry I don't have my Terraform dev env handy to test it myself right now.)

Separately, I have a terminology question: for several of the other ElastiCache objects the main identifier for the resource is name. In this case it's called replication_group_id. Would it be appropriate to rename the argument to name for consistency with the others, or is "Replication Group Id" how this is referred to in the AWS console UI?

@saulshanabrook
Copy link
Author

@apparentlymart That sounds like a good idea, for the case normalization. I am not working actively on this at the moment, but am happy to accept PR's against my branch.

@catsby catsby removed the waiting-response An issue/pull request is waiting for a response from the community label Oct 28, 2015
@HarryAtMove
Copy link

Would like to be using this, please merge

@@ -18,3 +18,4 @@ website/node_modules
*.bak
*~
.*.swp
config/lang/y.go
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should not be in the .gitignore. There's some oddness with go 1.4 and 1.5 but for now this file should just not be included in any changes, more ignored. Sorry for the hassle

@catsby
Copy link
Contributor

catsby commented Nov 10, 2015

I posted a few notes, but I think this needs some follow up. We need to merge/rebase master, and we need to evaluate what we're sending to the API. I got many "invalid parameter combination" errors when trying to specify all/some of the attributes.

@catsby catsby added the waiting-response An issue/pull request is waiting for a response from the community label Nov 10, 2015
@saulshanabrook
Copy link
Author

@catsby I am not actively working on this, at this time. If anyone wants these changes integrated, you are welcome to use this work here and propose a new PR onto this repo or my branch.

@dbethke
Copy link

dbethke commented Nov 25, 2015

+1. I'd like to use this.

@saulshanabrook
Copy link
Author

I am going to close this for now, since I am not going to fix it up.

@grayaii
Copy link
Contributor

grayaii commented Nov 30, 2015

Don't forget about tags... We're building from @dpetzold branch, so if possible we'll update it there...

@woodhull
Copy link

woodhull commented Dec 3, 2015

@catsby this seems like a feature that hashicorp should invest in given the original submitter closed the issue... and there are lots of people running a forked version to get the functionality.

@chadgrant
Copy link

@catsby Need this also

@aldarund
Copy link

+1, need this too

@HarryAtMove
Copy link

we could use this as well

@danielnbarbosa
Copy link

+1 this would be great to have

@dlsniper
Copy link
Contributor

dlsniper commented Mar 5, 2016

Can someone please lock this CLOSED issue so that it doesn't generate anymore +1 e-mails? Thank you!

@gposton
Copy link
Contributor

gposton commented Mar 11, 2016

@catsby @dlsniper, @dpetzold and I intend to follow up on the work that @saulshanabrook did here. From the inline comments, it doesn't look like there's much left to do. Am I missing something?

@inferiorhumanorgans
Copy link

@catsby any update on this?

@hashicorp hashicorp locked and limited conversation to collaborators Aug 22, 2016
@apparentlymart
Copy link
Contributor

I've locked this since the original submitter has said he no longer intends to work on this and so further discussion here isn't productive.

If someone would like to build on this and submit a new PR then that would be much appreciated!

@catsby
Copy link
Contributor

catsby commented Aug 22, 2016

Hey Friends – sorry for the silence here. @stack72 implemented aws_elasticache_replication_group in #8275, check it out! If you find something missing or have other feedback, please open a new issue

Thanks!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement provider/aws waiting-response An issue/pull request is waiting for a response from the community
Projects
None yet
Development

Successfully merging this pull request may close these issues.