-
Notifications
You must be signed in to change notification settings - Fork 0
/
timeouts_attribute.go
70 lines (57 loc) · 1.75 KB
/
timeouts_attribute.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/*
* SPDX-FileCopyrightText: Copyright (c) 2025 Orange
* SPDX-License-Identifier: Mozilla Public License 2.0
*
* This software is distributed under the MPL-2.0 license.
* the text of which is available at https://www.mozilla.org/en-US/MPL/2.0/
* or see the "LICENSE" file for more details.
*/
package superschema
import (
"context"
schemaD "github.com/hashicorp/terraform-plugin-framework/datasource/schema"
schemaR "github.com/hashicorp/terraform-plugin-framework/resource/schema"
timeoutsD "github.com/hashicorp/terraform-plugin-framework-timeouts/datasource/timeouts"
timeoutsR "github.com/hashicorp/terraform-plugin-framework-timeouts/resource/timeouts"
)
var _ Attribute = TimeoutAttribute{}
type ResourceTimeoutAttribute struct {
Create bool
Read bool
Delete bool
Update bool
}
type DatasourceTimeoutAttribute struct {
Read bool
}
type TimeoutAttribute struct {
Resource *ResourceTimeoutAttribute
DataSource *DatasourceTimeoutAttribute
}
// IsResource returns true if the attribute is a resource attribute.
func (s TimeoutAttribute) IsResource() bool {
return s.Resource != nil
}
// IsDataSource returns true if the attribute is a data source attribute.
func (s TimeoutAttribute) IsDataSource() bool {
return s.DataSource != nil
}
func (s TimeoutAttribute) GetResource(ctx context.Context) schemaR.Attribute {
var a schemaR.Attribute
if s.Resource != nil {
a = timeoutsR.Attributes(ctx, timeoutsR.Opts{
Create: s.Resource.Create,
Read: s.Resource.Read,
Delete: s.Resource.Delete,
Update: s.Resource.Update,
})
}
return a
}
func (s TimeoutAttribute) GetDataSource(ctx context.Context) schemaD.Attribute {
var a schemaD.Attribute
if s.DataSource != nil && s.DataSource.Read {
a = timeoutsD.Attributes(ctx)
}
return a
}