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.74k stars 9.09k forks source link

[Bug]: aws_db_snapshot_copy unexpected state 'pending', wanted target 'available' #29399

Open uriinf opened 1 year ago

uriinf commented 1 year ago

Terraform Core Version

1.2.4

AWS Provider Version

4.54.0

Affected Resource(s)

Expected Behavior

DB snapshot copied from one region to another

Actual Behavior

Occasionally aws_db_snapshot_copy fails with the error unexpected state 'pending', wanted target 'available'. Usually it solved with next run.

Relevant Error/Panic Output Snippet

aws_db_snapshot_copy.this[0]: Creating...
...
aws_db_snapshot_copy.this[0]: Still creating... [30s elapsed]
╷
│ Error: unexpected state 'pending', wanted target 'available'. last error: %!s(<nil>)
│
│   with aws_db_snapshot_copy.this[0],
│   on rds.tf line 7, in resource "aws_db_snapshot_copy" "this":
│    7: resource "aws_db_snapshot_copy" "this" {
│
╵

Terraform Configuration Files

resource "aws_db_snapshot_copy" "this" {
  count = 1

  destination_region            = "<region where the snapshot is>"
  source_db_snapshot_identifier = "<snapshot ARN>"
  target_db_snapshot_identifier = "<name to give to the copied snapshot"

  lifecycle {
    ignore_changes = [source_db_snapshot_identifier]
  }
}

data "aws_db_instance" "this" {
  count    = 1
  provider = aws.ir

  db_instance_identifier = var.rds_this_db_instance_identifier
}

data "aws_db_snapshot" "this" {
  count    = 1
  provider = aws.ir

  db_instance_identifier = data.aws_db_instance.this[0].id
  most_recent            = true
}

resource "aws_db_instance" "this" {
  count = 1

  snapshot_identifier    = aws_db_snapshot_copy.this[0].target_db_snapshot_identifier
...

Steps to Reproduce

terraform apply

Debug Output

No response

Panic Output

No response

Important Factoids

No response

References

No response

Would you like to implement a fix?

None

github-actions[bot] commented 1 year ago

Community Note

Voting for Prioritization

Volunteering to Work on This Issue

al-nwokedike-imprivata commented 1 year ago

Hello, was there a resolution to this? I am experiencing a similar issue trying to create automated backup replications @justinretzolk

justinretzolk commented 1 year ago

Hey @al-nwokedike-imprivata 👋 Thank you for checking in on this! Unfortunately I can't provide an ETA on when this will be looked into due to the potential of shifting priorities. We prioritize by count of :+1: reactions and a few other things (more information on our prioritization guide if you're interested).

daroga0002 commented 1 year ago

@uriinf I think your issue is related to default timeout which is 20 minutes. Please check as maybe you need just increate timeout config on resoource https://registry.terraform.io/providers/figma/aws-4-49-0/latest/docs/resources/db_snapshot_copy#timeouts

nronnei commented 1 year ago

Also running into this issue and don't believe it's a timeout issue. We're seeing the copy complete (via AWS Console) in ~5 minutes but getting this error.

antigenius0910 commented 11 months ago

Agree this is not a time out issue. below are our code with timeout for 12 hrs

### encrypt snapshot using a new dr1 KMS key and push to dr1 region
resource "aws_db_snapshot_copy" "db_snapshot_copy" {
  for_each = toset(data.aws_db_instances.db_instances.instance_identifiers)
  depends_on = [
    aws_db_snapshot.db_snapshot,
    aws_kms_replica_key.kms_replica_key,
  ]

  timeouts {
    create = "720m"
  }

  provider = aws.dr1-replica

  destination_region                          = var.dr1_region
  kms_key_id                                      = aws_kms_replica_key.kms_replica_key.arn
  source_db_snapshot_identifier     = aws_db_snapshot.db_snapshot[each.value].db_snapshot_arn
  target_db_snapshot_identifier      = "${each.value}-${formatdate("DD-MMM-YYYY", timestamp())}-dr1"

  # lifecycle {
  #   ignore_changes = [
  #     source_db_snapshot_identifier,
  #     target_db_snapshot_identifier,
  #   ]
  # }
}

result

│ Error: waiting for RDS DB Snapshot Copy (xxxxxxx-06-oct-2023-dr1) create: unexpected state 'pending', wanted target 'available'. last error: %!s(<nil>)