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

Terraform plan and apply fails when resource exists in state, but not in Coralogix backend #317

Open
Ross10x opened this issue Feb 3, 2025 · 2 comments

Comments

@Ross10x
Copy link

Ross10x commented Feb 3, 2025

When a dashboard folder resource managed by Terraform is deleted from Coralogix using the Coralogix UI, the Terraform plan / apply can no longer be run without erroring.

Affected Resource(s)

coralogix_dashboards_folder

Terraform Configuration Files

resource "coralogix_dashboards_folder" "platform" {
name = "Platform"
}

Terraform Version

v1.9.8

Provider Version

v2.0.4
Note: I'm aware that v2.0.6 is newest version as of raising this issue, however, we are pinned to 2.0.4 due to other issues, and nothing in the changelog indicates using v2.0.6 will resolve this issue

Debug Output

Planning failed. Terraform encountered an error while generating this plan.

│ Error: Dashboard folder "b79bce15-7b5c-4a39-92bd-c2edbebad100" is in state, but no longer exists in Coralogix backend
│ with coralogix_dashboards_folder.platform,
│ on ./dashboard_folders.tf line 24, in resource "coralogix_dashboards_folder" "platform":
│ 24: resource "coralogix_dashboards_folder" "platform" {

│ b79bce15-7b5c-4a39-92bd-c2edbebad100 will be recreated when you apply

Expected Behavior

On a read with no backend resource found, the provider should remove the resource from the state, not fail the build.
https://discuss.hashicorp.com/t/how-should-read-signal-that-a-resource-has-vanished-from-the-api-server/40833

This is an issue, as Terraform apply runs an implicit plan before any actions are taken, and this error makes it so it is not possible to run an apply and fix the state issue.

Actual Behavior

Instead of handling the error, the plan/apply is failed

Steps to Reproduce

  1. create a dashboard folder resource using Terraform provider
  2. delete dashboard folder resource from Coralogix using Coralogix ui
  3. run Terraform plan or apply using state from step 1

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment
@celaus
Copy link
Collaborator

celaus commented Feb 3, 2025

Hi - thanks for bringing this up, we'll take a look

@sergio10x
Copy link

This behaviour is also impacting the "terraform destroy" action. When a resource is not found by the API, the delete action errors instead of removing it from state.

Affected Resource(s)

coralogix_dashboards_folder, coralogix_dashboard, coralogix_alert

Terraform Configuration Files

resource "coralogix_dashboards_folder" "test" {
  name = "Test-Folder"
}

Terraform Version

v1.9.8

Provider Version

v2.0.5

Debug Output

coralogix_dashboards_folder.test: Refreshing state... [id=380d8c30-53bc-4ac7-8618-da7b5abab98d]
2025-02-05T10:18:48.821Z [DEBUG] provider.terraform-provider-coralogix_2.0.5: 2025/02/05 10:18:48 [ERROR] Could not find created folder with id: 380d8c30-53bc-4ac7-8618-da7b5abab98d
2025-02-05T10:18:48.821Z [ERROR] provider.terraform-provider-coralogix_2.0.5: Response contains error diagnostic: diagnostic_detail="380d8c30-53bc-4ac7-8618-da7b5abab98d will be recreated when you apply" tf_proto_version=6.7 tf_rpc=ReadResource @module=sdk.proto diagnostic_severity=ERROR diagnostic_summary="Dashboard folder \"380d8c30-53bc-4ac7-8618-da7b5abab98d\" is in state, but no longer exists in Coralogix backend" tf_provider_addr=registry.terraform.io/coralogix/coralogix tf_req_id=2f7b0a5d-bc18-2e3e-b129-4e1b95f7df41 tf_resource_type=coralogix_dashboards_folder @caller=github.com/hashicorp/[email protected]/tfprotov6/internal/diag/diagnostics.go:58 timestamp=2025-02-05T10:18:48.821Z
2025-02-05T10:18:48.821Z [ERROR] vertex "coralogix_dashboards_folder.test" error: Dashboard folder "380d8c30-53bc-4ac7-8618-da7b5abab98d" is in state, but no longer exists in Coralogix backend
2025-02-05T10:18:48.822Z [ERROR] vertex "coralogix_dashboards_folder.test (expand)" error: Dashboard folder "380d8c30-53bc-4ac7-8618-da7b5abab98d" is in state, but no longer exists in Coralogix backend
2025-02-05T10:18:48.822Z [WARN]  Planning encountered errors, so plan is not applyable
╷
│ Error: Dashboard folder "380d8c30-53bc-4ac7-8618-da7b5abab98d" is in state, but no longer exists in Coralogix backend
│ 
│   with coralogix_dashboards_folder.test,
│   on main.tf line 38, in resource "coralogix_dashboards_folder" "test":
│   38: resource "coralogix_dashboards_folder" "test" {
│ 
│ 380d8c30-53bc-4ac7-8618-da7b5abab98d will be recreated when you apply
╵

Expected Behavior

On a delete action, the provider should ignore “resource not found” errors since the operation was intended. It should then remove the resource from the statefile.

https://discuss.hashicorp.com/t/how-should-read-signal-that-a-resource-has-vanished-from-the-api-server/40833

Actual Behavior

Terraform destroy fails during the implicit plan due the resource not found.

Steps to Reproduce

  1. Create a dashboard folder resource using Terraform provider
  2. Delete dashboard folder resource from Coralogix using Coralogix ui
  3. Run Terraform destroy using state from step 1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants