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

[Bug]: Unable to ignore changes to RDS Postgres minor engine version #39579

Open YevheniiPokhvalii opened 1 month ago

YevheniiPokhvalii commented 1 month ago

Terraform Core Version

1.9.5

AWS Provider Version

5.69.0

Affected Resource(s)

aws_db_instance

Expected Behavior

Terraform should ignore the minor Postgres versions upgrade when auto_minor_version_upgrade = true. (auto_minor_version_upgrade is true by default)

Actual Behavior

api error InvalidParameterCombination: Cannot upgrade postgres from 13.15 to 13.13

Relevant Error/Panic Output Snippet

No response

Terraform Configuration Files

resource "aws_db_instance" "db_instance" {
  identifier              = "${var.env_name[var.environment]}-db-instance"
  engine                  = "postgres"
  db_name                 = "example_db"
  engine_version          = "13.13"
}

Steps to Reproduce

Run terraform plan

Terraform will perform the following actions:

  # aws_db_instance.db_instance will be updated in-place
  ~ resource "aws_db_instance" "db_instance" {
      ~ engine_version                        = "13.15" -> "13.13"
        id                                    = "db-someID"
}

Run terraform apply

api error InvalidParameterCombination: Cannot upgrade postgres from 13.15 to 13.13

Debug Output

No response

Panic Output

No response

Important Factoids

No response

References

This patch does not seem to fix the issue with Postgres versions: https://github.com/hashicorp/terraform-provider-aws/issues/1198

Postgres versioning: https://www.postgresql.org/docs/release/

Would you like to implement a fix?

None

github-actions[bot] commented 1 month ago

Community Note

Voting for Prioritization

Volunteering to Work on This Issue

trevorrea commented 1 month ago

Would you not use a lifecycle block for this:-

  lifecycle {
    ignore_changes = [
      engine_version
    ]
  }
YevheniiPokhvalii commented 1 month ago

Would you not use a lifecycle block for this:-

  lifecycle {
    ignore_changes = [
      engine_version
    ]
  }

This block is not a solution. It will not allow to update to major Postgres versions in the future. Someone fixed the same issue for MySQL versioning: https://github.com/hashicorp/terraform-provider-aws/issues/1198 But that solution does not work for Postgres versioning: https://www.postgresql.org/docs/release/

nekketsuuu commented 1 month ago

https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/db_instance#engine_version says

If auto_minor_version_upgrade is enabled, you can provide a prefix of the version such as 8.0 (for 8.0.36).

So, how about setting engine_version to 13 instead of 13.13?

YevheniiPokhvalii commented 1 month ago

https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/db_instance#engine_version says

If auto_minor_version_upgrade is enabled, you can provide a prefix of the version such as 8.0 (for 8.0.36).

So, how about setting engine_version to 13 instead of 13.13?

I tired that. I does not work. It tries to downgrade the database to 13 in this case. You'll see something like that:

  # aws_db_instance.db_instance will be updated in-place
  ~ resource "aws_db_instance" "db_instance" {
      ~ engine_version                        = "13.15" -> "13"
        id                                    = "db-someID"
}
nekketsuuu commented 1 month ago

Yes... I was falling into the same situation, too. It seems that this document was added at https://github.com/hashicorp/terraform-provider-aws/pull/3886 several years ago, but I don't know this is the intended behavior.