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]: RDS instance shouldn't leak on error during create #38251

Closed mergenci closed 12 hours ago

mergenci commented 5 days ago

Terraform Core Version

1.9.0

AWS Provider Version

5.56.1

Affected Resource(s)

aws_db_instance

Expected Behavior

In case of an error while waiting for an RDS instance to become available during creation, the resource shouldn't leak, i.e., it should be known by Terraform.

Actual Behavior

While creating an RDS instance, I terminated Terraform CLI to simulate an error. In fact, terminating Terraform CLI shouldn't leak resource either. Here's the relevant output:

aws_db_instance.test-leak-on-error: Creating...
aws_db_instance.test-leak-on-error: Still creating... [10s elapsed]
aws_db_instance.test-leak-on-error: Still creating... [20s elapsed]
^C
Interrupt received.
Please wait for Terraform to exit or data loss may occur.
Gracefully shutting down...

Stopping operation...
╷
│ Error: execution halted
│ 
│ 
╵
╷
│ Error: execution halted
│ 
│ 
╵
╷
│ Error: waiting for RDS DB Instance (terraform-20240701105728974200000001) create: context canceled
│ 
│   with aws_db_instance.test-leak-on-error,
│   on main.tf line 15, in resource "aws_db_instance" "test-leak-on-error":
│   15: resource "aws_db_instance" "test-leak-on-error" {
│ 
╵

I could see the resource terraform-20240701105728974200000001 on AWS Console. When I ran terraform apply again, terraform planned to create a new resource and had no idea that the resource had already been created. When I confirmed the apply, it created a new resource, leaving the previously created one intact.

Relevant Error/Panic Output Snippet

No response

Terraform Configuration Files

terraform {
  required_version = "= 1.9.0"
  required_providers {
    aws = {
      source  = "hashicorp/aws"
      version = "= 5.56.1"
    }
  }
}

provider "aws" {
  region = "us-west-2"
}

resource "aws_db_instance" "test-leak-on-error" {
  allocated_storage    = 10
  engine               = "mysql"
  engine_version       = "8.0"
  instance_class       = "db.t4g.micro"
  username             = "system"
  password             = "foobarbaz"
  skip_final_snapshot  = true
}

Steps to Reproduce

See “Actual Behavior” above.

Debug Output

No response

Panic Output

No response

Important Factoids

No response

References

No response

Would you like to implement a fix?

Yes

github-actions[bot] commented 5 days ago

Community Note

Voting for Prioritization

Volunteering to Work on This Issue

github-actions[bot] commented 12 hours ago

[!WARNING] This issue has been closed, meaning that any additional comments are hard for our team to see. Please assume that the maintainers will not see them.

Ongoing conversations amongst community members are welcome, however, the issue will be locked after 30 days. Moving conversations to another venue, such as the AWS Provider forum, is recommended. If you have additional concerns, please open a new issue, referencing this one where needed.