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.61k stars 9k forks source link

[Bug]: Issues setting custom parameter group on cross-region RDS Read Replica with Postgres engine #38056

Open LowzG opened 2 weeks ago

LowzG commented 2 weeks ago

Terraform Core Version

1.8.5

AWS Provider Version

5.51.1

Affected Resource(s)

aws_db_instance

Expected Behavior

Creating an RDS cross-region read replica with Postgres engine and custom parameter group should succeed

Actual Behavior

The following error message is produced Error: creating RDS DB Instance (read replica) (replica-ap-northeast-1): InvalidParameterCombination: A parameter group can't be specified during Read Replica creation for the following DB engine: postgres status code: 400, request id: ffff3ef0-274f-4e7f-ac74-04d06e8c5256

Relevant Error/Panic Output Snippet

No response

Terraform Configuration Files

resource "aws_db_instance" "replica-ap-northeast-1" {
  identifier             = "replica-ap-northeast-1"
  replicate_source_db    = "arn:aws:rds:us-east-2:*"
  instance_class         = "db.m7g.large"
  engine                 = "postgres"
  apply_immediately      = true
  skip_final_snapshot    = true
  vpc_security_group_ids = [local.vpc_id]
  parameter_group_name   = "custom-parameter-group"
}

Steps to Reproduce

terraform apply

Debug Output

No response

Panic Output

No response

Important Factoids

In this PR a change was introduced to set the parameter group of a cross-region read replica at time of creation as opposed to a modification task handled after the instance has been created.

That seems to work well for instances of Oracle engines, but not Postgres. AWS documentation seem to indicate that setting the custom parameter group on a read replica at time of creation can only be done on instances with Oracle or MySQL engines:

For the MySQL and Oracle DB engines, you can specify a custom parameter group for the read replica in the --db-parameter-group-name option of the AWS CLI command create-db-instance-read-replica. You can't specify a custom parameter group when you use the AWS Management Console.

I think the correct approach were may be to continue to set the parameter group at creation for Oracle/MySQL engines, and all others should happen after the instance is created as part of a modify task: https://github.com/hashicorp/terraform-provider-aws/blob/v5.54.1/internal/service/rds/instance.go#L932-L940

References

No response

Would you like to implement a fix?

None

github-actions[bot] commented 2 weeks ago

Community Note

Voting for Prioritization

Volunteering to Work on This Issue

ewbankkit commented 3 days ago

I can reproduce this with a new acceptance test:

% make testacc TESTARGS='-run=TestAccRDSInstance_ReplicateSourceDB_CrossRegion_parameterGroupNamePostgres' PKG=rds
make: Verifying source code with gofmt...
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go1.22.4 test ./internal/service/rds/... -v -count 1 -parallel 20  -run=TestAccRDSInstance_ReplicateSourceDB_CrossRegion_parameterGroupNamePostgres -timeout 360m
=== RUN   TestAccRDSInstance_ReplicateSourceDB_CrossRegion_parameterGroupNamePostgres
=== PAUSE TestAccRDSInstance_ReplicateSourceDB_CrossRegion_parameterGroupNamePostgres
=== CONT  TestAccRDSInstance_ReplicateSourceDB_CrossRegion_parameterGroupNamePostgres
    instance_test.go:2229: Step 1/2 error: Error running apply: exit status 1

        Error: creating RDS DB Instance (read replica) (tf-acc-test-6875571257136664753): InvalidParameterCombination: A parameter group can't be specified during Read Replica creation for the following DB engine: postgres
            status code: 400, request id: 3f8dfe34-170c-4bda-8768-7214fbd737b9

          with aws_db_instance.test,
          on terraform_plugin_test.tf line 32, in resource "aws_db_instance" "test":
          32: resource "aws_db_instance" "test" {

--- FAIL: TestAccRDSInstance_ReplicateSourceDB_CrossRegion_parameterGroupNamePostgres (829.42s)
FAIL
FAIL    github.com/hashicorp/terraform-provider-aws/internal/service/rds    833.974s
FAIL
make: *** [testacc] Error 1