Documentation ¶
Index ¶
- Constants
- Variables
- func AllowedValuesDescription(description string, allowedValues []string) string
- func CheckReadError(resourceType string, d *schema.ResourceData, err error) (returnValue diag.Diagnostics, shouldReturn bool)
- func CloneResourceSchemaForDatasource(r *schema.Resource, updates map[string]*schema.Schema) map[string]*schema.Schema
- func ComputedInt() *schema.Schema
- func ComputedIntWithDescription(description string) *schema.Schema
- func ComputedString() *schema.Schema
- func ComputedStringWithDescription(description string) *schema.Schema
- func Int32SliceToIntList(list []int32) []interface{}
- func Int32SliceToSet(src []int32) *schema.Set
- func IsNotFoundError(err error) bool
- func JSONBytesEqual(b1, b2 []byte) bool
- func ListOfSetsToStringSlice(listSet []interface{}) [][]string
- func ListToIntSlice[T int | int64](src []interface{}) []T
- func ListToStringSlice(src []interface{}) []string
- func Ref[T any](v T) *T
- func SchemaDiffFloat32(k, old string, nw string, d *schema.ResourceData) bool
- func SetToIntSlice[T int | int64](src *schema.Set) []T
- func SetToStringSlice(src *schema.Set) []string
- func StringSliceToList(list []string) []interface{}
- func StringSliceToSet(src []string) *schema.Set
- func SuppressEquivalentJSONDiffs(k, old, new string, d *schema.ResourceData) bool
- func UnpackMap[T any](m interface{}) map[string]T
- func ValidateDuration(i interface{}, p cty.Path) diag.Diagnostics
- func ValidateDurationWithDays(i interface{}, p cty.Path) diag.Diagnostics
- func WarnMissing(resourceType string, d *schema.ResourceData) diag.Diagnostics
- func WithAlertingMutex[...](f T) T
- type Client
- type DataSource
- type Resource
- type ResourceCategory
- type ResourceCommon
- type ResourceID
- type ResourceIDField
- type ResourceIDFieldType
- type ResourceListIDsFunc
Constants ¶
const ( ResourceIDSeparator = ":" ResourceIDFieldTypeInt = ResourceIDFieldType("int") ResourceIDFieldTypeString = ResourceIDFieldType("string") )
const NotFoundError = "404"
Variables ¶
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 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 ComputedInt ¶
func ComputedString ¶
func Int32SliceToIntList ¶
func Int32SliceToIntList(list []int32) []interface{}
func Int32SliceToSet ¶
func IsNotFoundError ¶
func JSONBytesEqual ¶
func ListOfSetsToStringSlice ¶
func ListOfSetsToStringSlice(listSet []interface{}) [][]string
func ListToIntSlice ¶
func ListToStringSlice ¶
func ListToStringSlice(src []interface{}) []string
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 SetToStringSlice ¶
func StringSliceToList ¶
func StringSliceToList(list []string) []interface{}
func StringSliceToSet ¶
func SuppressEquivalentJSONDiffs ¶
func SuppressEquivalentJSONDiffs(k, old, new string, d *schema.ResourceData) bool
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 ¶
func WithAlertingMutex[T schema.CreateContextFunc | schema.ReadContextFunc | schema.UpdateContextFunc | schema.DeleteContextFunc](f T) T
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 ¶
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 (*Resource) WithLister ¶
func (r *Resource) WithLister(lister ResourceListIDsFunc) *Resource
func (*Resource) WithPreferredResourceNameField ¶ added in v3.8.0
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
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 ¶
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.