Skip to content

feat(agent): plumb Terraform resource address for script unit names#26463

Draft
SasSwart wants to merge 1 commit into
sas/script-unitsfrom
sas/script-resource-address
Draft

feat(agent): plumb Terraform resource address for script unit names#26463
SasSwart wants to merge 1 commit into
sas/script-unitsfrom
sas/script-resource-address

Conversation

@SasSwart

Copy link
Copy Markdown
Contributor

Follow-up to #26459. Plumbs the Terraform resource address through the full pipeline so the script runner can use it as a unique, human-friendly sync unit identifier.

Problem

#26459 used DisplayName as the sync unit name, which is not guaranteed unique and was also not being set in the agent manifest (pre-existing bug in dbAgentScriptToProto).

Changes

Adds resource_address across every layer:

Layer File Change
Provisioner proto provisionersdk/proto/provisioner.proto Add resource_address field 10 to Script
Terraform provisioner/terraform/resources.go Populate from resource.Address (e.g. module.dev.coder_script.install_tools)
Database migration 000526 Add resource_address column to workspace_agent_scripts
Provisioner server coderd/provisionerdserver/ Plumb through agentScriptsParams and INSERT
Agent proto agent/proto/agent.proto Add resource_address field 11 to WorkspaceAgentScript
Manifest coderd/agentapi/manifest.go Fix: add missing DisplayName mapping (pre-existing bug) + add ResourceAddress
SDK codersdk/workspaceagents.go, agentsdk/convert.go Add field to type and both conversion functions
REST API coderd/database/db2sdk/ Add field mapping
Script runner agent/agentscripts/agentscripts.go scriptUnitName() prefers ResourceAddress, falls back to DisplayName

The Terraform resource address is available from tfjson.StateResource.Address without any Terraform provider changes. For multi-module setups, addresses look like module.dev_setup.coder_script.install_tools, providing both uniqueness and readability.

Generated by Coder Agents on behalf of @SasSwart

The script runner now registers each script as a sync unit during
Init() so all scripts are immediately visible via 'coder exp sync list'.
As each script executes, its unit status transitions from pending to
started, then to completed.

Changes:
- agent/agentsocket/server.go: NewServer takes *unit.Manager as a
  required parameter instead of creating its own internally.
- agent/agentscripts/agentscripts.go: Options gains a UnitManager field.
  Init() registers scripts using DisplayName as the unit ID.
  run() sets unit status to started before execution and completed after.
- agent/agent.go: Creates a shared unit.Manager and passes it to both
  the script runner and the socket server.
- Tests: Updated NewServer call sites; added TestScriptUnitsRegistered
  and TestScriptUnitsLifecycle.
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.

1 participant