Skip to content

standalone-output resource #811

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 4 commits into from
Oct 1, 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
- 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))
- Fix for synthetics http/tcp monitor produces inconsistent result after apply ([#801](https://github.com/elastic/terraform-provider-elasticstack/pull/801))
- 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))
- Migrate `elasticstack_fleet_output` to terraform-plugin-framework. ([#811](https://github.com/elastic/terraform-provider-elasticstack/pull/811))

## [0.11.7] - 2024-09-20

Expand Down
2 changes: 1 addition & 1 deletion docs/resources/fleet_output.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ resource "elasticstack_fleet_output" "test_output" {
- `default_monitoring` (Boolean) Make this output the default for agent monitoring.
- `hosts` (List of String) A list of hosts.
- `output_id` (String) Unique identifier of the output.
- `ssl` (Block List, Max: 1) SSL configuration. (see [below for nested schema](#nestedblock--ssl))
- `ssl` (Block List) SSL configuration. (see [below for nested schema](#nestedblock--ssl))

### Read-Only

Expand Down
101 changes: 45 additions & 56 deletions internal/clients/fleet/fleet.go

Large diffs are not rendered by default.

45 changes: 45 additions & 0 deletions internal/fleet/output/create.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package output

import (
"context"

"github.com/elastic/terraform-provider-elasticstack/internal/clients/fleet"
"github.com/hashicorp/terraform-plugin-framework/resource"
)

func (r *outputResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) {
var planModel outputModel

diags := req.Plan.Get(ctx, &planModel)
resp.Diagnostics.Append(diags...)
if resp.Diagnostics.HasError() {
return
}

client, err := r.client.GetFleetClient()
if err != nil {
resp.Diagnostics.AddError(err.Error(), "")
return
}

body, diags := planModel.toAPICreateModel(ctx)
resp.Diagnostics.Append(diags...)
if resp.Diagnostics.HasError() {
return
}

output, diags := fleet.CreateOutput(ctx, client, body)
resp.Diagnostics.Append(diags...)
if resp.Diagnostics.HasError() {
return
}

diags = planModel.populateFromAPICreate(ctx, output)
resp.Diagnostics.Append(diags...)
if resp.Diagnostics.HasError() {
return
}

diags = resp.State.Set(ctx, planModel)
resp.Diagnostics.Append(diags...)
}
28 changes: 28 additions & 0 deletions internal/fleet/output/delete.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package output

import (
"context"

"github.com/elastic/terraform-provider-elasticstack/internal/clients/fleet"
"github.com/hashicorp/terraform-plugin-framework/resource"
)

func (r *outputResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) {
var stateModel outputModel

diags := req.State.Get(ctx, &stateModel)
resp.Diagnostics.Append(diags...)
if resp.Diagnostics.HasError() {
return
}

client, err := r.client.GetFleetClient()
if err != nil {
resp.Diagnostics.AddError(err.Error(), "")
return
}

outputID := stateModel.OutputID.ValueString()
diags = fleet.DeleteOutput(ctx, client, outputID)
resp.Diagnostics.Append(diags...)
}
Loading
Loading