Skip to content

Conversation

@tobio
Copy link
Member

@tobio tobio commented Dec 3, 2025

Fixes #836

Introduces some new type helpers for the case where we want to treat an empty string as null.

To reproduce the original bug:

  1. Create a fleet output via Terraform, this resource is enough:
resource "elasticstack_fleet_output" "elasticsearch_output" {
  name                 = "elasticsearch-output"
  type                 = "elasticsearch"
  config_yaml          = yamlencode({})
  default_integrations = true
  default_monitoring   = true
  hosts = [
    "https://tb-es-http.elastic-system.svc:9200",
    "https://elasticsearch.acme.test.com:443" # added
  ]
}
  1. In the Fleet settings UI, update the name of the output and save it
  2. terraform apply

The current provider version will error, this PR will not. It's hard to create an acceptance test around this behaviour since it requires editing the output via the UI (I suppose I could have a test that modified the output directly via the API).

@tobio tobio requested review from dimuon and nick-benoit December 3, 2025 06:30
@tobio tobio self-assigned this Dec 3, 2025
Copilot AI review requested due to automatic review settings December 3, 2025 06:30
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 bug where empty string fields in API responses were not being properly handled, causing Terraform apply operations to fail after manual UI updates. The fix introduces new type utility functions to treat empty strings as null values, ensuring consistent state management between Terraform and the API.

Key changes:

  • New utility functions NonEmptyStringValue and NonEmptyStringPointerValue to convert empty strings to null
  • Updated SSL configuration handling to return null objects when all fields are empty
  • Added validators to ensure required SSL fields are non-empty

Reviewed changes

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

Show a summary per file
File Description
internal/utils/typeutils/string.go Added utility functions to convert empty strings to null values
internal/fleet/output/schema.go Added validators to ensure SSL certificate fields are non-empty
internal/fleet/output/models_ssl_test.go Added test cases for empty SSL field handling
internal/fleet/output/models_ssl.go Updated SSL model conversion to use new utilities and handle empty fields
internal/fleet/output/models_logstash.go Applied empty string handling to CaTrustedFingerprint field
internal/fleet/output/models_kafka.go Applied empty string handling to CaTrustedFingerprint field
internal/fleet/output/models_elasticsearch.go Applied empty string handling to CaTrustedFingerprint field
internal/elasticsearch/ml/anomaly_detection_job/models_tf.go Replaced verbose empty string checks with new utility functions throughout ML model conversions
internal/elasticsearch/index/alias/models.go Applied empty string handling to routing fields

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

Successfully merging this pull request may close these issues.

[Bug] elasticstack_fleet_output produces inconsistent result after 0.11.8 upgrade

2 participants