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

[BUG] dependency when destroy a component_template and it usage in a composable_index_template #189

Open
imanis opened this issue May 14, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@imanis
Copy link

imanis commented May 14, 2024

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"
    }
@imanis imanis added bug Something isn't working untriaged labels May 14, 2024
@rblcoder
Copy link
Collaborator

Please see if the comments from an issue from terraform repository helps

hashicorp/terraform#31769 (comment)

hashicorp/terraform#31769 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: 📦 Backlog
Development

No branches or pull requests

2 participants