mdbcommon

package
v0.140.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 3, 2025 License: MPL-2.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var BackupWindowType = types.ObjectType{
	AttrTypes: map[string]attr.Type{
		"hours":   types.Int64Type,
		"minutes": types.Int64Type,
	},
}
View Source
var MaintenanceWindowType = types.ObjectType{
	AttrTypes: map[string]attr.Type{
		"type": types.StringType,
		"day":  types.StringType,
		"hour": types.Int64Type,
	},
}
View Source
var ResourceType = types.ObjectType{
	AttrTypes: map[string]attr.Type{
		"resource_preset_id": types.StringType,
		"disk_type_id":       types.StringType,
		"disk_size":          types.Int64Type,
	},
}

Functions

func CreateClusterHosts

func CreateClusterHosts[T Host, H any, HS any, U any](ctx context.Context,
	utilsHostService CmpHostService[T, H, HS, U],
	hostSpecs basetypes.MapValue) ([]HS, diag.Diagnostics)

CreateClusterHosts is a method called during the host creation process. It converts hosts from their model representation to specifications suitable for use with the createHosts method. Finally, return the list of host specifications ready for creation and any diagnostic information collected.

func ExpandBackupWindow

func ExpandBackupWindow(ctx context.Context, bw types.Object, diags *diag.Diagnostics) *timeofday.TimeOfDay

func ExpandClusterMaintenanceWindow

func ExpandClusterMaintenanceWindow[
	V any,
	VW any,
	VA any,

	WD ~int32,

	T maintenanceWindow[
		V,
		VW, VA,
		WD,
		W, A,
	],

	W weeklyMaintenanceWindow[VW, WD],
	A anytimeMaintenanceWindow[VA],
](ctx context.Context, mw types.Object, diags *diag.Diagnostics) T

func ExpandEnvironment

func ExpandEnvironment[T ~int32](_ context.Context, e types.String, diags *diag.Diagnostics) T

func ExpandFolderId

func ExpandFolderId(ctx context.Context, f types.String, providerConfig *config.State, diags *diag.Diagnostics) string

func ExpandInt64Wrapper

func ExpandInt64Wrapper(ctx context.Context, in types.Int64, diags *diag.Diagnostics) *wrapperspb.Int64Value

func ExpandLabels

func ExpandLabels(ctx context.Context, labels types.Map, diags *diag.Diagnostics) map[string]string

func ExpandResources

func ExpandResources[V any, T resourceModel[V]](ctx context.Context, o types.Object, diags *diag.Diagnostics) T

func ExpandSecurityGroupIds

func ExpandSecurityGroupIds(ctx context.Context, sg types.Set, diags *diag.Diagnostics) []string

func FlattenBackupWindowStart

func FlattenBackupWindowStart(ctx context.Context, bws *timeofday.TimeOfDay, diags *diag.Diagnostics) types.Object

func FlattenBoolWrapper

func FlattenBoolWrapper(ctx context.Context, wb *wrapperspb.BoolValue, diags *diag.Diagnostics) types.Bool

func FlattenInt64Wrapper

func FlattenInt64Wrapper(ctx context.Context, pgBrpd *wrapperspb.Int64Value, diags *diag.Diagnostics) types.Int64

func FlattenMaintenanceWindow

func FlattenMaintenanceWindow[
	V any,
	VW any, VA any,

	WD ~int32,

	W weeklyMaintenanceWindow[VW, WD],
	A anytimeMaintenanceWindow[VA],

	T maintenanceWindow[V, VW, VA, WD, W, A],
](ctx context.Context, mw T, diags *diag.Diagnostics) types.Object

func FlattenMapString

func FlattenMapString(ctx context.Context, ms map[string]string, diags *diag.Diagnostics) types.Map

func FlattenResources

func FlattenResources[V any, T resourceModel[V]](ctx context.Context, r T, diags *diag.Diagnostics) types.Object

func FlattenSetString

func FlattenSetString(ctx context.Context, ss []string, diags *diag.Diagnostics) types.Set

func GetAttrNamesSetFromMap

func GetAttrNamesSetFromMap(o types.Map, diags *diag.Diagnostics) map[string]struct{}

func GetClusterIdForDatasource

func GetClusterIdForDatasource(ctx context.Context, providerConfig *provider_config.Config, config tfsdk.Config) (string, diag.Diagnostics)

GetClusterIdForDatasource retrieves the cluster ID for a given datasource. It accepts either a direct cluster ID or resolves it using the name attribute.

func GetUserConfig

func GetUserConfig(ctx context.Context, c interface{}, confAttrName string, diags *diag.Diagnostics) interface{}

GetUserConfig extracts UserConfig from a cluster config struct by protobuf tag

c must be a valid ClusterConfigStructure

func IsAttrZeroValue

func IsAttrZeroValue(val attr.Value, diags *diag.Diagnostics) bool

func ReadHosts

func ReadHosts[T Host, H ProtoHost, HS any, U any](
	ctx context.Context,
	sdk *ycsdk.SDK,
	diags *diag.Diagnostics,
	utilsHostService CmpHostService[T, H, HS, U],
	hostsApiService HostApiService[H, HS, U],
	stateHosts basetypes.MapValue,
	cid string,
) map[string]T

The ReadHosts method is used to update the state of hosts.

1. Map hosts from api to hosts in state by fqdn 2. Map hosts from api to hosts in state without fqdn by equal attributes 3. Add hosts from api to state if not mapped

func UpdateClusterHosts

func UpdateClusterHosts[T Host, H any, HS any, U any](
	ctx context.Context,
	sdk *ycsdk.SDK,
	diagnostics *diag.Diagnostics,
	utilsHostService CmpHostService[T, H, HS, U],
	hostsApiService HostApiService[H, HS, U],
	cid string,
	plan, state types.Map,
)

UpdateClusterHosts Method to update hosts within a cluster 1) Substitute labels using modifyStateDependsPlan

  • Utilize modifyStateDependsPlan to adjust labels in the state to match those intended in the plan.
  • This aims to prevent redundant host creation/deletion by better aligning the current state with the plan.

2) Calculate changes for Hosts

  • Determine which hosts need to be created, updated, or deleted by comparing current state with the desired plan.

3) Create remaining hosts 4) Update existing hosts 5) Delete remaining hosts

func UpdateClusterHostsWithShards

func UpdateClusterHostsWithShards[T HostWithShard, H any, HS ProtoHostWithShard, U any](
	ctx context.Context,
	sdk *ycsdk.SDK,
	diagnostics *diag.Diagnostics,
	utilsHostService CmpHostService[T, H, HS, U],
	hostsApiService HostApiServiceWithShards[H, HS, U],
	cid string,
	plan, state types.Map,
)

UpdateClusterHostsWithShards Method to update hosts and shards within a cluster 1) Substitute labels using modifyStateDependsPlan

  • Utilize modifyStateDependsPlan to adjust labels in the state to match those intended in the plan.
  • This aims to prevent redundant host creation/deletion by better aligning the current state with the plan.

2) Calculate changes for Hosts

  • Determine which hosts need to be created, updated, or deleted by comparing current state with the desired plan.

3) Calculate changes for Shards

  • Analyze differences in shard configurations between the current state and desired plan to decide which shards require creation or deletion.

4) Clean up host changes based on shard changes

  • Adjust host change operations to reflect shard changes accurately, avoiding unnecessary actions. For example, if a shard is being deleted, associated hosts will also be removed.

5) Create new shards 6) Create remaining hosts 7) Update existing hosts 8) Delete shards 9) Delete remaining hosts

Types

type BackupWindow

type BackupWindow struct {
	Hours   types.Int64 `tfsdk:"hours"`
	Minutes types.Int64 `tfsdk:"minutes"`
}

type CmpHostService

type CmpHostService[T Host, ProtoHost any, ProtoHostSpec any, UpdateSpec any] interface {
	// FullyMatch performs a complete comparison of all fields in two host models, similar to an equals method.
	// It also handles cases where fields may be unknown, ensuring robust comparison for complete state verification.
	FullyMatch(plan T, state T) bool
	// PartialMatch compares fields that cannot be changed by update methods.
	// It is designed to handle situations with unknown fields, focusing on attributes that must remain consistent.
	PartialMatch(plan T, state T) bool
	// GetChanges determines the differences between two host models.
	// If immutable fields have been changed, it returns an error.
	// If there are no changes, it returns nil; otherwise, it gathers an UpdateSpec to send to the API.
	GetChanges(plan T, state T) (*UpdateSpec, diag.Diagnostics)
	// ConvertToProto converts a host model to a specification suitable for host creation.
	// This method transforms the terraform model type to the `ProtoHostSpec` type used in API operations.
	ConvertToProto(T) ProtoHostSpec
	// ConvertFromProto converts an API-returned structure to the host model.
	// This method is essential for integrating responses into the terraform state model.
	ConvertFromProto(ProtoHost) T
}

CmpHostService is an interface for implementing common parsing methods for host models. T - Represents the host model within Terraform, likely detailing configuration and state as defined in Terraform templates. PortoHost - Refers to the protobuf type returned by a listHosts API call. It represents how hosts are structured in API communications. ProtoHostSpec - Is the protobuf type used for creating a host. It specifies the properties and configurations needed for API host creation. UpdateSpec - The protobuf type used for updating hosts, detailing the necessary changes.

type Host

type Host interface {
	GetFQDN() types.String
}

type HostApiService

type HostApiService[ProtoHost any, ProtoHostSpec any, UpdateSpec any] interface {
	ListHosts(ctx context.Context, sdk *ycsdk.SDK, diag *diag.Diagnostics, cid string) []ProtoHost
	CreateHosts(ctx context.Context, sdk *ycsdk.SDK, diag *diag.Diagnostics, cid string, specs []ProtoHostSpec)
	UpdateHosts(ctx context.Context, sdk *ycsdk.SDK, diag *diag.Diagnostics, cid string, specs []*UpdateSpec)
	DeleteHosts(ctx context.Context, sdk *ycsdk.SDK, diag *diag.Diagnostics, cid string, fqdns []string)
}

HostApiService is an interface that defines methods for API operations involving hosts. It is parameterized with types `ProtoHost`, `ProtoHostSpec`, and `UpdateSpec`

type HostApiServiceWithShards

type HostApiServiceWithShards[ProtoHost any, ProtoHostSpec any, UpdateSpec any] interface {
	HostApiService[ProtoHost, ProtoHostSpec, UpdateSpec]
	CreateShard(ctx context.Context, sdk *ycsdk.SDK, diag *diag.Diagnostics, cid, shardName string, hostSpecs []ProtoHostSpec)
	DeleteShard(ctx context.Context, sdk *ycsdk.SDK, diag *diag.Diagnostics, cid, shardName string)
}

HostApiService is an interface that defines methods for API operations involving hosts with shards. It is parameterized with types `ProtoHost`, `ProtoHostSpec`, and `UpdateSpec`

type HostWithShard

type HostWithShard interface {
	Host
	GetShard() string
}

type MaintenanceWindow

type MaintenanceWindow struct {
	Type types.String `tfsdk:"type"`
	Day  types.String `tfsdk:"day"`
	Hour types.Int64  `tfsdk:"hour"`
}

type ProtoHost

type ProtoHost interface {
	GetName() string
}

type ProtoHostWithShard

type ProtoHostWithShard interface {
	GetShardName() string
}

type Resource

type Resource struct {
	ResourcePresetId types.String `tfsdk:"resource_preset_id"`
	DiskSize         types.Int64  `tfsdk:"disk_size"`
	DiskTypeId       types.String `tfsdk:"disk_type_id"`
}

type SettingsAttributeInfoProvider

type SettingsAttributeInfoProvider interface {
	GetSettingsEnumNames() map[string]map[int32]string
	GetSettingsEnumValues() map[string]map[string]int32
	GetSetAttributes() map[string]struct{}
}

type SettingsMapType

type SettingsMapType struct {
	basetypes.MapType
	// contains filtered or unexported fields
}

SettingsMapType type is based on the example in the terraform plugin framerwork documentation https://developer.hashicorp.com/terraform/plugin/framework/handling-data/types/custom

Type is add-on to the string map for the mapping to primitive fields (Numbers, Bool, String) Used to configure Postgresql settings.

func (SettingsMapType) Equal

func (t SettingsMapType) Equal(o attr.Type) bool

Equal compare MsSettingsMapType with provided type

func (SettingsMapType) String

func (t SettingsMapType) String() string

func (SettingsMapType) ValueFromMap

ValueFromMap used to get MsSettingsMapType from a map value

func (SettingsMapType) ValueFromTerraform

func (t SettingsMapType) ValueFromTerraform(ctx context.Context, in tftypes.Value) (attr.Value, error)

ValueFromTerraform is a basic implementation of getting MsSettingsMapType value from terraform value

From example: https://developer.hashicorp.com/terraform/plugin/framework/handling-data/types/custom

func (SettingsMapType) ValueType

func (t SettingsMapType) ValueType(ctx context.Context) attr.Value

type SettingsMapValue

type SettingsMapValue struct {
	basetypes.MapValue
	// contains filtered or unexported fields
}

func NewSettingsMapNull

func NewSettingsMapNull() SettingsMapValue

func NewSettingsMapUnknown

func NewSettingsMapUnknown() SettingsMapValue

func NewSettingsMapValue

func NewSettingsMapValue(elements map[string]attr.Value, p SettingsAttributeInfoProvider) (SettingsMapValue, diag.Diagnostics)

NewMsSettingsMapValue creates MsSettingsMapValue from map[string]attr.Value, where attr.Value is a primitive value

func NewSettingsMapValueMust

func NewSettingsMapValueMust(elements map[string]attr.Value, p SettingsAttributeInfoProvider) SettingsMapValue

func (SettingsMapValue) Equal

func (v SettingsMapValue) Equal(o attr.Value) bool

Compare map values and elements values inside

func (SettingsMapValue) PrimitiveElements

func (v SettingsMapValue) PrimitiveElements(ctx context.Context, diags *diag.Diagnostics) map[string]attr.Value

PrimitiveElements is necessary to get primitive values map from a MsSettingsMapValue

func (SettingsMapValue) Type

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL