Skip to content

Commit 76bc05a

Browse files
Add Fleet output and server host (#327)
- Add Fleet output resource - Add Fleet server host resource - Set Fleet OpenAPI schema version to v8.7.1
1 parent 60113b1 commit 76bc05a

File tree

19 files changed

+2229
-188
lines changed

19 files changed

+2229
-188
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
- Add `elasticstack_kibana_alerting_rule` for managing Kibana alerting rules ([#292](https://github.com./elastic/terraform-provider-elasticstack/pull/292))
2626
- Add client for communicating with the Fleet APIs ([#311](https://github.com./elastic/terraform-provider-elasticstack/pull/311)])
2727
- Add `elasticstack_fleet_enrollment_tokens` and `elasticstack_fleet_agent_policy` for managing Fleet enrollment tokens and agent policies ([#322](https://github.com./elastic/terraform-provider-elasticstack/pull/322)])
28+
- Add `elasticstack_fleet_output` and `elasticstack_fleet_server_host` for managing Fleet outputs and server hosts ([#327](https://github.com./elastic/terraform-provider-elasticstack/pull/327)])
2829

2930
### Fixed
3031
- Updated unsupported queue_max_bytes_number and queue_max_bytes_units with queue.max_bytes ([#266](https://github.com./elastic/terraform-provider-elasticstack/issues/266))

docs/resources/fleet_output.md

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
---
2+
subcategory: "Fleet"
3+
layout: ""
4+
page_title: "Elasticstack: elasticstack_fleet_output Resource"
5+
description: |-
6+
Creates or updates a Fleet Output.
7+
---
8+
9+
# Resource: elasticstack_fleet_output
10+
11+
Creates or updates a Fleet Output.
12+
13+
## Example Usage
14+
15+
```terraform
16+
provider "elasticstack" {
17+
kibana {}
18+
}
19+
20+
resource "elasticstack_fleet_output" "test_output" {
21+
name = "Test Output"
22+
type = "elasticsearch"
23+
config_yaml = yamlencode({
24+
"ssl.verification_mode" : "none"
25+
})
26+
default_integrations = false
27+
default_monitoring = false
28+
hosts = [
29+
"https://elasticsearch:9200"
30+
]
31+
}
32+
```
33+
34+
<!-- schema generated by tfplugindocs -->
35+
## Schema
36+
37+
### Required
38+
39+
- `name` (String) The name of the output.
40+
- `type` (String) The output type.
41+
42+
### Optional
43+
44+
- `ca_sha256` (String) Fingerprint of the Elasticsearch CA certificate.
45+
- `config_yaml` (String, Sensitive) Advanced YAML configuration. YAML settings here will be added to the output section of each agent policy.
46+
- `default_integrations` (Boolean) Make this output the default for agent integrations.
47+
- `default_monitoring` (Boolean) Make this output the default for agent monitoring.
48+
- `hosts` (List of String) A list of hosts.
49+
- `output_id` (String) Unique identifier of the output.
50+
51+
### Read-Only
52+
53+
- `id` (String) The ID of this resource.
54+
55+
## Import
56+
57+
Import is supported using the following syntax:
58+
59+
```shell
60+
terraform import elasticstack_fleet_output.my_output <space id>/<output id>
61+
```

docs/resources/fleet_server_host.md

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
---
2+
subcategory: "Fleet"
3+
layout: ""
4+
page_title: "Elasticstack: elasticstack_fleet_server_host Resource"
5+
description: |-
6+
Creates or updates a Fleet Server Host.
7+
---
8+
9+
# Resource: elasticstack_fleet_server_host
10+
11+
Creates or updates a Fleet Server Host.
12+
13+
## Example Usage
14+
15+
```terraform
16+
provider "elasticstack" {
17+
kibana {}
18+
}
19+
20+
resource "elasticstack_fleet_server_host" "test_host" {
21+
name = "Test Host"
22+
default = false
23+
hosts = [
24+
"https://fleet-server:8220"
25+
]
26+
}
27+
```
28+
29+
<!-- schema generated by tfplugindocs -->
30+
## Schema
31+
32+
### Required
33+
34+
- `hosts` (List of String) A list of hosts.
35+
- `name` (String) The name of the Fleet server host.
36+
37+
### Optional
38+
39+
- `default` (Boolean) Set as default.
40+
- `host_id` (String) Unique identifier of the Fleet server host.
41+
42+
### Read-Only
43+
44+
- `id` (String) The ID of this resource.
45+
46+
## Import
47+
48+
Import is supported using the following syntax:
49+
50+
```shell
51+
terraform import elasticstack_fleet_server_host.my_host <space id>/<host id>
52+
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
terraform import elasticstack_fleet_output.my_output <space id>/<output id>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
provider "elasticstack" {
2+
kibana {}
3+
}
4+
5+
resource "elasticstack_fleet_output" "test_output" {
6+
name = "Test Output"
7+
type = "elasticsearch"
8+
config_yaml = yamlencode({
9+
"ssl.verification_mode" : "none"
10+
})
11+
default_integrations = false
12+
default_monitoring = false
13+
hosts = [
14+
"https://elasticsearch:9200"
15+
]
16+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
terraform import elasticstack_fleet_server_host.my_host <space id>/<host id>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
provider "elasticstack" {
2+
kibana {}
3+
}
4+
5+
resource "elasticstack_fleet_server_host" "test_host" {
6+
name = "Test Host"
7+
default = false
8+
hosts = [
9+
"https://fleet-server:8220"
10+
]
11+
}

internal/clients/fleet/fleet.go

+128
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,134 @@ func DeleteAgentPolicy(ctx context.Context, client *Client, id string) diag.Diag
9090
}
9191
}
9292

93+
// ReadOutput reads a specific output from the API.
94+
func ReadOutput(ctx context.Context, client *Client, id string) (*fleetapi.Output, diag.Diagnostics) {
95+
resp, err := client.API.GetOutputWithResponse(ctx, id)
96+
if err != nil {
97+
return nil, diag.FromErr(err)
98+
}
99+
100+
switch resp.StatusCode() {
101+
case http.StatusOK:
102+
return &resp.JSON200.Item, nil
103+
case http.StatusNotFound:
104+
return nil, nil
105+
default:
106+
return nil, reportUnknownError(resp.StatusCode(), resp.Body)
107+
}
108+
}
109+
110+
// CreateOutput creates a new output.
111+
func CreateOutput(ctx context.Context, client *Client, req fleetapi.PostOutputsJSONRequestBody) (*fleetapi.Output, diag.Diagnostics) {
112+
resp, err := client.API.PostOutputsWithResponse(ctx, req)
113+
if err != nil {
114+
return nil, diag.FromErr(err)
115+
}
116+
117+
switch resp.StatusCode() {
118+
case http.StatusOK:
119+
return resp.JSON200.Item, nil
120+
default:
121+
return nil, reportUnknownError(resp.StatusCode(), resp.Body)
122+
}
123+
}
124+
125+
// UpdateOutput updates an existing output.
126+
func UpdateOutput(ctx context.Context, client *Client, id string, req fleetapi.UpdateOutputJSONRequestBody) (*fleetapi.Output, diag.Diagnostics) {
127+
resp, err := client.API.UpdateOutputWithResponse(ctx, id, req)
128+
if err != nil {
129+
return nil, diag.FromErr(err)
130+
}
131+
132+
switch resp.StatusCode() {
133+
case http.StatusOK:
134+
return &resp.JSON200.Item, nil
135+
default:
136+
return nil, reportUnknownError(resp.StatusCode(), resp.Body)
137+
}
138+
}
139+
140+
// DeleteOutput deletes an existing output
141+
func DeleteOutput(ctx context.Context, client *Client, id string) diag.Diagnostics {
142+
resp, err := client.API.DeleteOutputWithResponse(ctx, id)
143+
if err != nil {
144+
return diag.FromErr(err)
145+
}
146+
147+
switch resp.StatusCode() {
148+
case http.StatusOK:
149+
return nil
150+
case http.StatusNotFound:
151+
return nil
152+
default:
153+
return reportUnknownError(resp.StatusCode(), resp.Body)
154+
}
155+
}
156+
157+
// ReadFleetServerHost reads a specific fleet server host from the API.
158+
func ReadFleetServerHost(ctx context.Context, client *Client, id string) (*fleetapi.FleetServerHost, diag.Diagnostics) {
159+
resp, err := client.API.GetOneFleetServerHostsWithResponse(ctx, id)
160+
if err != nil {
161+
return nil, diag.FromErr(err)
162+
}
163+
164+
switch resp.StatusCode() {
165+
case http.StatusOK:
166+
return &resp.JSON200.Item, nil
167+
case http.StatusNotFound:
168+
return nil, nil
169+
default:
170+
return nil, reportUnknownError(resp.StatusCode(), resp.Body)
171+
}
172+
}
173+
174+
// CreateFleetServerHost creates a new fleet server host.
175+
func CreateFleetServerHost(ctx context.Context, client *Client, req fleetapi.PostFleetServerHostsJSONRequestBody) (*fleetapi.FleetServerHost, diag.Diagnostics) {
176+
resp, err := client.API.PostFleetServerHostsWithResponse(ctx, req)
177+
if err != nil {
178+
return nil, diag.FromErr(err)
179+
}
180+
181+
switch resp.StatusCode() {
182+
case http.StatusOK:
183+
return resp.JSON200.Item, nil
184+
default:
185+
return nil, reportUnknownError(resp.StatusCode(), resp.Body)
186+
}
187+
}
188+
189+
// UpdateFleetServerHost updates an existing fleet server host.
190+
func UpdateFleetServerHost(ctx context.Context, client *Client, id string, req fleetapi.UpdateFleetServerHostsJSONRequestBody) (*fleetapi.FleetServerHost, diag.Diagnostics) {
191+
resp, err := client.API.UpdateFleetServerHostsWithResponse(ctx, id, req)
192+
if err != nil {
193+
return nil, diag.FromErr(err)
194+
}
195+
196+
switch resp.StatusCode() {
197+
case http.StatusOK:
198+
return &resp.JSON200.Item, nil
199+
default:
200+
return nil, reportUnknownError(resp.StatusCode(), resp.Body)
201+
}
202+
}
203+
204+
// DeleteFleetServerHost deletes an existing fleet server host.
205+
func DeleteFleetServerHost(ctx context.Context, client *Client, id string) diag.Diagnostics {
206+
resp, err := client.API.DeleteFleetServerHostsWithResponse(ctx, id)
207+
if err != nil {
208+
return diag.FromErr(err)
209+
}
210+
211+
switch resp.StatusCode() {
212+
case http.StatusOK:
213+
return nil
214+
case http.StatusNotFound:
215+
return nil
216+
default:
217+
return reportUnknownError(resp.StatusCode(), resp.Body)
218+
}
219+
}
220+
93221
func reportUnknownError(statusCode int, body []byte) diag.Diagnostics {
94222
return diag.Diagnostics{
95223
diag.Diagnostic{

0 commit comments

Comments
 (0)