Skip to content

chore(provisioner/terraform): warn when agent dir breaks Desktop file sync - #24951

Closed
zenithwolf1000 wants to merge 1 commit into
mainfrom
chore/warn-dir-breaks-file-sync
Closed

zenithwolf1000 wants to merge 1 commit into
mainfrom
chore/warn-dir-breaks-file-sync

Conversation

@zenithwolf1000

Copy link
Copy Markdown
Collaborator

Emits a WARN-level build log when a coder_agent resource has dir set to a value other than $HOME or ~, because this breaks Coder Desktop file sync.

Refs DEVEX-227

A companion change to the coder_agent Terraform provider docs is at coder/terraform-provider-coder (to be submitted separately).

Implementation notes

The warning is emitted in server.Graph() after ConvertState() returns, which is the earliest point where agent attributes (including Directory) are available alongside the session's ProvisionLog sink. The check skips agents with an empty dir (the default) or values that expand to $HOME.

Generated by Coder Agents

@code-asher code-asher left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me.

If you want to add a test appending something like this to the others should work:

		{
			Name: "warn-agent-dir",
			Files: map[string]string{
				"main.tf": `terraform {
					required_providers {
						coder = {
							source  = "coder/coder"
							version = ">= 2.12.0"
						}
					}
				}
				resource "coder_agent" "dev" {
					os   = "windows"
					arch = "arm64"
					dir = "~/test"
				}
				resource "null_resource" "dev" {
					depends_on = [coder_agent.dev]
				}
				`,
			},
			Response: &proto.GraphComplete{
				Resources: []*proto.Resource{
					{
						Name: "dev",
						Type: "null_resource",
						Agents: []*proto.Agent{{
							Name:                     "dev",
							OperatingSystem:          "windows",
							Architecture:             "arm64",
							Directory:                "~/test",
							Auth:                     &proto.Agent_Token{},
							ConnectionTimeoutSeconds: 120,
							DisplayApps: &proto.DisplayApps{
								Vscode:               true,
								SshHelper:            true,
								PortForwardingHelper: true,
								WebTerminal:          true,
							},
							ResourcesMonitoring: &proto.ResourcesMonitoring{},
							ApiKeyScope: "all",
						}},
					},
				},
			},
			PlanExpectLogContains: "will break Coder Desktop file sync",
			SkipCacheProviders:    true,
		},

Comment on lines +280 to +281
"agent %q has 'dir' set to %q, which will break Coder Desktop file sync. "+
"Set 'dir' to a value that expands to the user's home directory or leave it unset.",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could see someone setting /home/coder for example and tripping this warning saying it will break, but then the next sentence says it will be fine (since it is the home dir).

idk if it is worth picking over the wording for the edge cases though lol

But we could say something like "may break file sync if it expands to a directory other than the user's home directory" or something.

Copy link
Copy Markdown
Collaborator Author

Closing in favor of the diag.Warn approach in the Terraform provider (coder/terraform-provider-coder#507), which surfaces the warning through Terraform's own output into Coder build logs without needing a separate server-side check.

Generated by Coder Agents

@github-actions
github-actions Bot deleted the chore/warn-dir-breaks-file-sync branch November 5, 2026 00:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants