majordomo

package
v1.12.1 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Resource

type Resource[T any, H hcl.HCL[T]] struct {
	// contains filtered or unexported fields
}

Resource manages CRUD operations and marshaling between `hcl` and `tg` types.

func NewResource

func NewResource[T any, H hcl.HCL[T]](args ResourceArgs[T, H]) *Resource[T, H]

NewResource returns a new `Resource`.

func (*Resource[T, H]) Create

func (r *Resource[T, H]) Create(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics

Create calls the `CreateURL` function to get the URL for POST-ing the resource. If `CreateURL` is not set, calls `Update`. HCL information is decoded from the `ResourceData` and marshaled to `tg` type before POST-ing.

func (*Resource[T, H]) Delete

func (r *Resource[T, H]) Delete(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics

Delete calls the `DeleteURL` function to get the URL for DELETE-ing the resource. HCL information is decoded from the `ResourceData` and marshaled to `tg` type before DELETE-ing.

func (*Resource[T, H]) Noop

func (r *Resource[T, H]) Noop(_ context.Context, _ *schema.ResourceData, _ any) diag.Diagnostics

Noop is a no-op function that returns no diagnostics.

func (*Resource[T, H]) Read

func (r *Resource[T, H]) Read(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics

Read calls the `GetURL` function to get the URL for GET-ing the resource. If `GetURL` is not set, calls `Index` and searches for the resource. HCL information is decoded from the `ResourceData` and marshaled to `tg` type before GET-ing. After retrieving the API record, the HCL resource will be updated with the new information.

func (*Resource[T, H]) Update

func (r *Resource[T, H]) Update(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics

Update calls the `UpdateURL` function to get the URL for PUT-ing the resource. HCL information is decoded from the `ResourceData` and marshaled to `tg` type before PUT-ing.

type ResourceArgs

type ResourceArgs[T any, H hcl.HCL[T]] struct {
	CreateURL     func(H) string                                     // CreateURL should return the URL for POST-ing the resource. If not set, calls to `Create` will attempt to call `Update`.
	OnCreateReply func(*schema.ResourceData, []byte) (string, error) // OnCreateReply is called after a successful POST request. The ID returned will be set as the resource ID.
	OnUpdateReply func(*schema.ResourceData, []byte) (string, error) // OnUpdateReply is called after a successful PUT request. The ID returned will be set as the resource ID.
	GetFromNode   func(tg.Node) (T, bool, error)                     // GetFromNode should return the `tg` resource from the `tg.Node` resource.
	DeleteURL     func(H) string                                     // DeleteURL should return the URL for DELETE-ing the resource.
	GetURL        func(H) string                                     // GetURL should return the URL for GET-ing the resource, provided the API supports individual lookups.
	UpdateURL     func(H) string                                     // UpdateURL should return the URL for PUT-ing the resource.
	IndexURL      func() string                                      // IndexURL should return the URL for GET-ing a list of resources. If this and RemoteID are provided and GetURL is not, `Read` will attempt to call `Index` and search for the resource.
	RemoteID      func(T) string                                     // RemoteID should return the ID of `tg` resource from the remote API.
	ID            func(H) string                                     // ID should return the ID of the `hcl` resource.
}

Jump to

Keyboard shortcuts

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