Skip to content

Commit 9619533

Browse files
authored
fix: Regenerate agent token on each run (#51)
This resolves a race condition where an old agent could be updated and connected to before the new agent was registered.
1 parent 00d1ef6 commit 9619533

File tree

3 files changed

+8
-2
lines changed

3 files changed

+8
-2
lines changed

Diff for: docs/resources/agent.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,6 @@ resource "kubernetes_pod" "dev" {
5555

5656
- `id` (String) The ID of this resource.
5757
- `init_script` (String) Run this script on startup of an instance to initialize the agent.
58-
- `token` (String) Set the environment variable "CODER_AGENT_TOKEN" with this token to authenticate an agent.
58+
- `token` (String, Sensitive) Set the environment variable "CODER_AGENT_TOKEN" with this token to authenticate an agent.
5959

6060

Diff for: docs/resources/metadata.md

+1
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ resource "coder_metadata" "pod_info" {
5656
### Optional
5757

5858
- `hide` (Boolean) Hide the resource from the UI.
59+
- `icon` (String) A URL to an icon that will display in the dashboard. View built-in icons here: https://github.com/coder/coder/tree/main/site/static/icon. Use a built-in icon with `data.coder_workspace.me.access_url + "/icons/<path>"`.
5960

6061
### Read-Only
6162

Diff for: internal/provider/provider.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,11 @@ func New() *schema.Provider {
213213
}
214214
return updateInitScript(resourceData, i)
215215
},
216-
ReadContext: func(c context.Context, resourceData *schema.ResourceData, i interface{}) diag.Diagnostics {
216+
ReadWithoutTimeout: func(c context.Context, resourceData *schema.ResourceData, i interface{}) diag.Diagnostics {
217+
err := resourceData.Set("token", uuid.NewString())
218+
if err != nil {
219+
return diag.FromErr(err)
220+
}
217221
return updateInitScript(resourceData, i)
218222
},
219223
DeleteContext: func(c context.Context, rd *schema.ResourceData, i interface{}) diag.Diagnostics {
@@ -267,6 +271,7 @@ func New() *schema.Provider {
267271
},
268272
"token": {
269273
ForceNew: true,
274+
Sensitive: true,
270275
Description: `Set the environment variable "CODER_AGENT_TOKEN" with this token to authenticate an agent.`,
271276
Type: schema.TypeString,
272277
Computed: true,

0 commit comments

Comments
 (0)