|
| 1 | +package provider |
| 2 | + |
| 3 | +import ( |
| 4 | +"context" |
| 5 | + |
| 6 | +"github.com/google/uuid" |
| 7 | +"github.com/hashicorp/terraform-plugin-sdk/v2/diag" |
| 8 | +"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" |
| 9 | +) |
| 10 | + |
| 11 | +funcpoolResourceClaimResource()*schema.Resource { |
| 12 | +return&schema.Resource{ |
| 13 | +SchemaVersion:1, |
| 14 | + |
| 15 | +Description:"Use this resource to claim a resource pool entry.", |
| 16 | +CreateContext:func(_ context.Context,resourceData*schema.ResourceData,iinterface{}) diag.Diagnostics { |
| 17 | +resourceData.SetId(uuid.NewString()) |
| 18 | +returnnil |
| 19 | +}, |
| 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 | +// } |
| 31 | +returnnil |
| 32 | +}, |
| 33 | +DeleteContext:func(ctx context.Context,resourceData*schema.ResourceData,iinterface{}) diag.Diagnostics { |
| 34 | +returnnil |
| 35 | +}, |
| 36 | +Schema:map[string]*schema.Schema{ |
| 37 | +"pool_name": { |
| 38 | +Type:schema.TypeString, |
| 39 | +Required:true, |
| 40 | +ForceNew:true, |
| 41 | +Description:"The name of the pool from which an entry will be claimed.", |
| 42 | +}, |
| 43 | +"object_id": { |
| 44 | +Type:schema.TypeString, |
| 45 | +Computed:true, |
| 46 | +Description:"The object ID of the pooled entry resource", |
| 47 | +}, |
| 48 | +}, |
| 49 | +} |
| 50 | +} |
| 51 | + |
| 52 | +funcpoolResourceClaimableResource()*schema.Resource { |
| 53 | +return&schema.Resource{ |
| 54 | +SchemaVersion:1, |
| 55 | + |
| 56 | +Description:"Use this resource to specify which resources are claimable by workspaces.", |
| 57 | +CreateContext:func(_ context.Context,resourceData*schema.ResourceData,iinterface{}) diag.Diagnostics { |
| 58 | +resourceData.SetId(uuid.NewString()) |
| 59 | +returnnil |
| 60 | +}, |
| 61 | +ReadContext:func(ctx context.Context,resourceData*schema.ResourceData,iinterface{}) diag.Diagnostics { |
| 62 | +returnnil |
| 63 | +}, |
| 64 | +DeleteContext:func(ctx context.Context,resourceData*schema.ResourceData,iinterface{}) diag.Diagnostics { |
| 65 | +returnnil |
| 66 | +}, |
| 67 | +Schema:map[string]*schema.Schema{ |
| 68 | +"compute": { |
| 69 | +Type:schema.TypeSet, |
| 70 | +ForceNew:true, |
| 71 | +Optional:true, |
| 72 | +ConflictsWith: []string{"other"}, |
| 73 | +Elem:&schema.Resource{ |
| 74 | +Schema:map[string]*schema.Schema{ |
| 75 | +"instance_id": { |
| 76 | +Type:schema.TypeString, |
| 77 | +Description:"The ID of the compute instance (container/VM/etc).", |
| 78 | +ForceNew:true, |
| 79 | +Required:true, |
| 80 | +}, |
| 81 | +"agent_id": { |
| 82 | +Type:schema.TypeString, |
| 83 | +Description:"The ID of the agent running inside the compute instance.", |
| 84 | +ForceNew:true, |
| 85 | +Required:true, |
| 86 | +}, |
| 87 | +}, |
| 88 | +}, |
| 89 | +}, |
| 90 | +"other": { |
| 91 | +Type:schema.TypeString, |
| 92 | +ForceNew:true, |
| 93 | +Optional:true, |
| 94 | +}, |
| 95 | +}, |
| 96 | +} |
| 97 | +} |