Skip to content

Commit 845721a

Browse files
authored
standalone-output resource (#811)
* standalone output resource * remove sdk getFleetClient helper * remove unused fn * convert fleet fwdiag to diag
1 parent 49e3c95 commit 845721a

File tree

16 files changed

+814
-669
lines changed

16 files changed

+814
-669
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
- Migrate `elasticstack_fleet_agent_policy`, `elasticstack_fleet_integration` (both), and `elasticstack_fleet_server_host` to terraform-plugin-framework ([#785](https://github.com/elastic/terraform-provider-elasticstack/pull/785))
55
- Fix for synthetics http/tcp monitor produces inconsistent result after apply ([#801](https://github.com/elastic/terraform-provider-elasticstack/pull/801))
66
- Migrate `elasticstack_fleet_integration_policy` to terraform-plugin-framework. Fix drift in integration policy secrets. ([#797](https://github.com/elastic/terraform-provider-elasticstack/pull/797))
7+
- Migrate `elasticstack_fleet_output` to terraform-plugin-framework. ([#811](https://github.com/elastic/terraform-provider-elasticstack/pull/811))
78

89
## [0.11.7] - 2024-09-20
910

docs/resources/fleet_output.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ resource "elasticstack_fleet_output" "test_output" {
4848
- `default_monitoring` (Boolean) Make this output the default for agent monitoring.
4949
- `hosts` (List of String) A list of hosts.
5050
- `output_id` (String) Unique identifier of the output.
51-
- `ssl` (Block List, Max: 1) SSL configuration. (see [below for nested schema](#nestedblock--ssl))
51+
- `ssl` (Block List) SSL configuration. (see [below for nested schema](#nestedblock--ssl))
5252

5353
### Read-Only
5454

internal/clients/fleet/fleet.go

Lines changed: 45 additions & 56 deletions
Large diffs are not rendered by default.

internal/fleet/output/create.go

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package output
2+
3+
import (
4+
"context"
5+
6+
"github.com/elastic/terraform-provider-elasticstack/internal/clients/fleet"
7+
"github.com/hashicorp/terraform-plugin-framework/resource"
8+
)
9+
10+
func (r *outputResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) {
11+
var planModel outputModel
12+
13+
diags := req.Plan.Get(ctx, &planModel)
14+
resp.Diagnostics.Append(diags...)
15+
if resp.Diagnostics.HasError() {
16+
return
17+
}
18+
19+
client, err := r.client.GetFleetClient()
20+
if err != nil {
21+
resp.Diagnostics.AddError(err.Error(), "")
22+
return
23+
}
24+
25+
body, diags := planModel.toAPICreateModel(ctx)
26+
resp.Diagnostics.Append(diags...)
27+
if resp.Diagnostics.HasError() {
28+
return
29+
}
30+
31+
output, diags := fleet.CreateOutput(ctx, client, body)
32+
resp.Diagnostics.Append(diags...)
33+
if resp.Diagnostics.HasError() {
34+
return
35+
}
36+
37+
diags = planModel.populateFromAPICreate(ctx, output)
38+
resp.Diagnostics.Append(diags...)
39+
if resp.Diagnostics.HasError() {
40+
return
41+
}
42+
43+
diags = resp.State.Set(ctx, planModel)
44+
resp.Diagnostics.Append(diags...)
45+
}

internal/fleet/output/delete.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package output
2+
3+
import (
4+
"context"
5+
6+
"github.com/elastic/terraform-provider-elasticstack/internal/clients/fleet"
7+
"github.com/hashicorp/terraform-plugin-framework/resource"
8+
)
9+
10+
func (r *outputResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) {
11+
var stateModel outputModel
12+
13+
diags := req.State.Get(ctx, &stateModel)
14+
resp.Diagnostics.Append(diags...)
15+
if resp.Diagnostics.HasError() {
16+
return
17+
}
18+
19+
client, err := r.client.GetFleetClient()
20+
if err != nil {
21+
resp.Diagnostics.AddError(err.Error(), "")
22+
return
23+
}
24+
25+
outputID := stateModel.OutputID.ValueString()
26+
diags = fleet.DeleteOutput(ctx, client, outputID)
27+
resp.Diagnostics.Append(diags...)
28+
}

0 commit comments

Comments
 (0)