Skip to content

Use Custom Types for Timeouts #17

@bendbennett

Description

@bendbennett

Terraform CLI and Framework Versions

TF v1.3.2
terrfaform-plugin-framework 0.17.0

Use Cases or Problem Statement

With the release of terraform-plugin-framework v0.17.0 we can use custom types for nested blocks and nested attributes. This allows us to define types and values for timeouts and to add functions that are specific to the usage of the timeouts types and values rather than having to operate on types.Object.

Proposal

Add TimeoutsType and TimeoutsValue embedding types.ObjectType and types.Object, respectively.

For example:

type TimeoutsType struct {
	types.ObjectType
}

type TimeoutsValue struct {
	types.Object
}

Add functions that allow easy extraction of a time.Duration value from TimeoutsValue for create, read, update and delete.

For example:

func (t TimeoutsValue) Create(ctx context.Context) (time.Duration, error) {
	return t.getTimeout(ctx, attributeNameCreate)
}

Add resource and datasource schema-specific functions that generate the required schema.Block or schema.Attribute.

For example:

func Block(ctx context.Context, opts Opts) schema.Block {
	return schema.SingleNestedBlock{
		Attributes: attributesMap(opts),
		CustomType: timeouts.TimeoutsType{
			ObjectType: types.ObjectType{
				AttrTypes: attrTypesMap(opts),
			},
		},
	}
}

Additional Information

References

Code of Conduct

  • I agree to follow this project's Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions