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

Changes to aws_db_parameter_group variable calculations rejected by AWS for not matching capitalization are still persisted to state #14970

Closed
handlerbot opened this issue Sep 2, 2020 · 3 comments · Fixed by #18818
Assignees
Labels
service/rds Issues and PRs that pertain to the rds service. upstream-terraform Addresses functionality related to the Terraform core binary.
Milestone

Comments

@handlerbot
Copy link
Contributor

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • 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
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

Terraform CLI and Terraform AWS Provider Version

> terraform -v
Terraform v0.13.1
+ provider registry.terraform.io/hashicorp/aws v3.4.0

Affected Resource(s)

  • aws_db_parameter_group

Terraform Configuration Files

resource "aws_db_parameter_group" "x" {
  name        = "x"
  family      = "mysql5.7"

  parameter {
    name         = "innodb_buffer_pool_size"
    value        = "{DBInstanceClassmemory*8/19}"
    apply_method = "pending-reboot"
  }
}

Expected Behavior

Changes to the RDS parameter group not accepted by AWS are not persisted in the state file.

Actual Behavior

Changes to the RDS parameter group not accepted by AWS are persisted in the state file, overwriting the prior, still-retained configuration.

Steps to Reproduce

We start with having created the RDS parameter group with the config above:

> terraform state show aws_db_parameter_group.x
# aws_db_parameter_group.x:
resource "aws_db_parameter_group" "x" {
    arn         = "arn:aws:rds:us-west-2:<account_id>:pg:x"
    description = "Managed by Terraform"
    family      = "mysql5.7"
    id          = "x"
    name        = "x"

    parameter {
        apply_method = "pending-reboot"
        name         = "innodb_buffer_pool_size"
        value        = "{DBInstanceClassMemory*8/19}"
    }
}

Now, edit the above resource configuration to change {DBInstanceClassMemory*8/19} to {dBInstanceClassMemory*1/2}.
NOTE THAT THE FIRST LETTER IN THE STRING HAS BEEN LOWERCASED, D -> d

> terraform apply
aws_db_parameter_group.x: Refreshing state... [id=x]

An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:
  ~ update in-place

Terraform will perform the following actions:

  # aws_db_parameter_group.x will be updated in-place
  ~ resource "aws_db_parameter_group" "x" {
        arn         = "arn:aws:rds:us-west-2:<account_id>:pg:x"
        description = "Managed by Terraform"
        family      = "mysql5.7"
        id          = "x"
        name        = "x"
        tags        = {}

      + parameter {
          + apply_method = "pending-reboot"
          + name         = "innodb_buffer_pool_size"
          + value        = "{dBInstanceClassMemory*1/2}"
        }
      - parameter {
          - apply_method = "pending-reboot" -> null
          - name         = "innodb_buffer_pool_size" -> null
          - value        = "{dbinstanceclassmemory*8/19}" -> null
        }
    }

Plan: 0 to add, 1 to change, 0 to destroy.

Do you want to perform these actions?
  Terraform will perform the actions described above.
  Only 'yes' will be accepted to approve.

  Enter a value: yes

aws_db_parameter_group.x: Modifying... [id=x]

Error: Error modifying DB Parameter Group: InvalidParameterValue: value does not match pattern
	status code: 400, request id: 0db15cce-235a-4d25-b1ac-556b453b3241

> terraform state list
aws_db_parameter_group.x

> terraform state show aws_db_parameter_group.x
# aws_db_parameter_group.x:
resource "aws_db_parameter_group" "x" {
    arn         = "arn:aws:rds:us-west-2:<account_id>:pg:x"
    description = "Managed by Terraform"
    family      = "mysql5.7"
    id          = "x"
    name        = "x"
    tags        = {}

    parameter {
        apply_method = "pending-reboot"
        name         = "innodb_buffer_pool_size"
        value        = "{dBInstanceClassMemory*1/2}"
    }
}

> terraform plan -refresh=false

No changes. Infrastructure is up-to-date.
[...]

> terraform plan
Refreshing Terraform state in-memory prior to plan...
The refreshed state will be used to calculate this plan, but will not be
persisted to local or remote state storage.

aws_db_parameter_group.x: Refreshing state... [id=x]

------------------------------------------------------------------------

An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:
  ~ update in-place

Terraform will perform the following actions:

  # aws_db_parameter_group.x will be updated in-place
  ~ resource "aws_db_parameter_group" "x" {
        arn         = "arn:aws:rds:us-west-2:<account_id>:pg:x"
        description = "Managed by Terraform"
        family      = "mysql5.7"
        id          = "x"
        name        = "x"
        tags        = {}

      + parameter {
          + apply_method = "pending-reboot"
          + name         = "innodb_buffer_pool_size"
          + value        = "{dBInstanceClassMemory*1/2}"
        }
      - parameter {
          - apply_method = "pending-reboot" -> null
          - name         = "innodb_buffer_pool_size" -> null
          - value        = "{dbinstanceclassmemory*8/19}" -> null
        }
    }

Plan: 0 to add, 1 to change, 0 to destroy.

We can confirm this with the AWS console:
image

The *8/19 value is the actual value, but the state file now thinks otherwise.

I finally wrote the minimalist reproduction case for this in the course of testing out whether #12973 was still a live concern for us.

Interestingly, if you attempt to create an RDS parameter group that does not yet exist, and you use a capitalization of the variable different than what AWS wants, it also get persisted to the state file, but as tainted. ¯\(ツ)

@ghost ghost added the service/rds Issues and PRs that pertain to the rds service. label Sep 2, 2020
@github-actions github-actions bot added the needs-triage Waiting for first response or review from a maintainer. label Sep 2, 2020
@gdavison
Copy link
Contributor

gdavison commented Sep 2, 2020

Thanks for the issue, @handlerbot. This is related to an error in our shared Plugin SDK. hashicorp/terraform-plugin-sdk#476

@gdavison gdavison added upstream-terraform Addresses functionality related to the Terraform core binary. and removed needs-triage Waiting for first response or review from a maintainer. labels Sep 2, 2020
@github-actions github-actions bot added this to the v3.55.0 milestone Aug 18, 2021
@YakDriver YakDriver self-assigned this Aug 19, 2021
@github-actions
Copy link

This functionality has been released in v3.55.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!

@github-actions
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 Sep 19, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
service/rds Issues and PRs that pertain to the rds service. upstream-terraform Addresses functionality related to the Terraform core binary.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants