framework

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2024 License: BSD-3-Clause Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const (
	READINESS_TIMEOUT = 5 * time.Minute
	DELETION_TIMEOUT  = 1 * time.Minute
	POLLING_INTERVAL  = 1 * time.Second
	DEFAULT_RESOURCE  = "default"
	CREATE_OPERATION  = "create"
	UPDATE_OPERATION  = "update"
	DELETE_OPERATION  = "delete"
)
View Source
const (
	ALLOW_DESTRUCTIVE_REPLACE_VAR      = "NUODB_CP_ALLOW_DESTRUCTIVE_REPLACE"
	IMMUTABLE_ATTRIBUTE_CHANGE_ERR_FMT = "A change has been made to the immutable attribute `%s`, which may be rejected by the server or ignored. " +
		"In order for an immutable attribute change to take effect, it is necessary to delete and re-create the resource, which may result in data loss.\n\n" +
		"If it is acceptable to destroy all data associated with the resource, then deletion and re-creation can be enabled by setting the environment variable `" + ALLOW_DESTRUCTIVE_REPLACE_VAR + "=true` when running `terraform apply`:\n\n" +
		"    " + ALLOW_DESTRUCTIVE_REPLACE_VAR + "=true terraform apply\n\n" +
		"If the resource has dependent resources, it may be necessary to explicitly delete and re-create the resource and its dependent resources by running the following:\n\n" +
		"    terraform destroy -target=<resource>\n    terraform apply\n\n" +
		"If it is not acceptable to destroy all data associated with the resource, the configured value of the attribute can be reverted to the value in the Terraform state (`%s`)."
)
View Source
const (
	LABEL_FILTER_DESCRIPTION = "List of filters to apply based on labels, which are composed using `AND`. Acceptable filter expressions are:\n" +
		"  * `key` - Only return items that have label with specified key\n" +
		"  * `key=value` - Only return items that have label with specified key set to value\n" +
		"  * `!key` - Only return items that do _not_ have label with specified key\n" +
		"  * `key!=value` - Only return items that do _not_ have label with specified key set to value"
)

Variables

This section is empty.

Functions

func GetAttributeName

func GetAttributeName(oas *openapi3.Schema) string

func GetDataSourceAttributes added in v1.1.0

func GetDataSourceAttributes(name string) (map[string]datasource.Attribute, error)

func GetResourceAttributes added in v1.1.0

func GetResourceAttributes(name string) (map[string]resource.Attribute, error)

func GetSchema

func GetSchema(name string) (*openapi3.Schema, error)

func GetStringValidators added in v1.1.0

func GetStringValidators(oas *openapi3.Schema) []validator.String

func GetTerraformType

func GetTerraformType(schemaRef *openapi3.SchemaRef) attr.Type

func IsExtensionSet

func IsExtensionSet(oas *openapi3.Schema, key string) bool

func IsIdentifierAttribute

func IsIdentifierAttribute(oas *openapi3.Schema) bool

func IsImmutableAttribute

func IsImmutableAttribute(oas *openapi3.Schema) bool

func IsSensitiveAttribute

func IsSensitiveAttribute(oas *openapi3.Schema) bool

func ParseTimeouts added in v1.0.0

func ParseTimeouts(timeouts map[string]OperationTimeouts, resourceTypes map[string]struct{}) (map[string]map[string]time.Duration, error)

func ReadResource

func ReadResource(ctx context.Context, diags *diag.Diagnostics, fn func(context.Context, any) diag.Diagnostics, dest any) bool

ReadResource decodes Terraform configuration, state, or plan to a model struct containing ordinary Golang field types (e.g. bool, *int, []string) that have the `tfsdk:"..."` tag.

func ToDataSourceAttribute

func ToDataSourceAttribute(oas *openapi3.Schema) (string, datasource.Attribute)

func ToDataSourceSchema

func ToDataSourceSchema(oas *openapi3.Schema) map[string]datasource.Attribute

func ToResourceAttribute

func ToResourceAttribute(oas *openapi3.Schema, required, readOnly bool) (string, resource.Attribute)

func ToResourceSchema

func ToResourceSchema(oas *openapi3.Schema, readOnly bool) map[string]resource.Attribute

Types

type AttributeBuilder

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

func (*AttributeBuilder) WithComputedStringAttribute

func (ab *AttributeBuilder) WithComputedStringAttribute(name, description string) *AttributeBuilder

func (*AttributeBuilder) WithNameAttribute

func (ab *AttributeBuilder) WithNameAttribute(typeName string) *AttributeBuilder

func (*AttributeBuilder) WithNewListNestedAttribute

func (ab *AttributeBuilder) WithNewListNestedAttribute(name, description string) *AttributeBuilder

func (*AttributeBuilder) WithNewNestedAttribute

func (ab *AttributeBuilder) WithNewNestedAttribute(name, description string) *AttributeBuilder

func (*AttributeBuilder) WithOptionalStringAttribute

func (ab *AttributeBuilder) WithOptionalStringAttribute(name, description string) *AttributeBuilder

func (*AttributeBuilder) WithStringAttribute

func (ab *AttributeBuilder) WithStringAttribute(name, description string, optional bool) *AttributeBuilder

func (*AttributeBuilder) WithStringListAttribute

func (ab *AttributeBuilder) WithStringListAttribute(name, description string) *AttributeBuilder

type ClientWithOptions added in v1.0.0

type ClientWithOptions struct {
	Client openapi.ClientInterface
	// contains filtered or unexported fields
}

func NewClientWithOptions added in v1.0.0

func NewClientWithOptions(client openapi.ClientInterface, timeouts map[string]map[string]time.Duration) *ClientWithOptions

type DataSourceState

type DataSourceState interface {
	State

	// Read retrieves the state of the resource from the backend.
	Read(ctx context.Context, client openapi.ClientInterface) error
}

DataSourceState handles interactions with the provider API.

type GenericDataSource

type GenericDataSource struct {
	TypeName                string
	Description             string
	GetDataSourceAttributes func() (map[string]schema.Attribute, error)
	SchemaOverride          *schema.Schema
	Build                   func() DataSourceState
	// contains filtered or unexported fields
}

GenericDataSource is a DataSource implementation that handles all interactions with the Terraform API and delegates interaction with the provider API to DataSourceState.

func (*GenericDataSource) Configure

func (*GenericDataSource) Metadata

func (*GenericDataSource) Read

func (*GenericDataSource) Schema

type GenericPlanModifier

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

GenericPlanModifier is a plan modifier implementation that can be applied to any type.

func RequiresReplace

func RequiresReplace() *GenericPlanModifier

func UseStateForUnknown

func UseStateForUnknown() *GenericPlanModifier

func (GenericPlanModifier) Description

func (m GenericPlanModifier) Description(_ context.Context) string

Description returns a human-readable description of the plan modifier.

func (GenericPlanModifier) MarkdownDescription

func (m GenericPlanModifier) MarkdownDescription(_ context.Context) string

MarkdownDescription returns a markdown description of the plan modifier.

func (GenericPlanModifier) PlanModifyBool

PlanModifyBool implements the plan modification logic.

func (GenericPlanModifier) PlanModifyFloat64

PlanModifyFloat64 implements the plan modification logic.

func (GenericPlanModifier) PlanModifyInt64

PlanModifyInt64 implements the plan modification logic.

func (GenericPlanModifier) PlanModifyList

PlanModifyList implements the plan modification logic.

func (GenericPlanModifier) PlanModifyMap

PlanModifyMap implements the plan modification logic.

func (GenericPlanModifier) PlanModifyNumber

PlanModifyNumber implements the plan modification logic.

func (GenericPlanModifier) PlanModifyObject

PlanModifyObject implements the plan modification logic.

func (GenericPlanModifier) PlanModifyString

PlanModifyString implements the plan modification logic.

type GenericRequest

type GenericRequest struct {
	// Path contains the path of the attribute for modification. Use this path
	// for any response diagnostics.
	Path path.Path

	// Config contains the entire configuration of the resource.
	Config tfsdk.Config

	// ConfigValue contains the value of the attribute for modification from the configuration.
	ConfigValue attr.Value

	// Plan contains the entire proposed new state of the resource.
	Plan tfsdk.Plan

	// PlanValue contains the value of the attribute for modification from the proposed new state.
	PlanValue attr.Value

	// State contains the entire prior state of the resource.
	State tfsdk.State

	// StateValue contains the value of the attribute for modification from the prior state.
	StateValue attr.Value
}

GenericRequest is a request for plan modification that uses attr.Value instead of specific type of the attribute to enable code reuse across types.

type GenericResource

type GenericResource struct {
	TypeName              string
	Description           string
	GetResourceAttributes func() (map[string]schema.Attribute, error)
	Build                 func() ResourceState
	// contains filtered or unexported fields
}

GenericResource is a Resource implementation that handles all interactions with the Terraform API and delegates interaction with the provider API to ResourceState.

func (*GenericResource) AwaitDeleted

func (r *GenericResource) AwaitDeleted(ctx context.Context, state ResourceState) error

func (*GenericResource) AwaitReady

func (r *GenericResource) AwaitReady(ctx context.Context, state ResourceState, operation string) error

func (*GenericResource) Configure

func (*GenericResource) Create

func (*GenericResource) Delete

func (*GenericResource) GetTimeout added in v1.0.0

func (r *GenericResource) GetTimeout(operation string, defaultTimeout time.Duration) time.Duration

func (*GenericResource) ImportState

func (*GenericResource) Metadata

func (*GenericResource) Read

func (*GenericResource) Schema

func (*GenericResource) Update

type GenericResponse

type GenericResponse struct {
	// PlanValue is the planned new state for the attribute.
	PlanValue attr.Value

	// RequiresReplace indicates whether a change in the attribute
	// requires replacement of the whole resource.
	RequiresReplace bool

	// Diagnostics report errors or warnings related to validating the data
	// source configuration. An empty slice indicates success, with no warnings
	// or errors generated.
	Diagnostics *diag.Diagnostics
}

GenericResponse is a response to a GenericRequest.

type OperationTimeouts added in v1.0.0

type OperationTimeouts struct {
	Create *string `tfsdk:"create" hcl:"create" cty:"create"`
	Update *string `tfsdk:"update" hcl:"update" cty:"update"`
	Delete *string `tfsdk:"delete" hcl:"delete" cty:"delete"`
}

type ResourceState

type ResourceState interface {
	State

	// Reset resets the local state of the resource to the zero value.
	Reset()

	// CheckReady returns an error if the resource is not in the desired
	// state according to its spec, based on the local state. The supplied
	// client can be used to request additional readiness information from
	// the server.
	CheckReady(ctx context.Context, client openapi.ClientInterface) error

	// Create creates the resource in the backend based on the local state
	// and waits for it to satisfy IsReady().
	Create(ctx context.Context, client openapi.ClientInterface) error

	// Read retrieves the state of the resource from the backend.
	Read(ctx context.Context, client openapi.ClientInterface) error

	// Update updates the resource in the backend to match the local state
	// and waits for it to satisfy IsReady().
	Update(ctx context.Context, client openapi.ClientInterface, currentState ResourceState) error

	// Delete deletes the resource from the backend and waits for it to be
	// cleaned up.
	Delete(ctx context.Context, client openapi.ClientInterface) error

	// Deserialize the resource ID
	SetId(id string) error
}

ResourceState handles interactions with the provider API.

type SchemaBuilder

type SchemaBuilder struct {
	AttributeBuilder
	// contains filtered or unexported fields
}

func NewSchemaBuilder

func NewSchemaBuilder() *SchemaBuilder

func (*SchemaBuilder) Build

func (sb *SchemaBuilder) Build() *schema.Schema

func (*SchemaBuilder) WithDescription

func (sb *SchemaBuilder) WithDescription(description string) *SchemaBuilder

func (*SchemaBuilder) WithOrganizationScopeFilters

func (sb *SchemaBuilder) WithOrganizationScopeFilters(typeNamePlural string) *AttributeBuilder

WithOrganizationScopeFilters attaches common attributes for the filter nested attribute of an organization-scoped resource in DBaaS.

func (*SchemaBuilder) WithOrganizationScopeList

func (sb *SchemaBuilder) WithOrganizationScopeList(typeName, typeNamePlural string) *AttributeBuilder

WithOrganizationScopeList attaches schema information for the list attribute of the supplied type, which is organization-scoped (e.g. projects).

func (*SchemaBuilder) WithProjectScopeFilters

func (sb *SchemaBuilder) WithProjectScopeFilters(typeNamePlural string) *AttributeBuilder

WithProjectScopeFilters attaches schema information for the filter nested attribute of a project-scoped resource in DBaaS.

func (*SchemaBuilder) WithProjectScopeList

func (sb *SchemaBuilder) WithProjectScopeList(typeName, typeNamePlural string) *AttributeBuilder

WithProjectScopeList attaches schema information for the list attribute of the supplied type, which is project-scoped (e.g. databases).

type State

type State interface{}

State is a marker interface for all structs that model Terraform resources and data sources.

Jump to

Keyboard shortcuts

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