@@ -2,14 +2,9 @@ package provider
2
2
3
3
import (
4
4
"context"
5
- "fmt"
6
5
7
6
"github.com/hashicorp/terraform-plugin-framework/diag"
8
- "github.com/hashicorp/terraform-plugin-framework/path"
9
7
"github.com/hashicorp/terraform-plugin-framework/resource"
10
- "github.com/hashicorp/terraform-plugin-framework/resource/schema"
11
- "github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
12
- "github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier"
13
8
"github.com/hashicorp/terraform-plugin-framework/types"
14
9
"github.com/hashicorp/terraform-plugin-log/tflog"
15
10
@@ -34,55 +29,18 @@ type NamespaceResource struct {
34
29
}
35
30
36
31
// NamespaceResourceModel describes the resource data model.
37
- type NamespaceResourceModel struct {
38
- ID types.String `tfsdk:"id"`
39
- Name types.String `tfsdk:"name"`
40
- ParentID types.String `tfsdk:"parent_id"`
41
- }
32
+ type NamespaceResourceModel = NamespaceModel
42
33
43
34
func (r * NamespaceResource ) Metadata (_ context.Context , req resource.MetadataRequest , resp * resource.MetadataResponse ) {
44
35
resp .TypeName = req .ProviderTypeName + "_namespace"
45
36
}
46
37
47
38
func (r * NamespaceResource ) Schema (_ context.Context , _ resource.SchemaRequest , resp * resource.SchemaResponse ) {
48
- resp .Schema = schema.Schema {
49
- MarkdownDescription : "Namespace resource for Pomerium." ,
50
-
51
- Attributes : map [string ]schema.Attribute {
52
- "id" : schema.StringAttribute {
53
- Computed : true ,
54
- Description : "Unique identifier for the namespace." ,
55
- PlanModifiers : []planmodifier.String {
56
- stringplanmodifier .UseStateForUnknown (),
57
- },
58
- },
59
- "name" : schema.StringAttribute {
60
- Description : "Name of the namespace." ,
61
- Required : true ,
62
- },
63
- "parent_id" : schema.StringAttribute {
64
- Description : "ID of the parent namespace (optional)." ,
65
- Optional : true ,
66
- },
67
- },
68
- }
39
+ resp .Schema = NamespaceSchema (false )
69
40
}
70
41
71
42
func (r * NamespaceResource ) Configure (_ context.Context , req resource.ConfigureRequest , resp * resource.ConfigureResponse ) {
72
- if req .ProviderData == nil {
73
- return
74
- }
75
-
76
- c , ok := req .ProviderData .(* client.Client )
77
- if ! ok {
78
- resp .Diagnostics .AddError (
79
- "Unexpected Provider Data Type" ,
80
- fmt .Sprintf ("Expected *client.Client, got: %T." , req .ProviderData ),
81
- )
82
- return
83
- }
84
-
85
- r .client = c
43
+ r .client = ConfigureClient (req , resp , "namespace" )
86
44
}
87
45
88
46
func (r * NamespaceResource ) Create (ctx context.Context , req resource.CreateRequest , resp * resource.CreateResponse ) {
@@ -186,8 +144,8 @@ func (r *NamespaceResource) Delete(ctx context.Context, req resource.DeleteReque
186
144
resp .State .RemoveResource (ctx )
187
145
}
188
146
189
- func (r * NamespaceResource ) ImportState (ctx context.Context , req resource.ImportStateRequest , resp * resource.ImportStateResponse ) {
190
- resource . ImportStatePassthroughID (ctx , path . Root ( "id" ), req , resp )
147
+ func (r * NamespaceResource ) ImportState (_ context.Context , req resource.ImportStateRequest , resp * resource.ImportStateResponse ) {
148
+ ImportStatePassthroughID (req , resp )
191
149
}
192
150
193
151
func ConvertNamespaceToPB (_ context.Context , src * NamespaceResourceModel ) (* pb.Namespace , diag.Diagnostics ) {
0 commit comments