internal/fleet/integration_policy/resource.go (36 lines of code) (raw):
package integration_policy
import (
"context"
"fmt"
"github.com/elastic/terraform-provider-elasticstack/internal/clients"
"github.com/hashicorp/terraform-plugin-framework/path"
"github.com/hashicorp/terraform-plugin-framework/resource"
)
var (
_ resource.Resource = &integrationPolicyResource{}
_ resource.ResourceWithConfigure = &integrationPolicyResource{}
_ resource.ResourceWithImportState = &integrationPolicyResource{}
_ resource.ResourceWithUpgradeState = &integrationPolicyResource{}
)
// NewResource is a helper function to simplify the provider implementation.
func NewResource() resource.Resource {
return &integrationPolicyResource{}
}
type integrationPolicyResource struct {
client *clients.ApiClient
}
func (r *integrationPolicyResource) Configure(ctx context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse) {
client, diags := clients.ConvertProviderData(req.ProviderData)
resp.Diagnostics.Append(diags...)
r.client = client
}
func (r *integrationPolicyResource) Metadata(ctx context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) {
resp.TypeName = fmt.Sprintf("%s_%s", req.ProviderTypeName, "fleet_integration_policy")
}
func (r *integrationPolicyResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) {
resource.ImportStatePassthroughID(ctx, path.Root("policy_id"), req, resp)
}
func (r *integrationPolicyResource) UpgradeState(context.Context) map[int64]resource.StateUpgrader {
return map[int64]resource.StateUpgrader{
0: {PriorSchema: getSchemaV0(), StateUpgrader: upgradeV0},
}
}