Skip to content

Apply the sys_monitoring attribute during creation #792

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

Merged
merged 2 commits into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
## [Unreleased]

- Fix handling of `sys_monitoring` in `elasticstack_fleet_agent_policy` ([#792](https://github.com/elastic/terraform-provider-elasticstack/pull/792))

## [0.11.7] - 2024-09-20

- Add the `alerts_filter` field to the `actions` in the Create Rule API ([#774](https://github.com/elastic/terraform-provider-elasticstack/pull/774))
Expand Down
12 changes: 10 additions & 2 deletions internal/clients/fleet/fleet.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,16 @@ func ReadAgentPolicy(ctx context.Context, client *Client, id string) (*fleetapi.
}

// CreateAgentPolicy creates a new agent policy.
func CreateAgentPolicy(ctx context.Context, client *Client, req fleetapi.AgentPolicyCreateRequest) (*fleetapi.AgentPolicy, diag.Diagnostics) {
resp, err := client.API.CreateAgentPolicyWithResponse(ctx, req)
func CreateAgentPolicy(ctx context.Context, client *Client, req fleetapi.AgentPolicyCreateRequest, sysMonitoring bool) (*fleetapi.AgentPolicy, diag.Diagnostics) {
resp, err := client.API.CreateAgentPolicyWithResponse(ctx, req, func(ctx context.Context, req *http.Request) error {
if sysMonitoring {
qs := req.URL.Query()
qs.Add("sys_monitoring", "true")
req.URL.RawQuery = qs.Encode()
}

return nil
})
if err != nil {
return nil, diag.FromErr(err)
}
Expand Down
4 changes: 3 additions & 1 deletion internal/fleet/agent_policy_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ func ResourceAgentPolicy() *schema.Resource {
Description: "Enable collection of system logs and metrics.",
Type: schema.TypeBool,
Optional: true,
ForceNew: true,
},
"monitor_logs": {
Description: "Enable collection of agent logs.",
Expand Down Expand Up @@ -140,7 +141,8 @@ func resourceAgentPolicyCreate(ctx context.Context, d *schema.ResourceData, meta
}
req.MonitoringEnabled = &monitoringValues

policy, diags := fleet.CreateAgentPolicy(ctx, fleetClient, req)
sysMonitoring := d.Get("sys_monitoring").(bool)
policy, diags := fleet.CreateAgentPolicy(ctx, fleetClient, req, sysMonitoring)
if diags.HasError() {
return diags
}
Expand Down
Loading