Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ toolchain go1.23.7

require (
github.com/google/go-cmp v0.7.0
github.com/hashicorp/terraform-plugin-framework v1.15.1
github.com/hashicorp/terraform-plugin-go v0.28.0
github.com/hashicorp/terraform-plugin-framework v1.16.0-beta.1
github.com/hashicorp/terraform-plugin-go v0.29.0-beta.1
github.com/hashicorp/terraform-plugin-log v0.9.0
)

Expand All @@ -19,5 +19,5 @@ require (
github.com/mitchellh/go-testing-interface v1.14.1 // indirect
github.com/vmihailenco/msgpack/v5 v5.4.1 // indirect
github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect
golang.org/x/sys v0.32.0 // indirect
golang.org/x/sys v0.33.0 // indirect
)
12 changes: 6 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
github.com/hashicorp/go-hclog v1.5.0 h1:bI2ocEMgcVlz55Oj1xZNBsVi900c7II+fWDyV9o+13c=
github.com/hashicorp/go-hclog v1.5.0/go.mod h1:W4Qnvbt70Wk/zYJryRzDRU/4r0kIg0PVHBcfoyhpF5M=
github.com/hashicorp/terraform-plugin-framework v1.15.1 h1:2mKDkwb8rlx/tvJTlIcpw0ykcmvdWv+4gY3SIgk8Pq8=
github.com/hashicorp/terraform-plugin-framework v1.15.1/go.mod h1:hxrNI/GY32KPISpWqlCoTLM9JZsGH3CyYlir09bD/fI=
github.com/hashicorp/terraform-plugin-go v0.28.0 h1:zJmu2UDwhVN0J+J20RE5huiF3XXlTYVIleaevHZgKPA=
github.com/hashicorp/terraform-plugin-go v0.28.0/go.mod h1:FDa2Bb3uumkTGSkTFpWSOwWJDwA7bf3vdP3ltLDTH6o=
github.com/hashicorp/terraform-plugin-framework v1.16.0-beta.1 h1:HhL8HbPuKu9pH5kgEjeWWaqXgN88U42dFa8sYRLHQsY=
github.com/hashicorp/terraform-plugin-framework v1.16.0-beta.1/go.mod h1:XQfoA+oS1ETMuQrcM689/TWMx9leV59N7Xscm5t7b+g=
github.com/hashicorp/terraform-plugin-go v0.29.0-beta.1 h1:xeHlRQYev3iMXwX2W7+D1bSfLRBs9jojZXqE6hmNxMI=
github.com/hashicorp/terraform-plugin-go v0.29.0-beta.1/go.mod h1:5pww/UULn9C2tItq6o5sbScEkJxBUt9X9kI4DkeRsIw=
github.com/hashicorp/terraform-plugin-log v0.9.0 h1:i7hOA+vdAItN1/7UrfBqBwvYPQ9TFvymaRGZED3FCV0=
github.com/hashicorp/terraform-plugin-log v0.9.0/go.mod h1:rKL8egZQ/eXSyDqzLUuwUYLVdlYeamldAHSxjUFADow=
github.com/mattn/go-colorable v0.1.9/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=
Expand All @@ -37,8 +37,8 @@ golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220503163025-988cb79eb6c6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.32.0 h1:s77OFDvIQeibCmezSnk/q6iAfkdiQaJi4VzroCFrN20=
golang.org/x/sys v0.32.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
golang.org/x/sys v0.33.0 h1:q3i8TbbEz+JRD9ywIRlyRAQbM0qF7hu24q3teo2hbuw=
golang.org/x/sys v0.33.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
112 changes: 112 additions & 0 deletions list/timeouts/schema.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0

package timeouts

import (
"context"

"github.com/hashicorp/terraform-plugin-framework/attr"
"github.com/hashicorp/terraform-plugin-framework/list/schema"
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
"github.com/hashicorp/terraform-plugin-framework/types"

"github.com/hashicorp/terraform-plugin-framework-timeouts/internal/validators"
)

const (
attributeNameList = "list"
)

// Opts is used as an argument to BlockWithOpts and AttributesWithOpts to indicate
// whether supplied descriptions should override default descriptions.
type Opts struct {
ListDescription string
}

// BlockWithOpts returns a schema.Block containing attributes for `List`, which is
// defined as types.StringType and optional. A validator is used to verify
// that the value assigned to `List` can be parsed as time.Duration. The supplied
// Opts are used to override defaults.
func BlockWithOpts(ctx context.Context, opts Opts) schema.Block {
return schema.SingleNestedBlock{

Check failure on line 32 in list/timeouts/schema.go

View workflow job for this annotation

GitHub Actions / test (Go v1.24)

undefined: schema.SingleNestedBlock

Check failure on line 32 in list/timeouts/schema.go

View workflow job for this annotation

GitHub Actions / test (Go v1.23)

undefined: schema.SingleNestedBlock

Check failure on line 32 in list/timeouts/schema.go

View workflow job for this annotation

GitHub Actions / golangci-lint

undefined: schema.SingleNestedBlock
Attributes: attributesMap(opts),
CustomType: Type{
ObjectType: types.ObjectType{
AttrTypes: attrTypesMap(),
},
},
}
}

// Block returns a schema.Block containing attributes for `List`, which is
// defined as types.StringType and optional. A validator is used to verify
// that the value assigned to `List` can be parsed as time.Duration.
func Block(ctx context.Context) schema.Block {
return schema.SingleNestedBlock{

Check failure on line 46 in list/timeouts/schema.go

View workflow job for this annotation

GitHub Actions / test (Go v1.24)

undefined: schema.SingleNestedBlock

Check failure on line 46 in list/timeouts/schema.go

View workflow job for this annotation

GitHub Actions / test (Go v1.23)

undefined: schema.SingleNestedBlock

Check failure on line 46 in list/timeouts/schema.go

View workflow job for this annotation

GitHub Actions / golangci-lint

undefined: schema.SingleNestedBlock
Attributes: attributesMap(Opts{}),
CustomType: Type{
ObjectType: types.ObjectType{
AttrTypes: attrTypesMap(),
},
},
}
}

// AttributesWithOpts returns a schema.SingleNestedAttribute which contains an
// attribute for `List`, which is defined as types.StringType and optional.
// A validator is used to verify that the value assigned to an attribute
// can be parsed as time.Duration. The supplied Opts are used to override defaults.
func AttributesWithOpts(ctx context.Context, opts Opts) schema.Attribute {
return schema.SingleNestedAttribute{

Check failure on line 61 in list/timeouts/schema.go

View workflow job for this annotation

GitHub Actions / test (Go v1.24)

undefined: schema.SingleNestedAttribute

Check failure on line 61 in list/timeouts/schema.go

View workflow job for this annotation

GitHub Actions / test (Go v1.23)

undefined: schema.SingleNestedAttribute

Check failure on line 61 in list/timeouts/schema.go

View workflow job for this annotation

GitHub Actions / golangci-lint

undefined: schema.SingleNestedAttribute
Attributes: attributesMap(opts),
CustomType: Type{
ObjectType: types.ObjectType{
AttrTypes: attrTypesMap(),
},
},
Optional: true,
}
}

// Attributes returns a schema.SingleNestedAttribute which contains an
// attribute for `List`, which is defined as types.StringType and optional.
// A validator is used to verify that the value assigned to an attribute
// can be parsed as time.Duration.
func Attributes(ctx context.Context) schema.Attribute {
return schema.SingleNestedAttribute{

Check failure on line 77 in list/timeouts/schema.go

View workflow job for this annotation

GitHub Actions / test (Go v1.24)

undefined: schema.SingleNestedAttribute

Check failure on line 77 in list/timeouts/schema.go

View workflow job for this annotation

GitHub Actions / test (Go v1.23)

undefined: schema.SingleNestedAttribute

Check failure on line 77 in list/timeouts/schema.go

View workflow job for this annotation

GitHub Actions / golangci-lint

undefined: schema.SingleNestedAttribute (typecheck)
Attributes: attributesMap(Opts{}),
CustomType: Type{
ObjectType: types.ObjectType{
AttrTypes: attrTypesMap(),
},
},
Optional: true,
}
}

func attributesMap(opts Opts) map[string]schema.Attribute {
attribute := schema.StringAttribute{
Optional: true,
Description: `A string that can be [parsed as a duration](https://pkg.go.dev/time#ParseDuration) ` +
`consisting of numbers and unit suffixes, such as "30s" or "2h45m". Valid time units are ` +
`"s" (seconds), "m" (minutes), "h" (hours).`,
Validators: []validator.String{
validators.TimeDuration(),
},
}

if opts.ListDescription != "" {
attribute.Description = opts.ListDescription
}

return map[string]schema.Attribute{
attributeNameList: attribute,
}
}

func attrTypesMap() map[string]attr.Type {
return map[string]attr.Type{
attributeNameList: types.StringType,
}
}
Loading
Loading