in internal/kibana/synthetics/schema.go [569:671]
func (v *tfModelV0) toModelV0(ctx context.Context, api *kbapi.SyntheticsMonitor) (*tfModelV0, diag.Diagnostics) {
var schedule int64
var err error
dg := diag.Diagnostics{}
if api.Schedule != nil {
schedule, err = stringToInt64(api.Schedule.Number)
if err != nil {
dg.AddError("Failed to convert schedule to int64", err.Error())
return nil, dg
}
}
var privateLocLabels []string
for _, l := range api.Locations {
if !l.IsServiceManaged {
privateLocLabels = append(privateLocLabels, l.Label)
}
}
timeout, err := stringToInt64(string(api.Timeout))
if err != nil {
dg.AddError("Failed to convert timeout to int64", err.Error())
return nil, dg
}
var http *tfHTTPMonitorFieldsV0
var tcp *tfTCPMonitorFieldsV0
var icmp *tfICMPMonitorFieldsV0
var browser *tfBrowserMonitorFieldsV0
switch mType := api.Type; mType {
case kbapi.Http:
http = &tfHTTPMonitorFieldsV0{}
if v.HTTP != nil {
http = v.HTTP
}
http = http.toTfHTTPMonitorFieldsV0(ctx, dg, api)
case kbapi.Tcp:
tcp = &tfTCPMonitorFieldsV0{}
if v.TCP != nil {
tcp = v.TCP
}
tcp = tcp.toTfTCPMonitorFieldsV0(ctx, dg, api)
case kbapi.Icmp:
icmp = &tfICMPMonitorFieldsV0{}
if v.ICMP != nil {
icmp = v.ICMP
}
icmp, err = icmp.toTfICMPMonitorFieldsV0(api)
case kbapi.Browser:
browser = &tfBrowserMonitorFieldsV0{}
if v.Browser != nil {
browser = v.Browser
}
browser, err = browser.toTfBrowserMonitorFieldsV0(api)
default:
err = fmt.Errorf("unsupported monitor type: %s", mType)
}
if err != nil {
dg.AddError("Failed to convert monitor fields", err.Error())
return nil, dg
}
params := v.Params
if api.Params != nil {
params, err = toNormalizedValue(api.Params)
if err != nil {
dg.AddError("Failed to parse params", err.Error())
return nil, dg
}
}
resourceID := clients.CompositeId{
ClusterId: api.Namespace,
ResourceId: string(api.Id),
}
alertV0, dg := toTfAlertConfigV0(ctx, api.Alert)
if dg.HasError() {
return nil, dg
}
return &tfModelV0{
ID: types.StringValue(resourceID.String()),
Name: types.StringValue(api.Name),
SpaceID: types.StringValue(api.Namespace),
Schedule: types.Int64Value(schedule),
Locations: v.Locations,
PrivateLocations: StringSliceValue(privateLocLabels),
Enabled: types.BoolPointerValue(api.Enabled),
Tags: StringSliceValue(api.Tags),
Alert: alertV0,
APMServiceName: types.StringValue(api.APMServiceName),
TimeoutSeconds: types.Int64Value(timeout),
Params: params,
HTTP: http,
TCP: tcp,
ICMP: icmp,
Browser: browser,
RetestOnFailure: v.RetestOnFailure,
}, dg
}