common

package
v2.18.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	ResourceIDFieldTypeInt    = ResourceIDFieldType("int")
	ResourceIDFieldTypeString = ResourceIDFieldType("string")
)
View Source
const NotFoundError = "status: 404"

Variables

View Source
var (
	IDRegexp     = regexp.MustCompile(`^\d+$`)
	UIDRegexp    = regexp.MustCompile(`^[a-zA-Z0-9-_]+$`)
	EmailRegexp  = regexp.MustCompile(`.+\@.+\..+`)
	SHA256Regexp = regexp.MustCompile(`^[A-Fa-f0-9]{64}$`)
)

Functions

func AllowedValuesDescription

func AllowedValuesDescription(description string, allowedValues []string) string

func CheckReadError

func CheckReadError(resourceType string, d *schema.ResourceData, err error) (returnValue diag.Diagnostics, shouldReturn bool)

CheckReadError checks for common cases on resource read/delete paths: - If the resource no longer exists and 404s, it should be removed from state and return nil, to stop processing the read. - If there is an error, return the error. - Otherwise, do not return to continue processing the read.

func CloneResourceSchemaForDatasource

func CloneResourceSchemaForDatasource(r *schema.Resource, updates map[string]*schema.Schema) map[string]*schema.Schema

func ComputedInt

func ComputedInt() *schema.Schema

func ComputedIntWithDescription

func ComputedIntWithDescription(description string) *schema.Schema

func ComputedString

func ComputedString() *schema.Schema

func ComputedStringWithDescription

func ComputedStringWithDescription(description string) *schema.Schema

func Int32SliceToIntList

func Int32SliceToIntList(list []int32) []interface{}

func Int32SliceToSet

func Int32SliceToSet(src []int32) *schema.Set

func IsNotFoundError

func IsNotFoundError(err error) bool

func JSONBytesEqual

func JSONBytesEqual(b1, b2 []byte) bool

func ListOfSetsToStringSlice

func ListOfSetsToStringSlice(listSet []interface{}) [][]string

func ListToIntSlice

func ListToIntSlice[T int | int64](src []interface{}) []T

func ListToStringSlice

func ListToStringSlice(src []interface{}) []string

func Ref

func Ref[T any](v T) *T

func SchemaDiffFloat32

func SchemaDiffFloat32(k, old string, nw string, d *schema.ResourceData) bool

SchemaDiffFloat32 is a SchemaDiffSuppressFunc for diffing float32 values. schema.TypeFloat uses float64, which is a problem for API types that use float32. Terraform automatically converts float32 to float64 which changes the precision and causes incorrect diffs.

For example, synthetic_monitoring.Probe.Latitude is float32. Attempting to set grafanacloud_synthetic_monitoring_probe.latitude to 27.98606 results in 27.986059188842773. The solution is to diff old and new values as float32.

func SetToIntSlice

func SetToIntSlice[T int | int64](src *schema.Set) []T

func SetToStringSlice

func SetToStringSlice(src *schema.Set) []string

func StringSliceToList

func StringSliceToList(list []string) []interface{}

func StringSliceToSet

func StringSliceToSet(src []string) *schema.Set

func SuppressEquivalentJSONDiffs

func SuppressEquivalentJSONDiffs(k, old, new string, d *schema.ResourceData) bool

func UnpackMap

func UnpackMap[T any](m interface{}) map[string]T

func ValidateDuration

func ValidateDuration(i interface{}, p cty.Path) diag.Diagnostics

func ValidateDurationWithDays

func ValidateDurationWithDays(i interface{}, p cty.Path) diag.Diagnostics

func WarnMissing

func WarnMissing(resourceType string, d *schema.ResourceData) diag.Diagnostics

func WithAlertingMutex

WithAlertingMutex is a helper function that wraps a CRUD Terraform function with a mutex.

Types

type Client

type Client struct {
	GrafanaAPIURL       string
	GrafanaAPIURLParsed *url.URL
	GrafanaAPI          *goapi.GrafanaHTTPAPI
	GrafanaAPIConfig    *goapi.TransportConfig

	GrafanaCloudAPI *gcom.APIClient
	SMAPI           *SMAPI.Client
	MLAPI           *mlapi.Client
	OnCallClient    *onCallAPI.Client
	SLOClient       *slo.APIClient
	// contains filtered or unexported fields
}

func (*Client) GrafanaSubpath

func (c *Client) GrafanaSubpath(path string) string

type Resource

type Resource struct {
	Name                  string
	IDType                *ResourceID
	Schema                *schema.Resource
	PluginFrameworkSchema resource.ResourceWithConfigure
}

func NewLegacySDKResource added in v2.15.0

func NewLegacySDKResource(name string, idType *ResourceID, schema *schema.Resource) *Resource

func NewResource

func NewResource(name string, idType *ResourceID, schema resource.ResourceWithConfigure) *Resource

func (*Resource) ImportExample

func (r *Resource) ImportExample() string

type ResourceID

type ResourceID struct {
	// contains filtered or unexported fields
}

func NewResourceID

func NewResourceID(expectedFields ...ResourceIDField) *ResourceID

func NewResourceIDWithLegacySeparator deprecated

func NewResourceIDWithLegacySeparator(legacySeparator string, expectedFields ...ResourceIDField) *ResourceID

Deprecated: Use NewResourceID instead We should standardize on a single separator, so that function should only be used for old resources On major versions, switch to NewResourceID and remove uses of this function

func (*ResourceID) Fields added in v2.16.0

func (id *ResourceID) Fields() []ResourceIDField

func (*ResourceID) Make

func (id *ResourceID) Make(parts ...any) string

Make creates a resource ID from the given parts The parts must have the correct number of fields and types

func (*ResourceID) RequiredFields added in v2.15.0

func (id *ResourceID) RequiredFields() []ResourceIDField

func (*ResourceID) Single

func (id *ResourceID) Single(resourceID string) (any, error)

Single parses a resource ID into a single value

func (*ResourceID) Split

func (id *ResourceID) Split(resourceID string) ([]any, error)

Split parses a resource ID into its parts The parts will be cast to the expected types

type ResourceIDField

type ResourceIDField struct {
	Name     string
	Type     ResourceIDFieldType
	Optional bool
}

func IntIDField

func IntIDField(name string) ResourceIDField

func OptionalIntIDField added in v2.15.0

func OptionalIntIDField(name string) ResourceIDField

func OptionalStringIDField added in v2.15.0

func OptionalStringIDField(name string) ResourceIDField

func StringIDField

func StringIDField(name string) ResourceIDField

type ResourceIDFieldType

type ResourceIDFieldType string

Jump to

Keyboard shortcuts

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