Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

resource/schema: Initial package #558

Merged
merged 5 commits into from Nov 29, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/557.txt
@@ -0,0 +1,3 @@
```release-note:feature
resource/schema/planmodifier: New package which contains type-specific schema plan modifier interfaces
```
7 changes: 7 additions & 0 deletions .changelog/pending.txt
@@ -0,0 +1,7 @@
```release-note:note
resource: The `Resource` type `GetSchema` method has been deprecated. Use the `Schema` method instead.
```

```release-note:feature
resource/schema: New package which contains schema interfaces and types relevant to resources
```
82 changes: 82 additions & 0 deletions internal/fwschema/fwxschema/attribute_plan_modification.go
Expand Up @@ -2,6 +2,7 @@ package fwxschema

import (
"github.com/hashicorp/terraform-plugin-framework/internal/fwschema"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
"github.com/hashicorp/terraform-plugin-framework/tfsdk"
)

Expand All @@ -17,3 +18,84 @@ type AttributeWithPlanModifiers interface {
// the tfsdk.Attribute field name.
GetPlanModifiers() tfsdk.AttributePlanModifiers
}

// AttributeWithBoolPlanModifiers is an optional interface on Attribute which
// enables Bool plan modifier support.
type AttributeWithBoolPlanModifiers interface {
fwschema.Attribute

// BoolPlanModifiers should return a list of Bool plan modifiers.
BoolPlanModifiers() []planmodifier.Bool
}

// AttributeWithFloat64PlanModifiers is an optional interface on Attribute which
// enables Float64 plan modifier support.
type AttributeWithFloat64PlanModifiers interface {
fwschema.Attribute

// Float64PlanModifiers should return a list of Float64 plan modifiers.
Float64PlanModifiers() []planmodifier.Float64
}

// AttributeWithInt64PlanModifiers is an optional interface on Attribute which
// enables Int64 plan modifier support.
type AttributeWithInt64PlanModifiers interface {
fwschema.Attribute

// Int64PlanModifiers should return a list of Int64 plan modifiers.
Int64PlanModifiers() []planmodifier.Int64
}

// AttributeWithListPlanModifiers is an optional interface on Attribute which
// enables List plan modifier support.
type AttributeWithListPlanModifiers interface {
fwschema.Attribute

// ListPlanModifiers should return a list of List plan modifiers.
ListPlanModifiers() []planmodifier.List
}

// AttributeWithMapPlanModifiers is an optional interface on Attribute which
// enables Map plan modifier support.
type AttributeWithMapPlanModifiers interface {
fwschema.Attribute

// MapPlanModifiers should return a list of Map plan modifiers.
MapPlanModifiers() []planmodifier.Map
}

// AttributeWithNumberPlanModifiers is an optional interface on Attribute which
// enables Number plan modifier support.
type AttributeWithNumberPlanModifiers interface {
fwschema.Attribute

// NumberPlanModifiers should return a list of Number plan modifiers.
NumberPlanModifiers() []planmodifier.Number
}

// AttributeWithObjectPlanModifiers is an optional interface on Attribute which
// enables Object plan modifier support.
type AttributeWithObjectPlanModifiers interface {
fwschema.Attribute

// ObjectPlanModifiers should return a list of Object plan modifiers.
ObjectPlanModifiers() []planmodifier.Object
}

// AttributeWithSetPlanModifiers is an optional interface on Attribute which
// enables Set plan modifier support.
type AttributeWithSetPlanModifiers interface {
fwschema.Attribute

// SetPlanModifiers should return a list of Set plan modifiers.
SetPlanModifiers() []planmodifier.Set
}

// AttributeWithStringPlanModifiers is an optional interface on Attribute which
// enables String plan modifier support.
type AttributeWithStringPlanModifiers interface {
fwschema.Attribute

// StringPlanModifiers should return a list of String plan modifiers.
StringPlanModifiers() []planmodifier.String
}
28 changes: 28 additions & 0 deletions internal/fwschema/fwxschema/block_plan_modification.go
Expand Up @@ -2,6 +2,7 @@ package fwxschema

import (
"github.com/hashicorp/terraform-plugin-framework/internal/fwschema"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
"github.com/hashicorp/terraform-plugin-framework/tfsdk"
)

Expand All @@ -17,3 +18,30 @@ type BlockWithPlanModifiers interface {
// the tfsdk.Block field name.
GetPlanModifiers() tfsdk.AttributePlanModifiers
}

// BlockWithListPlanModifiers is an optional interface on Block which
// enables List plan modifier support.
type BlockWithListPlanModifiers interface {
fwschema.Block

// ListPlanModifiers should return a list of List plan modifiers.
ListPlanModifiers() []planmodifier.List
}

// BlockWithObjectPlanModifiers is an optional interface on Block which
// enables Object plan modifier support.
type BlockWithObjectPlanModifiers interface {
fwschema.Block

// ObjectPlanModifiers should return a list of Object plan modifiers.
ObjectPlanModifiers() []planmodifier.Object
}

// BlockWithSetPlanModifiers is an optional interface on Block which
// enables Set plan modifier support.
type BlockWithSetPlanModifiers interface {
fwschema.Block

// SetPlanModifiers should return a list of Set plan modifiers.
SetPlanModifiers() []planmodifier.Set
}
@@ -0,0 +1,15 @@
package fwxschema

import (
"github.com/hashicorp/terraform-plugin-framework/internal/fwschema"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
)

// NestedAttributeObjectWithPlanModifiers is an optional interface on
// NestedAttributeObject which enables Object plan modification support.
type NestedAttributeObjectWithPlanModifiers interface {
fwschema.NestedAttributeObject

// ObjectPlanModifiers should return a list of Object plan modifiers.
ObjectPlanModifiers() []planmodifier.Object
}
@@ -0,0 +1,15 @@
package fwxschema

import (
"github.com/hashicorp/terraform-plugin-framework/internal/fwschema"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
)

// NestedBlockObjectWithPlanModifiers is an optional interface on
// NestedBlockObject which enables Object plan modification support.
type NestedBlockObjectWithPlanModifiers interface {
fwschema.NestedBlockObject

// ObjectPlanModifiers should return a list of Object plan modifiers.
ObjectPlanModifiers() []planmodifier.Object
}