Terraform-provider-aws: Error Destroying Aurora Global Cluster with Primary and Secondary Regional Clusters

Created on 1 May 2020  ·  8Comments  ·  Source: hashicorp/terraform-provider-aws

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 Version

Terraform v0.12.24

Affected Resource(s)

  • aws__rds_global_cluster

Terraform Configuration Files

resource "aws_rds_global_cluster" "global" {
  provider                  = aws.pri
  global_cluster_identifier = "test-cluster"

Expected Behavior

Actual Behavior

Aurora Global Clusters with one regional cluster work fine with changes from #12499. They can be created and destroyed, but a global cluster is created with primary and secondary regional clusters the error from #12499 persists:

* aws_rds_cluster.this: error deleting RDS Cluster (dbtfmodules-aurora-mysql-global-test-secondary): InvalidDBClusterStateFault: This cluster is a part of a global cluster, please remove it from globalcluster first
    status code: 400, request id: fc9e7a36-b486-4f0b-8418-3a81de125289

Steps to Reproduce

After trying and failing the first destroy, a seconddestroy works as expected.

Important Factoids

In the destroy debug.log, the secondary cluster was removed from the global cluster (RemoveFromGlobalCluster request) and then tried to DeleteDBCluster and resulted in error.

The time between this two requests is very short and maybe the unlink is not applied when it performs the DeleteDBCluster request.

Using either like waitForState function to detect the cluster is unlinked or something like thread.Sleep could potentially fix the issue.

References

  • #12499
bug servicrds

All 8 comments

We have this issue with Terraform ENTP v0.12.24 / Provider 2.59. How soon we will get help on this?

We have this issue with Terraform ENTP v0.12.24 / Provider 2.59. How soon we will get help on this?

@pandianp1971 I'm still having issues with as well cc @bflad since he is working on the latest rds changes.

Hello, we also have this issue.

We are also having this issue.

@maryelizbeth

In order to give more context regarding this issue:

1) We are using Terraform Enterprise
2) We cannot provide the code since we have a lot of internal information but here is a very similar configuration we use.

provider "aws" {
 alias  = "sec"
region = "<secondary-region>"
}

resource "aws_rds_global_cluster" "global" {
  global_cluster_identifier = "test-cluster"
  engine                    = "aurora-mysql"
  engine_version            = "5.7.mysql_aurora.2.07.1"
  storage_encrypted         = false
}

resource "aws_rds_cluster" "primary_cluster" {
  availability_zones              = var.primary_availability_zones
  cluster_identifier              = var.cluster_name
  database_name                   = "test"
  engine                    = "aurora-mysql"
  engine_version            = "5.7.mysql_aurora.2.07.1"
  engine_mode     = "provisioned"
  global_cluster_identifier       = aws_rds_global_cluster.global.id
  master_password                 = "test"
  master_username                 = "test"
  skip_final_snapshot             = true
  storage_encrypted               = false
  vpc_security_group_ids          = [var.primary_vpc]
}

resource "aws_rds_cluster_instance" "primary" {
  cluster_identifier           = aws_rds_cluster.primary_cluster.id
  engine                    = "aurora-mysql"
  engine_version            = "5.7.mysql_aurora.2.07.1"
  identifier                   = "${var.db_instance_name}"
  instance_class               = "db.r4.large"
}

resource "aws_rds_cluster" "secondary_cluster" {
  provider                        = aws.sec
  apply_immediately               = var.cluster_apply_change_immediately
  availability_zones              = var.sec_az
  cluster_identifier              = "${var.cluster_name}-sec"
  db_subnet_group_name            = "default-vpc-test"
  depends_on                      = [aws_rds_cluster_instance.primary]
  engine                    = "aurora-mysql"
  engine_mode     = "provisioned"
  engine_version            = "5.7.mysql_aurora.2.07.1"
  global_cluster_identifier       = aws_rds_global_cluster.global.id
  skip_final_snapshot             = true
  storage_encrypted               = false
  vpc_security_group_ids          = [var.test_sec_groups]
}

resource "aws_rds_cluster_instance" "secondary" {
  provider                     = aws.sec
  cluster_identifier           = aws_rds_cluster.secondary_cluster.id
  db_subnet_group_name         = "default-vpc-test123"
  engine                    = "aurora-mysql"
  engine_version            = "5.7.mysql_aurora.2.07.1"
  identifier                   = "test_sec-sec"
  instance_class               = "db.r4.large"
  publicly_accessible          = false
}

Resources impacted:

  • aws_rds_global_cluster
  • aws_rds_cluster

More context:
The Aurora Global Cluster with one regional cluster works fine, we can create it and destroy it, but when we create the global cluster with primary and secondary regional clusters we got the same error:

 aws_rds_cluster.this: error deleting RDS Cluster (dbtfmodules-aurora-mysql-global-test-secondary): InvalidDBClusterStateFault: This cluster is a part of a global cluster, please remove it from globalcluster first status code: 400, request id: fc9e7a36-b486-4f0b-8418-3a81de125289

Then I run a subsequent destroy and works fine, so destroying two times is our workaround right now.

I’ve taken a look into the destroy destroy.log and saw that the secondary cluster was removed from the global cluster (RemoveFromGlobalCluster request) and then tried to DeleteDBCluster and got the error.

The time between these two requests is very short and maybe the unlink is not applied when it performs the DeleteDBCluster request. I’d recommend using either like waitForState function to detect the cluster is unlinked or something like thread.Sleep.
```

A fix has been merged to address the error on delete and will release with v3.1.0 of the Terraform AWS Provider.

This has been released in version 3.1.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 for triage. Thanks!

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 feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. Thanks!

Was this page helpful?
0 / 5 - 0 ratings