func flattenElasticsearchResources()

in ec/ecdatasource/deploymentdatasource/flatteners_elasticsearch.go [37:92]


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

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

		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.ClusterID != nil {
				model.ResourceID = types.StringValue(*res.Info.ClusterID)
			}

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

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

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

				if plan.AutoscalingEnabled != nil {
					model.Autoscale = types.StringValue(strconv.FormatBool(*plan.AutoscalingEnabled))
				}

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

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

		result = append(result, model)
	}

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

	return target, diagnostics
}