Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

provider/aws: Catch 400 error from rds_cluster #11795

Merged
merged 1 commit into from
Feb 8, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions builtin/providers/aws/resource_aws_rds_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -611,6 +611,13 @@ func resourceAwsRDSClusterDelete(d *schema.ResourceData, meta interface{}) error

log.Printf("[DEBUG] RDS Cluster delete options: %s", deleteOpts)
_, err := conn.DeleteDBCluster(&deleteOpts)
if err != nil {
if awsErr, ok := err.(awserr.Error); ok {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am presuming we can't put a cluster into a state to test this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test case is as follows:

# main.tf
variable "mysql_username" { default = "dummy_user" }
variable "mysql_password" { default = "password12345" }

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


resource "aws_rds_cluster" "cluster" {
  cluster_identifier     = "cluster-test-cluster"
  availability_zones     = ["us-west-2a","us-west-2b"]
  database_name          = "test-db"
  master_username        = "${var.mysql_username}"
  master_password        = "${var.mysql_password}"
  apply_immediately      = true
}

resource "aws_rds_cluster_instance" "group_0" {
  identifier           = "group-0-testing"
  cluster_identifier   = "${aws_rds_cluster.cluster.id}"
  instance_class       = "db.t2.medium"
  publicly_accessible  = true

  tags {
    Name = "group-0-testing"
  }
}

resource "aws_rds_cluster_instance" "group_1" {
  identifier           = "group-1-testing"
  cluster_identifier   = "${aws_rds_cluster.cluster.id}"
  instance_class       = "db.t2.medium"
  publicly_accessible  = true

  tags {
    Name = "group-1-testing"
  }
}

Followed by:

terraform apply
mkdir import; cd import
terraform import aws_rds_cluster.cluster cluster-test-cluster
terraform destroy
# observe error from dangling rds_cluster without instance groups being destroyed

if "InvalidDBClusterStateFault" == awsErr.Code() {
return fmt.Errorf("RDS Cluster cannot be deleted: %s", awsErr.Message())
}
}
}

stateConf := &resource.StateChangeConf{
Pending: []string{"available", "deleting", "backing-up", "modifying"},
Expand Down