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

[Bug]: aws_elasticache_replication_group recreates resource on engine_version upgrade #28011

Closed
madpipeline opened this issue Nov 24, 2022 · 6 comments · Fixed by #33954
Closed
Assignees
Labels
bug Addresses a defect in current functionality. prioritized Part of the maintainer teams immediate focus. To be addressed within the current quarter. service/elasticache Issues and PRs that pertain to the elasticache service.
Milestone

Comments

@madpipeline
Copy link
Contributor

Terraform Core Version

v1.3.5

AWS Provider Version

v4.40.0

Affected Resource(s)

  • aws_elasticache_replication_group

Expected Behavior

When upgrading the aws_elasticache_replication_group engine_version from any version to any version to upgrade the resource in-place, just like in the AWS Console.

Actual Behavior

When upgrading from version 2.8.24 to any other higher version, the plan wants to destroy and recreate the resource.

Upgrading from any other higher version to a higher version works as expected.

Relevant Error/Panic Output Snippet

No response

Terraform Configuration Files

provider "aws" {
  region = var.aws_region
}

module "vpc" {
  source = "terraform-aws-modules/vpc/aws"

  name = local.prefix
  cidr = "10.0.0.0/16"

  azs             = ["eu-west-1a", "eu-west-1b", "eu-west-1c"]
  private_subnets = ["10.0.1.0/24", "10.0.2.0/24", "10.0.3.0/24"]
  public_subnets  = ["10.0.101.0/24", "10.0.102.0/24", "10.0.103.0/24"]
  elasticache_subnets = ["10.0.31.0/24", "10.0.32.0/24"]

  enable_nat_gateway = true
  create_elasticache_subnet_group = true

  tags = local.common_tags
}

resource "aws_elasticache_replication_group" "session_mgm" {
  replication_group_id  = local.prefix
  description           = local.prefix
  node_type             = "cache.t2.micro"
  number_cache_clusters = "1"
  port                  = "6379"
  engine                = "redis"
  engine_version        = "6.2" # "3.2.6" # "2.8.24"

  availability_zones         = ["eu-west-1a"]
  automatic_failover_enabled = false
  subnet_group_name          = module.vpc.elasticache_subnet_group_name
  # security_group_ids         = [var.default_sg]
  parameter_group_name       = "default.redis6.x" # "default.redis3.2" # "default.redis2.8"

  auto_minor_version_upgrade = "true"
  maintenance_window         = "sun:03:00-sun:04:00"
  snapshot_window            = "00:00-01:00"
  snapshot_retention_limit   = "1"
  apply_immediately          = "false"

  tags = local.common_tags
}

Steps to Reproduce

  • Deploy the provided snippet with engine version set to 2.8.24
  • Change the engine version to any higher version
  • run terraform plan

The plan will attempt to destroy-recreate the resource instead of upgrading in place.

Debug Output

No response

Panic Output

No response

Important Factoids

According to the CloudFormation documentation on the Engine version, the upgrade should happen in place, with no down time.

References

Would you like to implement a fix?

Yes

@madpipeline madpipeline added bug Addresses a defect in current functionality. needs-triage Waiting for first response or review from a maintainer. labels Nov 24, 2022
@github-actions
Copy link

Community Note

Voting for Prioritization

  • Please vote on this issue by adding a 👍 reaction to the original post to help the community and maintainers prioritize this request.
  • Please see our prioritization guide for information on how we prioritize.
  • Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for issue followers and do not help prioritize the request.

Volunteering to Work on This Issue

  • If you are interested in working on this issue, please leave a comment.
  • If this would be your first contribution, please review the contribution guide.

@github-actions github-actions bot added the service/elasticache Issues and PRs that pertain to the elasticache service. label Nov 24, 2022
@breathingdust breathingdust removed the needs-triage Waiting for first response or review from a maintainer. label Nov 25, 2022
@apanzerj
Copy link
Contributor

apanzerj commented Dec 9, 2022

I'm seeing this issue when upgrading from 6 => 7 as well.

It does a drop and replace.

@josacar
Copy link

josacar commented Jan 13, 2023

I was able to replicate the bug:

package main

import (
	"fmt"
	gversion "github.com/hashicorp/go-version"
	"math"
	"regexp"
)

const (
	redisVersionPreV6RegexpRaw  = `[1-5](\.[[:digit:]]+){2}`
	redisVersionPostV6RegexpRaw = `(([6-9])\.x)|([6-9]\.[[:digit:]]+)`

	redisVersionRegexpRaw = redisVersionPreV6RegexpRaw + "|" + redisVersionPostV6RegexpRaw
)

const (
	redisVersionRegexpPattern       = "^" + redisVersionRegexpRaw + "$"
	redisVersionPostV6RegexpPattern = "^" + redisVersionPostV6RegexpRaw + "$"
)

var (
	redisVersionRegexp       = regexp.MustCompile(redisVersionRegexpPattern)
	redisVersionPostV6Regexp = regexp.MustCompile(redisVersionPostV6RegexpPattern)
)

func normalizeEngineVersion(version string) (*gversion.Version, error) {
	if matches := redisVersionPostV6Regexp.FindStringSubmatch(version); matches != nil {
		if matches[1] != "" {
			version = fmt.Sprintf("%s.%d", matches[2], math.MaxInt)
		} else if matches[3] != "" {
			version = matches[3]
		}
	}
	return gversion.NewVersion(version)
}

func main() {
	oVersion, _ := normalizeEngineVersion("6.x")
	nVersion, _ := normalizeEngineVersion("6.0")

	print(nVersion.LessThan(oVersion))
}

This return true as x is 'higher' than any digit.

When comparing two versions:

func main() {
        oVersion, _ := normalizeEngineVersion("6.0")
        nVersion, _ := normalizeEngineVersion("6.2")

        print(nVersion.LessThan(oVersion))
}

Works as expected returning false

@josacar
Copy link

josacar commented Jan 13, 2023

Looks like changing this:

const (
  redisVersionRegexpPattern       = "^" + redisVersionRegexpRaw + "$"
  redisVersionPostV6RegexpPattern = "^" + redisVersionPostV6RegexpRaw + "$"
)

to:

const (
  redisVersionRegexpPattern       = "^(?:" + redisVersionRegexpRaw + ")$"
  redisVersionPostV6RegexpPattern = "^(?:" + redisVersionPostV6RegexpRaw + ")$"
)

works fine, as with the previous implementation 2.8.12 will be detected as 8.12 as minor is higher or equal than 6

@gdavison gdavison self-assigned this Oct 13, 2023
@terraform-aws-provider terraform-aws-provider bot added the prioritized Part of the maintainer teams immediate focus. To be addressed within the current quarter. label Oct 13, 2023
@github-actions github-actions bot added this to the v5.22.0 milestone Oct 19, 2023
@github-actions github-actions bot removed the bug Addresses a defect in current functionality. label Oct 20, 2023
@github-actions
Copy link

This functionality has been released in v5.22.0 of the Terraform AWS Provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading.

For further feature requests or bug reports with this functionality, please create a new GitHub issue following the template. Thank you!

Copy link

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 20, 2023
@justinretzolk justinretzolk added the bug Addresses a defect in current functionality. label Feb 10, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Addresses a defect in current functionality. prioritized Part of the maintainer teams immediate focus. To be addressed within the current quarter. service/elasticache Issues and PRs that pertain to the elasticache service.
Projects
None yet
6 participants