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.8k stars 9.15k forks source link

[Bug]: destroyed Cloudseach domain!. #34435

Open thoeng-nuuday opened 11 months ago

thoeng-nuuday commented 11 months ago

Terraform Core Version

1.5.1

AWS Provider Version

4.67.0

Affected Resource(s)

resource "aws_cloudsearch_domain" "search" {
  name = "search-domain"
  scaling_parameters {
    desired_instance_type = "search.large"
  }
  multi_az = var.environment == "prd" ? true : false
}

Expected Behavior

This is a bit of an edgecase,

We had a stack creating a cloudsearch domain with the name search-domain, and that went well.

Then in another stack with a different statefile a cloudsearch with the same name 'search-domain' was created but failed (because of a wrong index field value)
And when the changes was reveret and applied the terraform removed the cloudsearch domain from aws

Actual Behavior

The second apply on the same resource from another stack should failed, because the cloudsearch domain already existed.

But the terraform plan and apply went through - and when the resource was removed - the first cloudsearch domain was delete, even if it was already created from another stack.

And no import of the resource had been done in stack 2.

Relevant Error/Panic Output Snippet

No response

Terraform Configuration Files

stack one

resource "aws_cloudsearch_domain" "search" {
  name = "search-domain"
  scaling_parameters {
    desired_instance_type = "search.small"
  }
  multi_az = false
}

State two

resource "aws_cloudsearch_domain" "search" {
  name = "search-domain"
  scaling_parameters {
    desired_instance_type = "search.small"
  }
  multi_az = false

  index_field {
    name            = "title"
    type            = "text"
    search          = true
    return          = true
    sort            = true
    highlight       = true
    analysis_scheme = "danish" # <- invalid field makes the cre
  }
}

Steps to Reproduce

Create the same cloudsearch domain from two different stacks in sequence and remove it again from the last one. The cloudsearchdomain is destroyed.

Debug Output

No response

Panic Output

No response

Important Factoids

No response

References

The apply should fail if the cloudsearch domain already exists

Would you like to implement a fix?

None

github-actions[bot] commented 11 months ago

Community Note

Voting for Prioritization

Volunteering to Work on This Issue