Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit7f0dab9

Browse files
committed
Inject instance IDs in by pool name
Signed-off-by: Danny Kopping <danny@coder.com>
1 parent058bb74 commit7f0dab9

File tree

1 file changed

+36
-15
lines changed

1 file changed

+36
-15
lines changed

‎provider/pool_resource_claim.go

Lines changed: 36 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@ package provider
22

33
import (
44
"context"
5+
"crypto/sha1"
6+
"encoding/base32"
7+
"fmt"
58

9+
"github.com/coder/terraform-provider-coder/provider/helpers"
610
"github.com/google/uuid"
711
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
812
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
@@ -15,22 +19,28 @@ func poolResourceClaimResource() *schema.Resource {
1519
Description:"Use this resource to claim a resource pool entry.",
1620
CreateContext:func(_ context.Context,resourceData*schema.ResourceData,iinterface{}) diag.Diagnostics {
1721
resourceData.SetId(uuid.NewString())
22+
23+
pool:=resourceData.Get("pool_name").(string)
24+
25+
// SHA-1 because Base32/64 produces an invalid env infix
26+
poolName:=sha1.Sum([]byte(pool))
27+
key:=fmt.Sprintf("CODER_RESOURCEPOOL_%x_ENTRY_INSTANCE_ID",poolName)
28+
instanceId,err:=helpers.RequireEnv(key)
29+
iferr!=nil {
30+
returndiag.Errorf("failed to get instance ID: %s",err.Error())
31+
}
32+
decoded,err:=base32.StdEncoding.DecodeString(instanceId)
33+
iferr!=nil {
34+
returndiag.Errorf("failed to decode instance ID %q: %s",instanceId,err.Error())
35+
}
36+
_=resourceData.Set("instance_id",string(decoded))
37+
1838
returnnil
1939
},
20-
ReadContext:func(ctx context.Context,resourceData*schema.ResourceData,iinterface{}) diag.Diagnostics {
21-
// poolb64 := base64.StdEncoding.EncodeToString([]byte(resourceData.Get("pool_name").(string)))
22-
// key := fmt.Sprintf("CODER_RESOURCE_POOL_%s_ENTRY_OBJECT_ID", poolb64)
23-
// objectId, err := helpers.RequireEnv(key)
24-
// if err != nil {
25-
// return diag.Errorf("resource pool entry object ID not found in env %q: %s", key, err)
26-
// }
27-
//
28-
// if err = resourceData.Set("object_id", objectId); err != nil {
29-
// return diag.Errorf("failed to set resource pool entry object ID: %s", err)
30-
// }
40+
ReadContext:func(ctx context.Context,data*schema.ResourceData,iinterface{}) diag.Diagnostics {
3141
returnnil
3242
},
33-
DeleteContext:func(ctx context.Context,resourceData*schema.ResourceData,iinterface{}) diag.Diagnostics {
43+
DeleteContext:func(ctx context.Context,data*schema.ResourceData,iinterface{}) diag.Diagnostics {
3444
returnnil
3545
},
3646
Schema:map[string]*schema.Schema{
@@ -40,10 +50,10 @@ func poolResourceClaimResource() *schema.Resource {
4050
ForceNew:true,
4151
Description:"The name of the pool from which an entry will be claimed.",
4252
},
43-
"object_id": {
53+
"instance_id": {
4454
Type:schema.TypeString,
4555
Computed:true,
46-
Description:"Theobject ID of the pooled entry resource",
56+
Description:"Theinstance ID of the pooled entry resource",
4757
},
4858
},
4959
}
@@ -88,9 +98,20 @@ func poolResourceClaimableResource() *schema.Resource {
8898
},
8999
},
90100
"other": {
91-
Type:schema.TypeString,
101+
Type:schema.TypeSet,
92102
ForceNew:true,
93103
Optional:true,
104+
105+
Elem:&schema.Resource{
106+
Schema:map[string]*schema.Schema{
107+
"instance_id": {
108+
Type:schema.TypeString,
109+
Description:"The ID of the instance.",
110+
ForceNew:true,
111+
Required:true,
112+
},
113+
},
114+
},
94115
},
95116
},
96117
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp