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.83k stars 9.18k forks source link

[Bug]: r/aws_redshiftserverless_namespace: non-empty plan after creating minimal namespace with workgroup and db_name output #39273

Open marcinbelczewski opened 2 months ago

marcinbelczewski commented 2 months ago

Terraform Core Version

1.9.5

AWS Provider Version

5.66.0

Affected Resource(s)

Expected Behavior

Empty plan after apply

Actual Behavior

Non-empty plan after apply:

❯ terraform plan
aws_redshiftserverless_namespace.test: Refreshing state... [id=test]
aws_redshiftserverless_workgroup.test: Refreshing state... [id=test]

Note: Objects have changed outside of Terraform

Terraform detected the following changes made outside of Terraform since the last "terraform apply" which may have affected this plan:

  # aws_redshiftserverless_namespace.test has changed
  ~ resource "aws_redshiftserverless_namespace" "test" {
      + db_name                          = "dev"
        id                               = "test"
        # (10 unchanged attributes hidden)
    }

Unless you have made equivalent changes to your configuration, or ignored the relevant attributes using ignore_changes, the following plan may include actions to undo or
respond to these changes.

Relevant Error/Panic Output Snippet

No response

Terraform Configuration Files


resource "aws_redshiftserverless_namespace" "test" {
  namespace_name = "test"
}

resource "aws_redshiftserverless_workgroup" "test" {
  namespace_name = aws_redshiftserverless_namespace.test.namespace_name
  workgroup_name = "test"
}

output "db_name" { value = aws_redshiftserverless_namespace.test.db_name}

### Steps to Reproduce

1. Terraform apply the above config
2. Run `terraform plan` and see the non-empty plan

### Debug Output

_No response_

### Panic Output

_No response_

### Important Factoids

The cause of the issue is suboptimal implementation of Redshift APIs. If namespace is created without dbName, then the default "dev" is used however, GetNamespace does not return this value. 
Workgroup creation modifies the namespace in a way that changes the dbName from empty to "dev" creating the drift. It never should happen that creation of one resource mutates another.  It is possible to mitigate the issue in the provider

### References

_No response_

### Would you like to implement a fix?

Yes
github-actions[bot] commented 2 months ago

Community Note

Voting for Prioritization

Volunteering to Work on This Issue