Skip to content

[Bug] Updating Existing Fleet Policy to Remove Agent Logging Fails #432

@renzedj

Description

@renzedj

Describe the bug

Agent logging does not update from elastic_fleet_agent_policy if both monitor_logs: false and monitor_metrics: false are set.

To Reproduce

Steps to reproduce the behavior:

  1. Define the following agent policy:
resource "elasticstack_fleet_agent_policy" "my_fleet_agent_policy" {
  name            = "my_fleet_agent_policy"
  namespace       = "default"
  sys_monitoring  = true
  monitor_logs    = true
  monitor_metrics = false
}
  1. Apply the configuration.
  2. Review new fleet policy to validate that Collect agent logs is checked under settings.
  3. Set monitor_logs = false in the agent policy.
  4. Apply the updated configuration.
  5. Review updated fleet policy to validate that Collect agent logs is still checked under settings; terraform.tfstate also shows monitor_logs: true.

Expected behavior

Collect agent logs should not be set.

Note: If monitor_logs: false and monitor_metrics: true are both set, then the results are as expected.

Debug output

PUT /api/fleet/agent_policies/<policy-id> HTTP/1.1
Host: <redacted>
User-Agent: Go-http-client/1.1
Content-Length: 158
Authorization: ***************************************************
Content-Type: application/json
Kbn-Xsrf: true
Accept-Encoding: gzip

{
 "data_output_id": null,
 "download_source_id": null,
 "fleet_server_host_id": null,
 "monitoring_output_id": null,
 "name": "my_fleet_agent_policy",
 "namespace": "default"
}

Versions (please complete the following information)

  • OS: macos
  • Terraform Version: 1.5.7
  • Provider version: 0.7.0, 0.8.0
  • Elastic Cloud Version: 8.10.2

Additional context

This can be reproduced with the API from Dev Tools in Kibana. To do so, follow steps 1-3 under "steps to reproduce," then apply the following update to the policy from Dev Tools to get the same results:

PUT kbn:/api/fleet/agent_policies/<policy-id>
{
 "data_output_id": null,
 "description": "Test Agent Policy",
 "download_source_id": null,
 "fleet_server_host_id": null,
 "monitoring_output_id": null,
 "name": "test-policy-1",
 "namespace": "default"
}

To get the expected results, it is necessary to provide an empty array for monitoring_enabled, such as:

PUT kbn:/api/fleet/agent_policies/<policy-id>
{
 "data_output_id": null,
 "description": "Test Agent Policy",
 "download_source_id": null,
 "fleet_server_host_id": null,
 "monitoring_output_id": null,
 "monitoring_enabled": [],
 "name": "test-policy-1",
 "namespace": "default"
}

Explicitly setting monitoring_enabled: null generates the following error:

{
  "statusCode": 400,
  "error": "Bad Request",
  "message": "[request body.monitoring_enabled]: expected value of type [array] but got [null]"
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions