terraform-provider-opensearch
terraform-provider-opensearch copied to clipboard
[BUG] dependency when destroy a component_template and it usage in a composable_index_template
What is the bug?
When trying to delete a component_template
How can one reproduce the bug?
1- define opensearch_component_template.default-settings
2- define opensearch_composable_index_template.sample2-template that reference default-settings
resource "opensearch_composable_index_template" "sample2-template" {
name = "sample2-template"
body = <<EOF
{
"index_patterns": ["logs-sample2-*"],
"priority": 1000,
"data_stream": {"timestamp_field": {"name": "@timestamp"}},
"composed_of": ["default-settings", "default-mappings"]
}
EOF
depends_on = [opensearch_component_template.default-settings]
}
3- run terraform apply and create resources
4- remove the definition of default-settings and its reference from the sample2-template
5- run terraform apply and you will get this error message:
module.component_template.opensearch_component_template.default-settings: Destroying... [id=default-settings] ╷ │ Error: elastic: Error 400 (Bad Request): component templates [default-settings] cannot be removed as they are still in use by index templates [sample2-template] [type=illegal_argument_exception]
What is the expected behavior?
A method to set destroy dependency between the 2 resources in order to update sample2-template before destroying default-settings
Do you have any additional context?
Plan of the step 5:
Terraform will perform the following actions:
# module.component_template.opensearch_component_template.default-settings will be destroyed
# (because opensearch_component_template.default-settings is not in configuration)
- resource "opensearch_component_template" "default-settings" {
- body = jsonencode(
{
- template = {
- settings = {
- index = {
- codec = "best_compression"
- number_of_replicas = "1"
- number_of_shards = "3"
}
}
}
}
) -> null
- id = "default-settings" -> null
- name = "default-settings" -> null
}
# module.data_streams.opensearch_composable_index_template.sample2-template will be updated in-place
~ resource "opensearch_composable_index_template" "sample2-template" {
~ body = jsonencode(
~ {
~ composed_of = [
- "default-settings",
]
}
)
id = "sample2-template"
name = "sample2-template"
}
Please see if the comments from an issue from terraform repository helps
https://github.com/hashicorp/terraform/issues/31769#issuecomment-1243911229
https://github.com/hashicorp/terraform/issues/31769#issuecomment-1243987954