func flattenIntegrationsServerResources()

in ec/ecdatasource/deploymentdatasource/flatteners_integrations_server.go [34:88]


func flattenIntegrationsServerResources(ctx context.Context, in []*models.IntegrationsServerResourceInfo) (types.List, diag.Diagnostics) {
	var diagnostics diag.Diagnostics
	var result = make([]integrationsServerResourceInfoModelV0, 0, len(in))

	for _, res := range in {
		model := integrationsServerResourceInfoModelV0{
			Topology: types.ListNull(types.ObjectType{AttrTypes: integrationsServerTopologyAttrTypes()}),
		}

		if res.ElasticsearchClusterRefID != nil {
			model.ElasticsearchClusterRefID = types.StringValue(*res.ElasticsearchClusterRefID)
		}

		if res.RefID != nil {
			model.RefID = types.StringValue(*res.RefID)
		}

		if res.Info != nil {
			if res.Info.Healthy != nil {
				model.Healthy = types.BoolValue(*res.Info.Healthy)
			}

			if res.Info.ID != nil {
				model.ResourceID = types.StringValue(*res.Info.ID)
			}

			if res.Info.Status != nil {
				model.Status = types.StringValue(*res.Info.Status)
			}

			if !util.IsCurrentIntegrationsServerPlanEmpty(res) {
				var plan = res.Info.PlanInfo.Current.Plan

				if plan.IntegrationsServer != nil {
					model.Version = types.StringValue(plan.IntegrationsServer.Version)
				}

				var diags diag.Diagnostics
				model.Topology, diags = flattenIntegrationsServerTopology(ctx, plan)
				diagnostics.Append(diags...)
			}

			if res.Info.Metadata != nil {
				model.HttpEndpoint, model.HttpsEndpoint = converters.ExtractEndpointsToTypes(res.Info.Metadata)
			}
		}

		result = append(result, model)
	}

	target, diags := types.ListValueFrom(ctx, types.ObjectType{AttrTypes: integrationsServerResourceInfoAttrTypes()}, result)
	diagnostics.Append(diags...)

	return target, diagnostics
}