Skip to content

Conversation

@tobio
Copy link
Member

@tobio tobio commented Dec 21, 2025

Fixes #1570

@tobio tobio requested a review from dimuon December 21, 2025 22:26
@tobio tobio self-assigned this Dec 21, 2025
Copilot AI review requested due to automatic review settings December 21, 2025 22:26
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a panic that occurred when attempting to import a non-existent ML datafeed resource. The fix adds a nil check in the read operation to gracefully handle cases where the datafeed is not found, preventing the panic and allowing Terraform to properly report that the resource does not exist.

Key Changes:

  • Added nil check in the datafeed read operation to handle non-existent resources
  • Added acceptance test to verify the fix for importing non-existent datafeeds

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
internal/elasticsearch/ml/datafeed/read.go Added nil check after API call to prevent panic when datafeed doesn't exist
internal/elasticsearch/ml/datafeed/acc_test.go Added acceptance test for importing non-existent datafeed
internal/elasticsearch/ml/datafeed/testdata/TestAccResourceDatafeed_ImportNonExistent/import_missing/datafeed.tf Test configuration file for the non-existent import test case

Comment on lines +13 to +15
resource "elasticstack_elasticsearch_ml_datafeed" "test" {
datafeed_id = var.datafeed_id
job_id = var.job_id
Copy link

Copilot AI Dec 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test configuration references a non-existent job via var.job_id set to 'dummy-job'. Since the test is specifically for importing a non-existent datafeed, it should not depend on a non-existent job. Consider creating an actual ML job resource in the test configuration or document why the non-existent job reference is acceptable for this test scenario.

Copilot uses AI. Check for mistakes.
ResourceName: "elasticstack_elasticsearch_ml_datafeed.test",
ImportState: true,
ImportStateId: "cluster-id/non-existent-datafeed-id",
ImportStateVerify: false,
Copy link

Copilot AI Dec 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test disables import state verification with ImportStateVerify: false. For a test validating import behavior of non-existent resources, consider adding ExpectError to verify that Terraform properly reports the resource as not found, rather than silently succeeding with verification disabled.

Copilot uses AI. Check for mistakes.

### Changes

- Add `advanced_settings` to `elasticstack_fleet_agent_policy` to configure agent logging, CPU limits, and download settings ([#1545](https://github.com/elastic/terraform-provider-elasticstack/pull/1545))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for fixing this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Provider crashes when attempting to import non-existent datafeed from anomaly detection job

3 participants