-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathprovider.go
More file actions
161 lines (142 loc) · 4.31 KB
/
provider.go
File metadata and controls
161 lines (142 loc) · 4.31 KB
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
package framework
import (
"context"
"fmt"
"github.com/hashicorp/terraform-plugin-framework/datasource"
"github.com/hashicorp/terraform-plugin-framework/ephemeral"
"github.com/hashicorp/terraform-plugin-framework/function"
"github.com/hashicorp/terraform-plugin-framework/list"
"github.com/hashicorp/terraform-plugin-framework/provider"
"github.com/hashicorp/terraform-plugin-framework/provider/schema"
"github.com/hashicorp/terraform-plugin-framework/resource"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/hashicorp/terraform-provider-corner/internal/backend"
)
var (
_ provider.ProviderWithFunctions = (*testProvider)(nil)
_ provider.ProviderWithEphemeralResources = (*testProvider)(nil)
_ provider.ProviderWithListResources = (*testProvider)(nil)
)
func New() provider.Provider {
return &testProvider{
ephSpyClient: &EphemeralResourceSpyClient{},
}
}
func NewWithEphemeralSpy(spy *EphemeralResourceSpyClient) provider.Provider {
return &testProvider{
ephSpyClient: spy,
}
}
func NewWithUpgradeVersion(version int64) provider.Provider {
return &testProvider{
ephSpyClient: &EphemeralResourceSpyClient{},
upgradeVersion: version,
}
}
type testProvider struct {
ephSpyClient *EphemeralResourceSpyClient
upgradeVersion int64
}
func (p *testProvider) Metadata(_ context.Context, _ provider.MetadataRequest, resp *provider.MetadataResponse) {
resp.TypeName = "framework"
}
func (p *testProvider) Schema(_ context.Context, _ provider.SchemaRequest, resp *provider.SchemaResponse) {
resp.Schema = schema.Schema{
Attributes: map[string]schema.Attribute{
"dummy": schema.StringAttribute{
Optional: true,
},
"deferral": schema.BoolAttribute{
Optional: true,
},
},
}
}
func (p *testProvider) Configure(ctx context.Context, req provider.ConfigureRequest, resp *provider.ConfigureResponse) {
var config providerConfig
diags := req.Config.Get(ctx, &config)
resp.Diagnostics.Append(diags...)
if resp.Diagnostics.HasError() {
return
}
client, err := backend.NewClient()
if err != nil {
resp.Diagnostics.AddError("Error initialising client", err.Error())
}
if req.ClientCapabilities.DeferralAllowed && config.Deferral.ValueBool() {
resp.Deferred = &provider.Deferred{
Reason: provider.DeferredReasonProviderConfigUnknown,
}
}
resp.ResourceData = client
resp.EphemeralResourceData = p.ephSpyClient
}
func (p *testProvider) Resources(_ context.Context) []func() resource.Resource {
return []func() resource.Resource{
NewSchemaResource,
NewDeferredActionResource,
NewDeferredActionPlanModificationResource,
NewDynamicSchemaResource,
NewDynamicComputedTypeChangeResource,
NewTimeoutsResource,
NewTimeTypesResource,
NewUserResource,
NewFloat32PrecisionResource,
NewFloat64PrecisionResource,
NewTFSDKReflectionResource,
NewMoveStateResource,
NewSetNestedBlockWithDefaultsResource,
NewSetSemanticEqualityResource,
NewCustomTypeResource,
NewWriteOnlyResource,
NewWriteOnceResource,
NewWriteOnlyValidationsResource,
NewWriteOnlyImportResource,
NewWriteOnlyMoveResource,
func() resource.Resource {
return NewWriteOnlyUpgradeResource(p.upgradeVersion)
},
NewIdentityResource,
NewListResource,
}
}
func (p *testProvider) DataSources(_ context.Context) []func() datasource.DataSource {
return nil
}
func (p *testProvider) Functions(ctx context.Context) []func() function.Function {
return []func() function.Function{
NewBoolFunction,
NewDynamicFunction,
NewFloat32Function,
NewFloat64Function,
NewInt32Function,
NewInt64Function,
NewListFunction,
NewMapFunction,
NewNumberFunction,
NewObjectFunction,
NewObjectWithDynamicFunction,
NewSetFunction,
NewStringFunction,
NewVariadicFunction,
NewDynamicVariadicFunction,
}
}
func (p *testProvider) EphemeralResources(ctx context.Context) []func() ephemeral.EphemeralResource {
return []func() ephemeral.EphemeralResource{
NewSchemaEphemeralResource,
NewEphemeralLifecycleResource,
}
}
func (p *testProvider) ListResources(_ context.Context) []func() list.ListResource {
fmt.Println("ListResources called")
return []func() list.ListResource{
NewListResourceAsListResource,
}
}
type providerConfig struct {
Dummy types.String `tfsdk:"dummy"`
Deferral types.Bool `tfsdk:"deferral"`
}