config

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2024 License: Apache-2.0 Imports: 28 Imported by: 513

Documentation

Index

Constants

View Source
const (
	// PackageNameConfig is the name of the provider subpackage that contains
	// the base resources (e.g., ProviderConfig, ProviderConfigUsage,
	// StoreConfig. etc.).
	// TODO: we should be careful that there may also exist short groups with
	// these names. We can consider making these configurable by the provider
	// maintainer.
	PackageNameConfig = "config"
	// PackageNameMonolith is the name of the backwards-compatible
	// provider subpackage that contains the all the resources.
	PackageNameMonolith = "monolith"
)

Variables

View Source
var (
	DefaultBasePackages = BasePackages{
		APIVersion: []string{

			"apis/v1alpha1",
			"apis/v1beta1",
		},

		Controller: []string{

			"internal/controller/providerconfig",
		},
		ControllerMap: map[string]string{

			"internal/controller/providerconfig": PackageNameConfig,
		},
	}

	// NopSensitive does nothing.
	NopSensitive = Sensitive{
		AdditionalConnectionDetailsFn: NopAdditionalConnectionDetails,
	}
)

Commonly used resource configurations.

View Source
var (
	// NameAsIdentifier uses "name" field in the arguments as the identifier of
	// the resource.
	NameAsIdentifier = ExternalName{
		SetIdentifierArgumentFn: func(base map[string]any, name string) {
			base["name"] = name
		},
		GetExternalNameFn: IDAsExternalName,
		GetIDFn:           ExternalNameAsID,
		OmittedFields: []string{
			"name",
			"name_prefix",
		},
	}

	// IdentifierFromProvider is used in resources whose identifier is assigned by
	// the remote client, such as AWS VPC where it gets an identifier like
	// vpc-2213das instead of letting user choose a name.
	IdentifierFromProvider = ExternalName{
		SetIdentifierArgumentFn: NopSetIdentifierArgument,
		GetExternalNameFn:       IDAsExternalName,
		GetIDFn:                 ExternalNameAsID,
		DisableNameInitializer:  true,
	}
)

Functions

func GetExternalNameFromTemplated

func GetExternalNameFromTemplated(tmpl, val string) (string, error)

GetExternalNameFromTemplated takes a Terraform ID and the template it's produced from and reverse it to get the external name. For example, you can supply "/subscription/{{ .paramters.some }}/{{ .external_name }}" with "/subscription/someval/myname" and get "myname" returned.

func GetSchema

func GetSchema(sch *schema.Resource, fieldpath string) *schema.Schema

GetSchema returns the schema of the field whose fieldpath is given. Returns nil if Schema is not found at the specified path.

func ManipulateEveryField

func ManipulateEveryField(r *schema.Resource, op func(sch *schema.Schema))

ManipulateEveryField manipulates all fields in the schema by input function.

func MarkAsRequired

func MarkAsRequired(sch *schema.Resource, fieldpaths ...string)

MarkAsRequired marks the schema of the given fieldpath as required. It's most useful in cases where external name contains an optional parameter that is defaulted by the provider but we need it to exist or to fix plain buggy schemas. Deprecated: Use Resource.MarkAsRequired instead. This function will be removed in future versions.

func MoveToStatus

func MoveToStatus(sch *schema.Resource, fieldpaths ...string)

MoveToStatus moves given fields and their leaf fields to the status as a whole. It's used mostly in cases where there is a field that is represented as a separate CRD, hence you'd like to remove that field from spec.

Types

type AdditionalConnectionDetailsFn

type AdditionalConnectionDetailsFn func(attr map[string]any) (map[string][]byte, error)

AdditionalConnectionDetailsFn functions adds custom keys to connection details secret using input terraform attributes

var NopAdditionalConnectionDetails AdditionalConnectionDetailsFn = func(_ map[string]any) (map[string][]byte, error) {
	return nil, nil
}

NopAdditionalConnectionDetails does nothing, when no additional connection details configuration function provided.

type BasePackages

type BasePackages struct {
	APIVersion []string
	// Deprecated: Use ControllerMap instead.
	Controller    []string
	ControllerMap map[string]string
}

BasePackages keeps lists of packages that needs to be registered as API and controllers. Typically, we expect to see ProviderConfig packages here. These APIs and controllers belong to non-generated (manually maintained) resources.

type ConfigurationInjector

type ConfigurationInjector func(jsonMap map[string]any, tfMap map[string]any) error

ConfigurationInjector is a function that injects Terraform configuration values from the specified managed resource into the specified configuration map. jsonMap is the map obtained by converting the `spec.forProvider` using the JSON tags and tfMap is obtained by using the TF tags.

func CanonicalizeJSONParameters added in v1.1.1

func CanonicalizeJSONParameters(tfPath ...string) ConfigurationInjector

CanonicalizeJSONParameters returns a ConfigurationInjector that computes and stores the canonical forms of the JSON documents for the specified list of top-level Terraform configuration arguments. Please note that currently only top-level configuration arguments are supported by this function.

type CustomDiff

CustomDiff customizes the computed Terraform InstanceDiff. This can be used in cases where, for example, changes in a certain argument should just be dismissed. The new InstanceDiff is returned along with any errors.

type ExternalName

type ExternalName struct {
	// SetIdentifierArgumentFn sets the name of the resource in Terraform argument
	// map. In many cases, there is a field called "name" in the HCL schema, however,
	// there are cases like RDS DB Cluster where the name field in HCL is called
	// "cluster_identifier". This function is the place that you can take external
	// name and assign it to that specific key for that resource type.
	SetIdentifierArgumentFn SetIdentifierArgumentsFn

	// GetExternalNameFn returns the external name extracted from TF State. In most cases,
	// "id" field contains all the information you need. You'll need to extract
	// the format that is decided for external name annotation to use.
	// For example the following is an Azure resource ID:
	// /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/mygroup1
	// The function should return "mygroup1" so that it can be used to set external
	// name if it was not set already.
	GetExternalNameFn GetExternalNameFn

	// GetIDFn returns the string that will be used as "id" key in TF state. In
	// many cases, external name format is the same as "id" but when it is not
	// we may need information from other places to construct it. For example,
	// the following is an Azure resource ID:
	// /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/mygroup1
	// The function here should use information from supplied arguments to
	// construct this ID, i.e. "mygroup1" from external name, subscription ID
	// from terraformProviderConfig, and others from parameters map if needed.
	GetIDFn GetIDFn

	// OmittedFields are the ones you'd like to be removed from the schema since
	// they are specified via external name. For example, if you set
	// "cluster_identifier" in SetIdentifierArgumentFn, then you need to omit
	// that field.
	// You can omit only the top level fields.
	// No field is omitted by default.
	OmittedFields []string

	// DisableNameInitializer allows you to specify whether the name initializer
	// that sets external name to metadata.name if none specified should be disabled.
	// It needs to be disabled for resources whose external identifier is randomly
	// assigned by the provider, like AWS VPC where it gets vpc-21kn123 identifier
	// and not let you name it.
	DisableNameInitializer bool

	// IdentifierFields are the fields that are used to construct external
	// resource identifier. We need to know these fields no matter what the
	// management policy is including the Observe Only, different from other
	// (required) fields.
	IdentifierFields []string
}

ExternalName contains all information that is necessary for naming operations, such as removal of those fields from spec schema and calling Configure function to fill attributes with information given in external name.

func NewExternalNameFrom added in v1.1.1

func NewExternalNameFrom(parent ExternalName, opts ...ExternalNameFromOption) ExternalName

NewExternalNameFrom initializes a new ExternalNameFrom with the given parent and with the given options. An example configuration that uses a TemplatedStringAsIdentifier as its parent (base) and sets a default value for the external-name if the external-name is yet not populated is as follows:

config.NewExternalNameFrom(config.TemplatedStringAsIdentifier("", "{{ .parameters.type }}/{{ .setup.client_metadata.account_id }}/{{ .external_name }}"),

config.WithGetIDFn(func(fn config.GetIDFn, ctx context.Context, externalName string, parameters map[string]any, terraformProviderConfig map[string]any) (string, error) {
	if externalName == "" {
		externalName = "some random string"
	}
	return fn(ctx, externalName, parameters, terraformProviderConfig)
}))

func ParameterAsIdentifier

func ParameterAsIdentifier(param string) ExternalName

ParameterAsIdentifier uses the given field name in the arguments as the identifier of the resource.

func TemplatedStringAsIdentifier

func TemplatedStringAsIdentifier(nameFieldPath, tmpl string) ExternalName

TemplatedStringAsIdentifier accepts a template as the shape of the Terraform ID and lets you provide a field path for the argument you're using as external name. The available variables you can use in the template are as follows:

parameters: A tree of parameters that you'd normally see in a Terraform HCL file. You can use TF registry documentation of given resource to see what's available.

setup.configuration: The Terraform configuration object of the provider. You can take a look at the TF registry provider configuration object to see what's available. Not to be confused with ProviderConfig custom resource of the Crossplane provider.

setup.client_metadata: The Terraform client metadata available for the provider, such as the AWS account ID for the AWS provider.

external_name: The value of external name annotation of the custom resource. It is required to use this as part of the template.

The following template functions are available:

ToLower: Converts the contents of the pipeline to lower-case

ToUpper: Converts the contents of the pipeline to upper-case

Please note that it's currently *not* possible to use the template functions on the .external_name template variable. Example usages:

TemplatedStringAsIdentifier("index_name", "/subscriptions/{{ .setup.configuration.subscription }}/{{ .external_name }}")

TemplatedStringAsIdentifier("index_name", "/resource/{{ .external_name }}/static")

TemplatedStringAsIdentifier("index_name", "{{ .parameters.cluster_id }}:{{ .parameters.node_id }}:{{ .external_name }}")

TemplatedStringAsIdentifier("", "arn:aws:network-firewall:{{ .setup.configuration.region }}:{{ .setup.client_metadata.account_id }}:{{ .parameters.type | ToLower }}-rulegroup/{{ .external_name }}")

type ExternalNameFrom added in v1.1.1

type ExternalNameFrom struct {
	ExternalName
	// contains filtered or unexported fields
}

ExternalNameFrom is an ExternalName configuration which uses a parent configuration as its base and modifies any of the GetIDFn, GetExternalNameFn or SetIdentifierArgumentsFn. This enables us to reuse the existing ExternalName configurations with modifications in their behaviors via compositions.

type ExternalNameFromOption added in v1.1.1

type ExternalNameFromOption func(from *ExternalNameFrom)

ExternalNameFromOption is an option that modifies the behavior of an ExternalNameFrom external-name configuration.

func WithGetExternalNameFn added in v1.1.1

func WithGetExternalNameFn(fn func(fn GetExternalNameFn, tfstate map[string]any) (string, error)) ExternalNameFromOption

WithGetExternalNameFn sets the GetExternalNameFn for the ExternalNameFrom configuration. The function parameter fn receives the parent ExternalName's GetExternalNameFn, and implementations may invoke the parent's GetExternalNameFn via this parameter. For the description of the rest of the parameters and return values, please see the documentation of GetExternalNameFn.

func WithGetIDFn added in v1.1.1

func WithGetIDFn(fn func(fn GetIDFn, ctx context.Context, externalName string, parameters map[string]any, terraformProviderConfig map[string]any) (string, error)) ExternalNameFromOption

WithGetIDFn sets the GetIDFn for the ExternalNameFrom configuration. The function parameter fn receives the parent ExternalName's GetIDFn, and implementations may invoke the parent's GetIDFn via this parameter. For the description of the rest of the parameters and return values, please see the documentation of GetIDFn.

func WithSetIdentifierArgumentsFn added in v1.1.1

func WithSetIdentifierArgumentsFn(fn func(fn SetIdentifierArgumentsFn, base map[string]any, externalName string)) ExternalNameFromOption

WithSetIdentifierArgumentsFn sets the SetIdentifierArgumentsFn for the ExternalNameFrom configuration. The function parameter fn receives the parent ExternalName's SetIdentifierArgumentsFn, and implementations may invoke the parent's SetIdentifierArgumentsFn via this parameter. For the description of the rest of the parameters and return values, please see the documentation of SetIdentifierArgumentsFn.

type GetExternalNameFn

type GetExternalNameFn func(tfstate map[string]any) (string, error)

GetExternalNameFn returns the external name extracted from the TF State.

var IDAsExternalName GetExternalNameFn = func(tfstate map[string]any) (string, error) {
	if id, ok := tfstate["id"].(string); ok && id != "" {
		return id, nil
	}
	return "", errors.New("cannot find id in tfstate")
}

IDAsExternalName returns the TF State ID as external name.

type GetIDFn

type GetIDFn func(ctx context.Context, externalName string, parameters map[string]any, terraformProviderConfig map[string]any) (string, error)

GetIDFn returns the ID to be used in TF State file, i.e. "id" field in terraform.tfstate.

var ExternalNameAsID GetIDFn = func(_ context.Context, externalName string, _ map[string]any, _ map[string]any) (string, error) {
	return externalName, nil
}

ExternalNameAsID returns the name to be used as ID in TF State file.

type InjectedKey added in v1.1.0

type InjectedKey struct {
	Key          string
	DefaultValue string
}

type LateInitializer

type LateInitializer struct {
	// IgnoredFields are the field paths to be skipped during
	// late-initialization. Similar to other configurations, these paths are
	// Terraform field paths concatenated with dots. For example, if we want to
	// ignore "ebs" block in "aws_launch_template", we should add
	// "block_device_mappings.ebs".
	IgnoredFields []string
	// contains filtered or unexported fields
}

LateInitializer represents configurations that control late-initialization behaviour

func (*LateInitializer) AddIgnoredCanonicalFields

func (l *LateInitializer) AddIgnoredCanonicalFields(cf string)

AddIgnoredCanonicalFields sets ignored canonical fields

func (*LateInitializer) GetIgnoredCanonicalFields

func (l *LateInitializer) GetIgnoredCanonicalFields() []string

GetIgnoredCanonicalFields returns the ignoredCanonicalFields

type ListMapKeys added in v1.1.0

type ListMapKeys struct {
	// InjectedKey can be used to inject the specified index key
	// into the generated CRD schema for the list object when
	// the SSA merge strategy for the parent list is `map`.
	// If a non-zero `InjectedKey` is specified, then a field of type string with
	// the specified name is injected into the Terraform schema and used as
	// a list map key together with any other existing keys specified in `Keys`.
	InjectedKey InjectedKey
	// Keys is the set of list map keys to be used while SSA merges list items.
	// If InjectedKey is non-zero, then it's automatically put into Keys and
	// you must not specify the InjectedKey in Keys explicitly.
	Keys []string
}

ListMapKeys is the list map keys when the server-side apply merge strategy islistType=map.

type ListMergeStrategy added in v1.1.0

type ListMergeStrategy struct {
	// ListMapKeys is the list map keys when the SSA merge strategy is
	// `listType=map`.  The keys specified here must be a set of scalar Terraform
	// argument names to be used as the list map keys for the object list.
	ListMapKeys ListMapKeys
	// MergeStrategy is the SSA merge strategy for an object list. Valid values
	// are: `atomic`, `set` and `map`
	MergeStrategy ListType
}

ListMergeStrategy configures the corresponding field as list and configures its server-side apply merge strategy.

type ListType added in v1.1.0

type ListType string

A ListType is a type of list.

const (
	// ListTypeAtomic means the entire list is replaced during merge. At any
	// point in time, a single manager owns the list.
	ListTypeAtomic ListType = "atomic"

	// ListTypeSet can be granularly merged, and different managers can own
	// different elements in the list. The list can include only scalar
	// elements.
	ListTypeSet ListType = "set"

	// ListTypeMap can be granularly merged, and different managers can own
	// different elements in the list. The list can include only nested types
	// (i.e. objects).
	ListTypeMap ListType = "map"
)

Types of lists.

type MapType added in v1.1.0

type MapType string

A MapType is a type of map.

const (
	// MapTypeAtomic means that the map can only be entirely replaced by a
	// single manager.
	MapTypeAtomic MapType = "atomic"

	// MapTypeGranular means that the map supports separate managers updating
	// individual fields.
	MapTypeGranular MapType = "granular"
)

Types of maps.

type MergeStrategy added in v1.1.0

type MergeStrategy struct {
	ListMergeStrategy   ListMergeStrategy
	MapMergeStrategy    MapType
	StructMergeStrategy StructType
}

MergeStrategy configures the server-side apply merge strategy for the corresponding field. One and only one of the pointer members can be set and the specified merge strategy configuration must match the field's type, e.g., you cannot set MapMergeStrategy for a field of type list.

type NewInitializerFn

type NewInitializerFn func(client client.Client) managed.Initializer

NewInitializerFn returns the Initializer with a client.

var TagInitializer NewInitializerFn = func(client client.Client) managed.Initializer {
	return NewTagger(client, "tags")
}

TagInitializer returns a tagger to use default tag initializer.

type OperationTimeouts

type OperationTimeouts struct {
	Read   time.Duration
	Create time.Duration
	Update time.Duration
	Delete time.Duration
}

OperationTimeouts allows configuring resource operation timeouts: https://www.terraform.io/language/resources/syntax#operation-timeouts Please note that, not all resources support configuring timeouts.

type Provider

type Provider struct {
	// TerraformResourcePrefix is the prefix used in all resources of this
	// Terraform provider, e.g. "aws_". Defaults to "<prefix>_". This is being
	// used while setting some defaults like Kind of the resource. For example,
	// for "aws_rds_cluster", we drop "aws_" prefix and its group ("rds") to set
	// Kind of the resource as "Cluster".
	TerraformResourcePrefix string

	// RootGroup is the root group that all CRDs groups in the provider are based
	// on, e.g. "aws.upbound.io".
	// Defaults to "<TerraformResourcePrefix>.upbound.io".
	RootGroup string

	// ShortName is the short name of the provider. Typically, added as a CRD
	// category, e.g. "awsjet". Default to "<prefix>jet". For more details on CRD
	// categories, see: https://kubernetes.io/docs/tasks/extend-kubernetes/custom-resources/custom-resource-definitions/#categories
	ShortName string

	// ModulePath is the go module path for the Crossplane provider repo, e.g.
	// "github.com/upbound/provider-aws"
	ModulePath string

	// FeaturesPackage is the relative package patch for the features package to
	// configure the features behind the feature gates.
	FeaturesPackage string

	// BasePackages keeps lists of base packages that needs to be registered as
	// API and controllers. Typically, we expect to see ProviderConfig packages
	// here.
	BasePackages BasePackages

	// DefaultResourceOptions is a list of config.ResourceOption that will be
	// applied to all resources before any user-provided options are applied.
	DefaultResourceOptions []ResourceOption

	// SkipList is a list of regex for the Terraform resources to be skipped.
	// For example, to skip generation of "aws_shield_protection_group", one
	// can add "aws_shield_protection_group$". To skip whole aws waf group, one
	// can add "aws_waf.*" to the list.
	SkipList []string

	// MainTemplate is the template string to be used to render the
	// provider subpackage main program. If this is set, the generated provider
	// is broken up into subpackage families partitioned across the API groups.
	// A monolithic provider is also generated to
	// ensure backwards-compatibility.
	MainTemplate string

	// IncludeList is a list of regex for the Terraform resources to be
	// included and reconciled via the Terraform CLI.
	// For example, to include "aws_shield_protection_group" into
	// the generated resources, one can add "aws_shield_protection_group$".
	// To include whole aws waf group, one can add "aws_waf.*" to the list.
	// Defaults to []string{".+"} which would include all resources.
	IncludeList []string

	// TerraformPluginSDKIncludeList is a list of regex for the Terraform resources
	// implemented with Terraform Plugin SDKv2 to be included and reconciled
	// in the no-fork architecture (without the Terraform CLI).
	// For example, to include "aws_shield_protection_group" into
	// the generated resources, one can add "aws_shield_protection_group$".
	// To include whole aws waf group, one can add "aws_waf.*" to the list.
	// Defaults to []string{".+"} which would include all resources.
	TerraformPluginSDKIncludeList []string

	// TerraformPluginFrameworkIncludeList is a list of regex for the Terraform
	// resources implemented with Terraform Plugin Framework  to be included and
	// reconciled in the no-fork architecture (without the Terraform CLI).
	// For example, to include "aws_shield_protection_group" into
	// the generated resources, one can add "aws_shield_protection_group$".
	// To include whole aws waf group, one can add "aws_waf.*" to the list.
	// Defaults to []string{".+"} which would include all resources.
	TerraformPluginFrameworkIncludeList []string

	// Resources is a map holding resource configurations where key is Terraform
	// resource name.
	Resources map[string]*Resource

	// TerraformProvider is the Terraform provider in Terraform Plugin SDKv2
	// compatible format
	TerraformProvider *schema.Provider

	// TerraformPluginFrameworkProvider is the Terraform provider reference
	// in Terraform Plugin Framework compatible format
	TerraformPluginFrameworkProvider fwprovider.Provider
	// contains filtered or unexported fields
}

Provider holds configuration for a provider to be generated with Upjet.

func NewProvider

func NewProvider(schema []byte, prefix string, modulePath string, metadata []byte, opts ...ProviderOption) *Provider

NewProvider builds and returns a new Provider from provider tfjson schema, that is generated using Terraform CLI with: `terraform providers schema --json`

func (*Provider) AddResourceConfigurator

func (p *Provider) AddResourceConfigurator(resource string, c ResourceConfiguratorFn)

AddResourceConfigurator adds resource specific configurators.

func (*Provider) ConfigureResources

func (p *Provider) ConfigureResources()

ConfigureResources configures resources with provided ResourceConfigurator's

func (*Provider) GetSkippedResourceNames

func (p *Provider) GetSkippedResourceNames() []string

GetSkippedResourceNames returns a list of Terraform resource names available in the Terraform provider schema, but not in the include list or in the skip list, meaning that the corresponding managed resources are not generated.

func (*Provider) SetResourceConfigurator

func (p *Provider) SetResourceConfigurator(resource string, c ResourceConfigurator)

SetResourceConfigurator sets ResourceConfigurator for a resource. This will override all previously added ResourceConfigurators for this resource.

type ProviderOption

type ProviderOption func(*Provider)

A ProviderOption configures a Provider.

func WithBasePackages

func WithBasePackages(b BasePackages) ProviderOption

WithBasePackages configures BasePackages for this Provider.

func WithDefaultResourceOptions

func WithDefaultResourceOptions(opts ...ResourceOption) ProviderOption

WithDefaultResourceOptions configures DefaultResourceOptions for this Provider.

func WithFeaturesPackage

func WithFeaturesPackage(s string) ProviderOption

WithFeaturesPackage configures FeaturesPackage for this Provider.

func WithIncludeList

func WithIncludeList(l []string) ProviderOption

WithIncludeList configures IncludeList for this Provider.

func WithMainTemplate

func WithMainTemplate(template string) ProviderOption

func WithReferenceInjectors

func WithReferenceInjectors(refInjectors []ReferenceInjector) ProviderOption

WithReferenceInjectors configures an ordered list of `ReferenceInjector`s for this Provider. The configured reference resolvers are executed in order to inject cross-resource references across this Provider's resources.

func WithRootGroup

func WithRootGroup(s string) ProviderOption

WithRootGroup configures RootGroup for resources of this Provider.

func WithShortName

func WithShortName(s string) ProviderOption

WithShortName configures ShortName for resources of this Provider.

func WithSkipList

func WithSkipList(l []string) ProviderOption

WithSkipList configures SkipList for this Provider.

func WithTerraformPluginFrameworkIncludeList added in v1.1.0

func WithTerraformPluginFrameworkIncludeList(l []string) ProviderOption

WithTerraformPluginFrameworkIncludeList configures the TerraformPluginFrameworkIncludeList for this Provider, with the given Terraform Plugin Framework-based resource name list

func WithTerraformPluginFrameworkProvider added in v1.1.0

func WithTerraformPluginFrameworkProvider(tp fwprovider.Provider) ProviderOption

WithTerraformPluginFrameworkProvider configures the TerraformPluginFrameworkProvider for this Provider.

func WithTerraformPluginSDKIncludeList added in v1.1.0

func WithTerraformPluginSDKIncludeList(l []string) ProviderOption

WithTerraformPluginSDKIncludeList configures the TerraformPluginSDKIncludeList for this Provider, with the given Terraform Plugin SDKv2-based resource name list

func WithTerraformProvider

func WithTerraformProvider(tp *schema.Provider) ProviderOption

WithTerraformProvider configures the TerraformProvider for this Provider.

type Reference

type Reference struct {
	// Type is the type name of the CRD if it is in the same package or
	// <package-path>.<type-name> if it is in a different package.
	Type string
	// TerraformName is the name of the Terraform resource
	// which will be referenced. The supplied resource name is
	// converted to a type name of the corresponding CRD using
	// the configured TerraformTypeMapper.
	TerraformName string
	// Extractor is the function to be used to extract value from the
	// referenced type. Defaults to getting external name.
	// Optional
	Extractor string
	// RefFieldName is the field name for the Reference field. Defaults to
	// <field-name>Ref or <field-name>Refs.
	// Optional
	RefFieldName string
	// SelectorFieldName is the field name for the Selector field. Defaults to
	// <field-name>Selector.
	// Optional
	SelectorFieldName string
}

Reference represents the Crossplane options used to generate reference resolvers for fields

type ReferenceInjector

type ReferenceInjector interface {
	InjectReferences(map[string]*Resource) error
}

ReferenceInjector injects cross-resource references across the resources of this Provider.

type References

type References map[string]Reference

References represents reference resolver configurations for the fields of a given resource. Key should be the field path of the field to be referenced.

type Resource

type Resource struct {
	// Name is the name of the resource type in Terraform,
	// e.g. aws_rds_cluster.
	Name string

	// TerraformResource is the Terraform representation of the
	// Terraform Plugin SDKv2 based resource.
	TerraformResource *schema.Resource

	// TerraformPluginFrameworkResource is the Terraform representation
	// of the TF Plugin Framework based resource
	TerraformPluginFrameworkResource fwresource.Resource

	// ShortGroup is the short name of the API group of this CRD. The full
	// CRD API group is calculated by adding the group suffix of the provider.
	// For example, ShortGroup could be `ec2` where group suffix of the
	// provider is `aws.crossplane.io` and in that case, the full group would
	// be `ec2.aws.crossplane.io`
	ShortGroup string

	// Version is the version CRD will have.
	Version string

	// Kind is the kind of the CRD.
	Kind string

	// UseAsync should be enabled for resource whose creation and/or deletion
	// takes more than 1 minute to complete such as Kubernetes clusters or
	// databases.
	UseAsync bool

	// InitializerFns specifies the initializer functions to be used
	// for this Resource.
	InitializerFns []NewInitializerFn

	// OperationTimeouts allows configuring resource operation timeouts.
	OperationTimeouts OperationTimeouts

	// ExternalName allows you to specify a custom ExternalName.
	ExternalName ExternalName

	// References keeps the configuration to build cross resource references
	References References

	// Sensitive keeps the configuration to handle sensitive information
	Sensitive Sensitive

	// LateInitializer configuration to control late-initialization behaviour
	LateInitializer LateInitializer

	// MetaResource is the metadata associated with the resource scraped from
	// the Terraform registry.
	MetaResource *registry.Resource

	// Path is the resource path for the API server endpoint. It defaults to
	// the plural name of the generated CRD. Overriding this sets both the
	// path and the plural name for the generated CRD.
	Path string

	// SchemaElementOptions is a map from the schema element paths to
	// SchemaElementOption for configuring options for schema elements.
	SchemaElementOptions SchemaElementOptions

	// TerraformConfigurationInjector allows a managed resource to inject
	// configuration values in the Terraform configuration map obtained by
	// deserializing its `spec.forProvider` value. Managed resources can
	// use this resource configuration option to inject Terraform
	// configuration parameters into their deserialized configuration maps,
	// if the deserialization skips certain fields.
	TerraformConfigurationInjector ConfigurationInjector

	// TerraformCustomDiff allows a resource.Terraformed to customize how its
	// Terraform InstanceDiff is computed during reconciliation.
	TerraformCustomDiff CustomDiff

	// ServerSideApplyMergeStrategies configures the server-side apply merge
	// strategy for the fields at the given map keys. The map key is
	// a Terraform configuration argument path such as a.b.c, without any
	// index notation (i.e., array/map components do not need indices).
	ServerSideApplyMergeStrategies ServerSideApplyMergeStrategies

	Conversions []conversion.Conversion

	// OverrideFieldNames allows to manually override the relevant field name to
	// avoid possible Go struct name conflicts that may occur after Multiversion
	// CRDs support. During field generation, there may be fields with the same
	// struct name calculated in the same group. For example, let X and Y
	// resources in the same API group have a field named Tag. This field is an
	// object type and the name calculated for the struct to be generated is
	// TagParameters (for spec) for both resources. To avoid this conflict, upjet
	// looks at all previously created structs in the package during generation
	// and if there is a conflict, it puts the Kind name of the related resource
	// in front of the next one: YTagParameters.
	// With Multiversion CRDs support, the above conflict scenario cannot be
	// solved in the generator when the old API group is preserved and not
	// regenerated, because the generator does not know the object names in the
	// old version. For example, a new API version is generated for resource X. In
	// this case, no generation is done for the old version of X and when Y is
	// generated, the generator is not aware of the TagParameters in X and
	// generates TagParameters instead of YTagParameters. Thus, two object types
	// with the same name are generated in the same package. This can be overcome
	// by using this configuration API.
	// The key of the map indicates the name of the field that is generated and
	// causes the conflict, while the value indicates the name used to avoid the
	// conflict. By convention, also used in upjet, the field name is preceded by
	// the value of the generated Kind, for example:
	// "TagParameters": "ClusterTagParameters"
	OverrideFieldNames map[string]string
	// contains filtered or unexported fields
}

Resource is the set of information that you can override at different steps of the code generation pipeline.

func DefaultResource

func DefaultResource(name string, terraformSchema *schema.Resource, terraformPluginFrameworkResource fwresource.Resource, terraformRegistry *registry.Resource, opts ...ResourceOption) *Resource

DefaultResource keeps an initial default configuration for all resources of a provider.

func (*Resource) MarkAsRequired added in v1.1.6

func (r *Resource) MarkAsRequired(fieldpaths ...string)

MarkAsRequired marks the given fieldpaths as required without manipulating the native field schema.

func (*Resource) RequiredFields added in v1.1.6

func (r *Resource) RequiredFields() []string

RequiredFields returns slice of the marked as required fieldpaths.

func (*Resource) ShouldUseTerraformPluginFrameworkClient added in v1.1.0

func (r *Resource) ShouldUseTerraformPluginFrameworkClient() bool

ShouldUseTerraformPluginFrameworkClient returns whether to generate a Terraform Plugin Framework-based external client for this Resource.

func (*Resource) ShouldUseTerraformPluginSDKClient added in v1.1.0

func (r *Resource) ShouldUseTerraformPluginSDKClient() bool

ShouldUseTerraformPluginSDKClient returns whether to generate an SDKv2-based external client for this Resource.

type ResourceConfigurator

type ResourceConfigurator interface {
	Configure(r *Resource)
}

ResourceConfigurator configures a Resource

type ResourceConfiguratorChain

type ResourceConfiguratorChain []ResourceConfigurator

A ResourceConfiguratorChain chains multiple ResourceConfigurators.

func (ResourceConfiguratorChain) Configure

func (cc ResourceConfiguratorChain) Configure(r *Resource)

Configure configures a resource by calling each ResourceConfigurator in the chain serially.

type ResourceConfiguratorFn

type ResourceConfiguratorFn func(r *Resource)

ResourceConfiguratorFn is a function that implements the ResourceConfigurator interface

func (ResourceConfiguratorFn) Configure

func (c ResourceConfiguratorFn) Configure(r *Resource)

Configure configures a resource by calling ResourceConfiguratorFn

type ResourceOption

type ResourceOption func(*Resource)

ResourceOption allows setting optional fields of a Resource object.

type SchemaElementOption

type SchemaElementOption struct {
	// AddToObservation is set to true if the field represented by
	// a schema element is to be added to the generated CRD type's
	// Observation type.
	AddToObservation bool
	// EmbeddedObject  is set to true if the field represented by
	// a schema element is to be embedded into its parent instead of being
	// generated as a single element list.
	EmbeddedObject bool
}

SchemaElementOption represents configuration options on a schema element.

type SchemaElementOptions

type SchemaElementOptions map[string]*SchemaElementOption

SchemaElementOptions represents schema element options for the schema elements of a Resource.

func (SchemaElementOptions) AddToObservation

func (m SchemaElementOptions) AddToObservation(el string) bool

AddToObservation returns true if the schema element at the specified path should be added to the CRD type's Observation type.

func (SchemaElementOptions) EmbeddedObject added in v1.1.1

func (m SchemaElementOptions) EmbeddedObject(el string) bool

EmbeddedObject returns true if the schema element at the specified path should be generated as an embedded object.

func (SchemaElementOptions) SetAddToObservation

func (m SchemaElementOptions) SetAddToObservation(el string)

SetAddToObservation sets the AddToObservation for the specified key.

func (SchemaElementOptions) SetEmbeddedObject added in v1.1.1

func (m SchemaElementOptions) SetEmbeddedObject(el string)

SetEmbeddedObject sets the EmbeddedObject for the specified key.

type Sensitive

type Sensitive struct {
	// AdditionalConnectionDetailsFn is the path for function adding additional
	// connection details keys
	AdditionalConnectionDetailsFn AdditionalConnectionDetailsFn
	// contains filtered or unexported fields
}

Sensitive represents configurations to handle sensitive information

func (*Sensitive) AddFieldPath

func (s *Sensitive) AddFieldPath(tf, xp string)

AddFieldPath adds the given tf path and xp path to the fieldPaths map.

func (*Sensitive) GetFieldPaths

func (s *Sensitive) GetFieldPaths() map[string]string

GetFieldPaths returns the fieldPaths map for Sensitive

type ServerSideApplyMergeStrategies added in v1.1.0

type ServerSideApplyMergeStrategies map[string]MergeStrategy

ServerSideApplyMergeStrategies configures the server-side apply merge strategy for the field at the specified path as the map key. The key is a Terraform configuration argument path such as a.b.c, without any index notation (i.e., array/map components do not need indices). It's an error to set a configuration option which does not match the object type at the specified path or to leave the corresponding configuration entry empty. For example, if the field at path a.b.c is a list, then ListMergeStrategy must be set and it should be the only configuration entry set.

type SetIdentifierArgumentsFn

type SetIdentifierArgumentsFn func(base map[string]any, externalName string)

SetIdentifierArgumentsFn sets the name of the resource in Terraform attributes map, i.e. Main HCL file.

var NopSetIdentifierArgument SetIdentifierArgumentsFn = func(_ map[string]any, _ string) {}

NopSetIdentifierArgument does nothing. It's useful for cases where the external name is calculated by provider and doesn't have any effect on spec fields.

type StructType added in v1.1.0

type StructType string

A StructType is a type of struct.

const (
	// StructTypeAtomic means that the struct can only be entirely replaced by a
	// single manager.
	StructTypeAtomic StructType = "atomic"

	// StructTypeGranular means that the struct supports separate managers
	// updating individual fields.
	StructTypeGranular StructType = "granular"
)

Struct types.

type Tagger

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

Tagger implements the Initialize function to set external tags

func NewTagger

func NewTagger(kube client.Client, fieldName string) *Tagger

NewTagger returns a Tagger object.

func (*Tagger) Initialize

func (t *Tagger) Initialize(ctx context.Context, mg xpresource.Managed) error

Initialize is a custom initializer for setting external tags

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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