func flattenElasticsearchConfig()

in ec/ecdatasource/stackdatasource/flatteners_elasticsearch.go [30:89]


func flattenElasticsearchConfig(ctx context.Context, res *models.StackVersionElasticsearchConfig) (types.List, diag.Diagnostics) {
	var diags diag.Diagnostics
	model := newElasticsearchConfigModelV0()

	target := types.ListNull(elasticsearchConfigSchema().GetType().(types.ListType).ElemType)
	empty := true

	if res == nil {
		return target, diags
	}

	if len(res.Blacklist) > 0 {
		var d diag.Diagnostics
		model.DenyList, d = types.ListValueFrom(ctx, types.StringType, res.Blacklist)
		diags.Append(d...)
		empty = false
	}

	if res.CapacityConstraints != nil {
		model.CapacityConstraintsMax = types.Int64Value(int64(*res.CapacityConstraints.Max))
		model.CapacityConstraintsMin = types.Int64Value(int64(*res.CapacityConstraints.Min))
		empty = false
	}

	if len(res.CompatibleNodeTypes) > 0 {
		var d diag.Diagnostics
		model.CompatibleNodeTypes, d = types.ListValueFrom(ctx, types.StringType, res.CompatibleNodeTypes)
		diags.Append(d...)
		empty = false
	}

	if res.DockerImage != nil && *res.DockerImage != "" {
		model.DockerImage = types.StringValue(*res.DockerImage)
		empty = false
	}

	if len(res.Plugins) > 0 {
		var d diag.Diagnostics
		model.Plugins, d = types.ListValueFrom(ctx, types.StringType, res.Plugins)
		diags.Append(d...)
		empty = false
	}

	if len(res.DefaultPlugins) > 0 {
		var d diag.Diagnostics
		model.DefaultPlugins, d = types.ListValueFrom(ctx, types.StringType, res.DefaultPlugins)
		diags.Append(d...)
		empty = false
	}

	if empty {
		return target, diags
	}

	var d diag.Diagnostics
	target, d = types.ListValueFrom(ctx, target.ElementType(ctx), []elasticsearchConfigModelV0{model})
	diags.Append(d...)

	return target, diags
}