common

package
v3.14.1 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2024 License: MPL-2.0 Imports: 27 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ResourceIDSeparator       = ":"
	ResourceIDFieldTypeInt    = ResourceIDFieldType("int")
	ResourceIDFieldTypeString = ResourceIDFieldType("string")
)
View Source
const NotFoundError = "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
	CloudProviderAPI     *cloudproviderapi.Client
	ConnectionsAPIClient *connectionsapi.Client
	// contains filtered or unexported fields
}

func (*Client) GrafanaSubpath

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

type DataSource added in v3.2.0

type DataSource struct {
	ResourceCommon
	PluginFrameworkSchema datasource.DataSourceWithConfigure
}

DataSource represents a Terraform data source, implemented either with the SDKv2 or Terraform Plugin Framework.

func NewDataSource added in v3.2.0

func NewDataSource(category ResourceCategory, name string, schema datasource.DataSourceWithConfigure) *DataSource

func NewLegacySDKDataSource added in v3.2.0

func NewLegacySDKDataSource(category ResourceCategory, name string, schema *schema.Resource) *DataSource

type Resource

type Resource struct {
	ResourceCommon
	IDType                *ResourceID
	PluginFrameworkSchema resource.ResourceWithConfigure

	// Generation configuration
	ListIDsFunc                ResourceListIDsFunc
	PreferredResourceNameField string // This field will be used as the resource name instead of the ID. This is useful if the ID is not ideal for humans (ex: UUID or numeric). The field value should uniquely identify the resource.
}

Resource represents a Terraform resource, implemented either with the SDKv2 or Terraform Plugin Framework.

func NewLegacySDKResource

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

func NewResource

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

func (*Resource) ImportExample

func (r *Resource) ImportExample() string

func (*Resource) WithLister

func (r *Resource) WithLister(lister ResourceListIDsFunc) *Resource

func (*Resource) WithPreferredResourceNameField added in v3.8.0

func (r *Resource) WithPreferredResourceNameField(fieldName string) *Resource

type ResourceCategory added in v3.2.0

type ResourceCategory string
var (
	CategoryAlerting            ResourceCategory = "Alerting"
	CategoryCloud               ResourceCategory = "Cloud"
	CategoryGrafanaEnterprise   ResourceCategory = "Grafana Enterprise"
	CategoryGrafanaOSS          ResourceCategory = "Grafana OSS"
	CategoryMachineLearning     ResourceCategory = "Machine Learning"
	CategoryOnCall              ResourceCategory = "OnCall"
	CategorySLO                 ResourceCategory = "SLO"
	CategorySyntheticMonitoring ResourceCategory = "Synthetic Monitoring"
	CategoryCloudProvider       ResourceCategory = "Cloud Provider"
	CategoryConnections         ResourceCategory = "Connections"
)

type ResourceCommon added in v3.2.0

type ResourceCommon struct {
	Name     string
	Schema   *schema.Resource // Legacy SDKv2 schema
	Category ResourceCategory
}

type ResourceID

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

func NewResourceID

func NewResourceID(expectedFields ...ResourceIDField) *ResourceID

func (*ResourceID) Fields

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

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

func OptionalIntIDField(name string) ResourceIDField

func OptionalStringIDField

func OptionalStringIDField(name string) ResourceIDField

func StringIDField

func StringIDField(name string) ResourceIDField

type ResourceIDFieldType

type ResourceIDFieldType string

type ResourceListIDsFunc

type ResourceListIDsFunc func(ctx context.Context, client *Client, data any) ([]string, error)

ResourceListIDsFunc is a function that returns a list of resource IDs. This is used to generate TF config from existing resources. The data arg can be used to pass information between different listers. For example, the list of stacks will be used when listing stack plugins.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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