Skip to content

Commit b7dcbaa

Browse files
committed
feat(resource): add setup key Type for schema generation
1 parent c2e2e61 commit b7dcbaa

File tree

5 files changed

+660
-16
lines changed

5 files changed

+660
-16
lines changed

provider/cmd/pulumi-resource-netbird/schema.json

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,19 @@
347347
"end"
348348
]
349349
},
350+
"netbird:resource:SetupKeyType": {
351+
"type": "string",
352+
"enum": [
353+
{
354+
"description": "Reusable setup key that supports multiple peers.",
355+
"value": "reusable"
356+
},
357+
{
358+
"description": "One-off setup key that can be used only once.",
359+
"value": "one-off"
360+
}
361+
]
362+
},
350363
"netbird:resource:Type": {
351364
"type": "string",
352365
"enum": [
@@ -887,6 +900,113 @@
887900
"rules"
888901
]
889902
},
903+
"netbird:resource:SetupKey": {
904+
"description": "Manages a NetBird setup key.",
905+
"properties": {
906+
"allowExtraDnsLabels": {
907+
"type": "boolean",
908+
"description": "Allow peers to add extra DNS labels beyond the base peer name."
909+
},
910+
"autoGroups": {
911+
"type": "array",
912+
"items": {
913+
"type": "string"
914+
},
915+
"description": "Group IDs to auto-assign to peers created with this key."
916+
},
917+
"ephemeral": {
918+
"type": "boolean",
919+
"description": "Whether peers registered with this key are ephemeral (auto-expire)."
920+
},
921+
"expires": {
922+
"type": "string"
923+
},
924+
"expiresIn": {
925+
"type": "integer",
926+
"description": "Time-to-live in seconds from creation; use 0 for no expiration if supported by the API."
927+
},
928+
"key": {
929+
"type": "string"
930+
},
931+
"lastUsed": {
932+
"type": "string"
933+
},
934+
"name": {
935+
"type": "string",
936+
"description": "Setup key display name."
937+
},
938+
"revoked": {
939+
"type": "boolean"
940+
},
941+
"state": {
942+
"type": "string"
943+
},
944+
"type": {
945+
"$ref": "#/types/netbird:resource:SetupKeyType",
946+
"description": "Setup key type: 'one-off' (single use) or 'reusable'."
947+
},
948+
"updatedAt": {
949+
"type": "string"
950+
},
951+
"usageLimit": {
952+
"type": "integer",
953+
"description": "Maximum uses for reusable keys; 0 = unlimited."
954+
},
955+
"usedTimes": {
956+
"type": "integer"
957+
},
958+
"valid": {
959+
"type": "boolean"
960+
}
961+
},
962+
"required": [
963+
"name",
964+
"type",
965+
"expiresIn",
966+
"autoGroups",
967+
"usageLimit"
968+
],
969+
"inputProperties": {
970+
"allowExtraDnsLabels": {
971+
"type": "boolean",
972+
"description": "Allow peers to add extra DNS labels beyond the base peer name."
973+
},
974+
"autoGroups": {
975+
"type": "array",
976+
"items": {
977+
"type": "string"
978+
},
979+
"description": "Group IDs to auto-assign to peers created with this key."
980+
},
981+
"ephemeral": {
982+
"type": "boolean",
983+
"description": "Whether peers registered with this key are ephemeral (auto-expire)."
984+
},
985+
"expiresIn": {
986+
"type": "integer",
987+
"description": "Time-to-live in seconds from creation; use 0 for no expiration if supported by the API."
988+
},
989+
"name": {
990+
"type": "string",
991+
"description": "Setup key display name."
992+
},
993+
"type": {
994+
"$ref": "#/types/netbird:resource:SetupKeyType",
995+
"description": "Setup key type: 'one-off' (single use) or 'reusable'."
996+
},
997+
"usageLimit": {
998+
"type": "integer",
999+
"description": "Maximum uses for reusable keys; 0 = unlimited."
1000+
}
1001+
},
1002+
"requiredInputs": [
1003+
"name",
1004+
"type",
1005+
"expiresIn",
1006+
"autoGroups",
1007+
"usageLimit"
1008+
]
1009+
},
8901010
"netbird:resource:User": {
8911011
"description": "A NetBird user that receives an invite and is optionally assigned groups and roles.",
8921012
"properties": {

provider/resource/setupkey.go

Lines changed: 34 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,24 +23,24 @@ func (s *SetupKey) Annotate(a infer.Annotator) {
2323

2424
// SetupKeyArgs represents the input arguments for creating a setup key.
2525
type SetupKeyArgs struct {
26-
Name string `pulumi:"name"`
27-
Type string `pulumi:"type"` // "one-off" | "reusable"
28-
ExpiresIn int `pulumi:"expiresIn"` // seconds
29-
AutoGroups []string `pulumi:"autoGroups"`
30-
UsageLimit int `pulumi:"usageLimit"` // 0 = unlimited
31-
Ephemeral *bool `pulumi:"ephemeral,optional"`
32-
AllowExtraDNSLabels *bool `pulumi:"allowExtraDnsLabels,optional"`
26+
Name string `pulumi:"name"`
27+
Type SetupKeyType `pulumi:"type"` // "one-off" | "reusable"
28+
ExpiresIn int `pulumi:"expiresIn"` // seconds
29+
AutoGroups []string `pulumi:"autoGroups"`
30+
UsageLimit int `pulumi:"usageLimit"` // 0 = unlimited
31+
Ephemeral *bool `pulumi:"ephemeral,optional"`
32+
AllowExtraDNSLabels *bool `pulumi:"allowExtraDnsLabels,optional"`
3333
}
3434

3535
// Annotate provides documentation for SetupKeyArgs fields.
3636
func (a *SetupKeyArgs) Annotate(annotator infer.Annotator) {
37-
annotator.Describe(&a.Name, "Setup key name.")
38-
annotator.Describe(&a.Type, "Setup key type: 'one-off' or 'reusable'.")
39-
annotator.Describe(&a.ExpiresIn, "Expiration time in seconds.")
40-
annotator.Describe(&a.AutoGroups, "List of group IDs to auto-assign to peers.")
41-
annotator.Describe(&a.UsageLimit, "Usage limit (0 = unlimited).")
42-
annotator.Describe(&a.Ephemeral, "Whether peers registered with this key are ephemeral.")
43-
annotator.Describe(&a.AllowExtraDNSLabels, "Allow extra DNS labels to be added to peers.")
37+
annotator.Describe(&a.Name, "Setup key display name.")
38+
annotator.Describe(&a.Type, "Setup key type: 'one-off' (single use) or 'reusable'.")
39+
annotator.Describe(&a.ExpiresIn, "Time-to-live in seconds from creation; use 0 for no expiration if supported by the API.")
40+
annotator.Describe(&a.AutoGroups, "Group IDs to auto-assign to peers created with this key.")
41+
annotator.Describe(&a.UsageLimit, "Maximum uses for reusable keys; 0 = unlimited.")
42+
annotator.Describe(&a.Ephemeral, "Whether peers registered with this key are ephemeral (auto-expire).")
43+
annotator.Describe(&a.AllowExtraDNSLabels, "Allow peers to add extra DNS labels beyond the base peer name.")
4444
}
4545

4646
// SetupKeyState represents the state/output of a setup key resource.
@@ -57,6 +57,24 @@ type SetupKeyState struct {
5757
UpdatedAt *string `pulumi:"updatedAt,optional"`
5858
}
5959

60+
// SetupKeyType defines the kind of setup key accepted by NetBird.
61+
type SetupKeyType string
62+
63+
const (
64+
// SetupKeyTypeReusable creates a key that can be used multiple times.
65+
SetupKeyTypeReusable SetupKeyType = SetupKeyType("reusable")
66+
// SetupKeyTypeOneOff creates a key that can only be used once.
67+
SetupKeyTypeOneOff SetupKeyType = SetupKeyType("one-off")
68+
)
69+
70+
// Values describes the setup key type enum for schema generation.
71+
func (SetupKeyType) Values() []infer.EnumValue[Type] {
72+
return []infer.EnumValue[Type]{
73+
{Name: "reusable", Value: Type(SetupKeyTypeReusable), Description: "Reusable setup key that supports multiple peers."},
74+
{Name: "one-off", Value: Type(SetupKeyTypeOneOff), Description: "One-off setup key that can be used only once."},
75+
}
76+
}
77+
6078
// Create creates a new NetBird setup key.
6179
func (*SetupKey) Create(ctx context.Context, req infer.CreateRequest[SetupKeyArgs]) (infer.CreateResponse[SetupKeyState], error) {
6280
p.GetLogger(ctx).Debugf("Create:SetupKey name=%s, type=%s", req.Inputs.Name, req.Inputs.Type)
@@ -86,7 +104,7 @@ func (*SetupKey) Create(ctx context.Context, req infer.CreateRequest[SetupKeyArg
86104
// Use CreateSetupKeyRequest for creation
87105
createReq := nbapi.CreateSetupKeyRequest{
88106
Name: req.Inputs.Name,
89-
Type: req.Inputs.Type,
107+
Type: string(req.Inputs.Type),
90108
ExpiresIn: req.Inputs.ExpiresIn,
91109
AutoGroups: req.Inputs.AutoGroups,
92110
UsageLimit: req.Inputs.UsageLimit,
@@ -148,7 +166,7 @@ func (*SetupKey) Read(ctx context.Context, setupKeyID string, state SetupKeyStat
148166
p.GetLogger(ctx).Debugf("Read:SetupKeyAPI name=%s, id=%s", setupKey.Name, setupKey.Id)
149167

150168
state.Name = setupKey.Name
151-
state.Type = setupKey.Type
169+
state.Type = SetupKeyType(setupKey.Type)
152170
state.AutoGroups = setupKey.AutoGroups
153171
state.UsageLimit = setupKey.UsageLimit
154172
ephemeral := setupKey.Ephemeral

sdk/go/netbird/resource/init.go

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)