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_db_parameter_group apply_method causing constant diff - pending-reboot -> immediate #18035

Closed
joshbranham opened this issue Mar 10, 2021 · 3 comments · Fixed by #18818
Closed
Assignees
Labels
service/rds Issues and PRs that pertain to the rds service.
Milestone

Comments

@joshbranham
Copy link

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

Affected Resource(s)

❯ terraform -v
Terraform v0.13.5
+ provider registry.terraform.io/hashicorp/aws v3.24.1
+ provider registry.terraform.io/hashicorp/random v3.0.1

Terraform Configuration Files

Please include all Terraform configurations required to reproduce the bug. Bug reports without a functional reproduction may be closed without investigation.

# input variable on a module with parameters
custom_database_parameters = [
    {
      name  = "autovacuum"
      value = "1"
    },
    {
      name  = "idle_in_transaction_session_timeout"
      value = "14400000"
    },
    {
      name  = "log_autovacuum_min_duration"
      value = "5000"
    },
    {
      name  = "log_duration"
      value = "0"
    },
    {
      name  = "log_lock_waits"
      value = "1"
    },
    {
      name  = "log_min_error_statement"
      value = "error"
    },
    {
      name  = "log_statement"
      value = "ddl"
    },
    {
      name  = "pg_stat_statements.track"
      value = "all"
    },
    {
      name  = "rds.force_ssl"
      value = "1"
    },
    {
      name  = "rds.log_retention_period"
      value = "1440"
    },
    {
      name         = "track_activity_query_size"
      value        = "2048"
      apply_method = "pending-reboot"
    },
    {
      name  = "autovacuum_vacuum_cost_delay",
      value = "5"
    },
    {
      name  = "autovacuum_vacuum_cost_limit",
      value = "10000"
    },
    {
      name  = "autovacuum_work_mem",
      value = "2097152"
    },
    {
      name  = "work_mem",
      value = "8192"
    },
    {
      name  = "checkpoint_timeout",
      value = "600"
    },
    {
      name  = "max_wal_size",
      value = "16384"
    },
    {
      name  = "random_page_cost",
      value = "1.1"
    }
  ]

# module code that takes those in

resource "aws_db_parameter_group" "default" {
  name        = local.parameter_group_name
  description = var.parameter_group_description
  family      = var.parameter_group_family

  dynamic "parameter" {
    for_each = local.database_parameters

    content {
      name         = parameter.value.name
      value        = parameter.value.value
      apply_method = lookup(parameter.value, "apply_method", null)
    }
  }

  tags = local.tags
}

Debug Output

This is the specific output related to the parameter group

https://gist.github.com/joshbranham/bd1a5f5c46ac0aef8614e8197e7824fb

Expected Behavior

I changed one parameter in the custom_database_parameters and it should only have a diff for that value

Actual Behavior

The diff includes most parameters and wants to change the apply_method

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:

  # module.rds.aws_db_parameter_group.default will be updated in-place
  ~ resource "aws_db_parameter_group" "default" {
        arn         = "arn:aws:rds:us-east-1:715666668144:pg:production-rds-indexing-service-dbparamgroup"
        description = "Managed by Terraform"
        family      = "postgres12"
        id          = "production-rds-indexing-service-dbparamgroup"
        name        = "production-rds-indexing-service-dbparamgroup"
        tags        = {
            "Name"                = "salsify-indexing-service-production"
            "salsify:environment" = "production"
            "salsify:owner"       = "platform-foundations"
            "salsify:platform"    = "indexing-service"
            "salsify:terraform"   = "owned"
        }

      + parameter {
          + apply_method = "immediate"
          + name         = "autovacuum"
          + value        = "1"
        }
      + parameter {
          + apply_method = "immediate"
          + name         = "autovacuum_vacuum_cost_delay"
          + value        = "5"
        }
      + parameter {
          + apply_method = "immediate"
          + name         = "autovacuum_vacuum_cost_limit"
          + value        = "10000"
        }
      + parameter {
          + apply_method = "immediate"
          + name         = "autovacuum_work_mem"
          + value        = "2097152"
        }
      + parameter {
          + apply_method = "immediate"
          + name         = "checkpoint_timeout"
          + value        = "600"
        }
      + parameter {
          + apply_method = "immediate"
          + name         = "idle_in_transaction_session_timeout"
          + value        = "14400000"
        }
      + parameter {
          + apply_method = "immediate"
          + name         = "log_autovacuum_min_duration"
          + value        = "5000"
        }
      + parameter {
          + apply_method = "immediate"
          + name         = "log_duration"
          + value        = "0"
        }
      + parameter {
          + apply_method = "immediate"
          + name         = "log_lock_waits"
          + value        = "1"
        }
      + parameter {
          + apply_method = "immediate"
          + name         = "log_min_error_statement"
          + value        = "error"
        }
      + parameter {
          + apply_method = "immediate"
          + name         = "log_statement"
          + value        = "ddl"
        }
        parameter {
            apply_method = "immediate"
            name         = "max_wal_size"
            value        = "16384"
        }
      + parameter {
          + apply_method = "immediate"
          + name         = "pg_stat_statements.track"
          + value        = "all"
        }
        parameter {
            apply_method = "immediate"
            name         = "random_page_cost"
            value        = "1.1"
        }
      + parameter {
          + apply_method = "immediate"
          + name         = "rds.force_ssl"
          + value        = "1"
        }
      + parameter {
          + apply_method = "immediate"
          + name         = "rds.log_retention_period"
          + value        = "1440"
        }
      + parameter {
          + apply_method = "immediate"
          + name         = "work_mem"
          + value        = "8193"
        }
      - parameter {
          - apply_method = "pending-reboot" -> null
          - name         = "autovacuum" -> null
          - value        = "1" -> null
        }
      - parameter {
          - apply_method = "pending-reboot" -> null
          - name         = "autovacuum_vacuum_cost_delay" -> null
          - value        = "5" -> null
        }
      - parameter {
          - apply_method = "pending-reboot" -> null
          - name         = "autovacuum_vacuum_cost_limit" -> null
          - value        = "10000" -> null
        }
      - parameter {
          - apply_method = "pending-reboot" -> null
          - name         = "autovacuum_work_mem" -> null
          - value        = "2097152" -> null
        }
      - parameter {
          - apply_method = "pending-reboot" -> null
          - name         = "checkpoint_timeout" -> null
          - value        = "600" -> null
        }
      - parameter {
          - apply_method = "pending-reboot" -> null
          - name         = "idle_in_transaction_session_timeout" -> null
          - value        = "14400000" -> null
        }
      - parameter {
          - apply_method = "pending-reboot" -> null
          - name         = "log_autovacuum_min_duration" -> null
          - value        = "5000" -> null
        }
      - parameter {
          - apply_method = "pending-reboot" -> null
          - name         = "log_duration" -> null
          - value        = "0" -> null
        }
      - parameter {
          - apply_method = "pending-reboot" -> null
          - name         = "log_lock_waits" -> null
          - value        = "1" -> null
        }
      - parameter {
          - apply_method = "pending-reboot" -> null
          - name         = "log_min_error_statement" -> null
          - value        = "error" -> null
        }
      - parameter {
          - apply_method = "pending-reboot" -> null
          - name         = "log_statement" -> null
          - value        = "ddl" -> null
        }
      - parameter {
          - apply_method = "pending-reboot" -> null
          - name         = "pg_stat_statements.track" -> null
          - value        = "all" -> null
        }
      - parameter {
          - apply_method = "pending-reboot" -> null
          - name         = "rds.force_ssl" -> null
          - value        = "1" -> null
        }
      - parameter {
          - apply_method = "pending-reboot" -> null
          - name         = "rds.log_retention_period" -> null
          - value        = "1440" -> null
        }
        parameter {
            apply_method = "pending-reboot"
            name         = "track_activity_query_size"
            value        = "2048"
        }
      - parameter {
          - apply_method = "pending-reboot" -> null
          - name         = "work_mem" -> null
          - value        = "8192" -> null
        }
    }

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

Steps to Reproduce

  1. Change an parameter value
  2. Run terraform plan
  3. See the diff

OR

  1. Run plan with no changes, and its clean

Important Factoids

This parameter group is imported into this module. A terraform state rm and a new import did not render any different result.

The most confusing piece to me is where pending-reboot is coming from for all the dynamic/immediate parameter apply_methods?

References

  • #0000
@ghost ghost added the service/rds Issues and PRs that pertain to the rds service. label Mar 10, 2021
@github-actions github-actions bot added the needs-triage Waiting for first response or review from a maintainer. label Mar 10, 2021
@johnmarcou
Copy link

johnmarcou commented May 24, 2021

Having the same issue here.
Here my understanding after investigation.

During the state refresh, terraform will do some kind of aws rds describe-db-parameters --db-parameter-group-name NAME. That is returning the current parameters, such as:

        {
            "ParameterName": "pg_stat_statements.track",
            "ParameterValue": "all",
            "Description": "Selects which statements are tracked by pg_stat_statements.",
            "Source": "user",
            "ApplyType": "dynamic",
            "DataType": "string",
            "AllowedValues": "NONE,TOP,ALL",
            "IsModifiable": true,
            "ApplyMethod": "pending-reboot"
        },

Here, we can see the ApplyMethod used at the PREVIOUS change of the parameter.

In the terraform code, if only the apply_method is updated but not the parameter value:

  • terraform detect it as a change (diffing delete/create)
  • AWS API receive the call to update the parameter
  • the desired value is identical to the current value, so API decide to NOT update/reboot/change the parameter with the new ApplyMethod.

At the next run, terraform still detect the change.
Note that change is detected only if 1 of the parameter in the group has a changed value, which is really confusing.

Workaround: change the value of the drifted parameter to reset the ApplyMethod, then revert back to initial value.
Or, just not update the apply_methode until a value update is necessary.

@github-actions github-actions bot added this to the v3.55.0 milestone Aug 18, 2021
@YakDriver YakDriver self-assigned this Aug 19, 2021
@YakDriver YakDriver removed the needs-triage Waiting for first response or review from a maintainer. label 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.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants