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

[Bug]: aws_msk_cluster fails to destroy/update a cluster if the cluster state is FAILED #37471

Open diego7marques opened 3 months ago

diego7marques commented 3 months ago

Terraform Core Version

1.8.3

AWS Provider Version

5.41.0,5.49.0

Affected Resource(s)

aws_msk_cluster

Expected Behavior

The terraform must be able to destroy a cluster in "FAILED" state.

Actual Behavior

The plan/apply/destroy returns an error and does not proceed with the rest of the code, which makes the terraform unusable until you delete the MSK instance manually in the AWS console.

Relevant Error/Panic Output Snippet

Error: reading MSK Cluster (arn:aws:kafka:<region>:<accountId>:cluster/msk-kafka-cluster/<GUID>) bootstrap brokers: 
operation error Kafka: GetBootstrapBrokers, https response error StatusCode: 400, 
BadRequestException: You can't get bootstrap broker nodes for a cluster in FAILED state.
│ 
│   with aws_msk_cluster.this[0],
│   on main.tf line 5, in resource "aws_msk_cluster" "this":
│    5: resource "aws_msk_cluster" "this" {
│

Terraform Configuration Files

resource "aws_msk_cluster" "this" {
  cluster_name           = "github-issue"
  kafka_version          = "3.5.1"
  number_of_broker_nodes = 2

  broker_node_group_info {
    instance_type = "kafka.t3.small"
    client_subnets = [
      "subnet-12345679",
      "subnet-98765432",
    ]
    storage_info {
      ebs_storage_info {
        volume_size = 100
      }
    }
    security_groups = ["sg-12345679"]
  }

  logging_info {
    broker_logs {
      s3 {
        enabled = true
        bucket  = "issue-github"
        prefix  = "logs/msk-"
      }
    }
  }
}

Steps to Reproduce

1 - Force the MSK cluster to fail on the first run. For example, run the terraform with a s3 bucket that does not exist. If you do this, the state of the cluster will be FAILED with the following error:

Error: waiting for MSK Cluster create: unexpected state 'FAILED', wanted target 'ACTIVE'. last error: InvalidInput.ResourceNotFound: The resource issue-github doesn't exist. Specify an existing destination for broker logs, and then try the operation again.

2 - Correct the name of the s3 bucket with an existing bucket and run terraform apply again and the error will appear. The same happens if you try to run terraform destroy.

Debug Output

No response

Panic Output

No response

Important Factoids

No response

References

No response

Would you like to implement a fix?

No

github-actions[bot] commented 3 months ago

Community Note

Voting for Prioritization

Volunteering to Work on This Issue