Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 578eb11

Browse files
committed
Update Terraform provider to use relative path
1 parent e3ff8ad commit 578eb11

File tree

15 files changed

+216
-187
lines changed

15 files changed

+216
-187
lines changed

coderd/coderd.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,11 @@ import (
3434

3535
// Options are requires parameters for Coder to start.
3636
type Options struct {
37-
AccessURL *url.URL
38-
Logger slog.Logger
39-
Database database.Store
40-
Pubsub database.Pubsub
37+
AccessURL *url.URL
38+
WildcardURL *url.URL
39+
Logger slog.Logger
40+
Database database.Store
41+
Pubsub database.Pubsub
4142

4243
AgentConnectionUpdateFrequency time.Duration
4344
// APIRateLimit is the minutely throughput rate limit per user or ip.

coderd/database/databasefake/databasefake.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1533,13 +1533,14 @@ func (q *fakeQuerier) InsertWorkspaceApp(_ context.Context, arg database.InsertW
15331533
defer q.mutex.Unlock()
15341534

15351535
workspaceApp := database.WorkspaceApp{
1536-
ID: arg.ID,
1537-
AgentID: arg.AgentID,
1538-
CreatedAt: arg.CreatedAt,
1539-
Name: arg.Name,
1540-
Icon: arg.Icon,
1541-
Command: arg.Command,
1542-
Target: arg.Target,
1536+
ID: arg.ID,
1537+
AgentID: arg.AgentID,
1538+
CreatedAt: arg.CreatedAt,
1539+
Name: arg.Name,
1540+
Icon: arg.Icon,
1541+
Command: arg.Command,
1542+
Url: arg.Url,
1543+
RelativePath: arg.RelativePath,
15431544
}
15441545
q.workspaceApps = append(q.workspaceApps, workspaceApp)
15451546
return workspaceApp, nil

coderd/database/dump.sql

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/database/migrations/000011_workspace_apps.up.sql renamed to coderd/database/migrations/000014_workspace_apps.up.sql

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,9 @@ CREATE TABLE workspace_apps (
44
agent_id uuid NOT NULL REFERENCES workspace_agents (id) ON DELETE CASCADE,
55
name varchar(64) NOT NULL,
66
icon varchar(256) NOT NULL,
7-
-- A command to run when opened.
87
command varchar(65534),
9-
-- A URL or port to target.
10-
target varchar(65534),
8+
url varchar(65534),
9+
relative_path boolean NOT NULL DEFAULT false,
1110
PRIMARY KEY (id),
1211
UNIQUE(agent_id, name)
1312
);

coderd/database/models.go

Lines changed: 8 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/database/queries.sql.go

Lines changed: 21 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/database/queries/workspaceapps.sql

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ INSERT INTO
1313
name,
1414
icon,
1515
command,
16-
target
16+
url,
17+
relative_path
1718
)
1819
VALUES
19-
($1, $2, $3, $4, $5, $6, $7) RETURNING *;
20+
($1, $2, $3, $4, $5, $6, $7, $8) RETURNING *;

coderd/provisionerdaemons.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -665,10 +665,11 @@ func insertWorkspaceResource(ctx context.Context, db database.Store, jobID uuid.
665665
String: app.Command,
666666
Valid: app.Command != "",
667667
},
668-
Target: sql.NullString{
669-
String: app.Target,
670-
Valid: app.Target != "",
668+
Url: sql.NullString{
669+
String: app.Url,
670+
Valid: app.Url != "",
671671
},
672+
RelativePath: app.RelativePath,
672673
})
673674
if err != nil {
674675
return xerrors.Errorf("insert app: %w", err)

coderd/workspaceagents.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -462,11 +462,11 @@ func convertApps(dbApps []database.WorkspaceApp) []codersdk.WorkspaceApp {
462462
apps := make([]codersdk.WorkspaceApp, 0)
463463
for _, dbApp := range dbApps {
464464
apps = append(apps, codersdk.WorkspaceApp{
465-
ID: dbApp.ID,
466-
Name: dbApp.Name,
467-
Command: dbApp.Command.String,
468-
Target: dbApp.Target.String,
469-
Icon: dbApp.Icon,
465+
ID: dbApp.ID,
466+
Name: dbApp.Name,
467+
Command: dbApp.Command.String,
468+
AccessURL: dbApp.Url.String,
469+
Icon: dbApp.Icon,
470470
})
471471
}
472472
return apps

codersdk/workspaceapps.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,14 @@ package codersdk
33
import "github.com/google/uuid"
44

55
type WorkspaceApp struct {
6-
ID uuid.UUID `json:"id"`
7-
Name string `json:"name"`
8-
Command string `json:"command,omitempty"`
9-
Target string `json:"target,omitempty"`
10-
Icon string `json:"icon"`
6+
ID uuid.UUID `json:"id"`
7+
// Name is a unique identifier attached to an agent.
8+
Name string `json:"name"`
9+
Command string `json:"command,omitempty"`
10+
// AccessURL is an address used to access the application.
11+
// If command is specified, this will be omitted.
12+
AccessURL string `json:"access_url,omitempty"`
13+
// Icon is a relative path or external URL that specifies
14+
// an icon to be displayed in the dashboard.
15+
Icon string `json:"icon"`
1116
}

provisioner/terraform/provision.go

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -523,11 +523,12 @@ func parseTerraformApply(ctx context.Context, terraform *tfexec.Terraform, state
523523
}
524524

525525
type appAttributes struct {
526-
AgentID string `mapstructure:"agent_id"`
527-
Name string `mapstructure:"name"`
528-
Icon string `mapstructure:"icon"`
529-
Target string `mapstructure:"target"`
530-
Command string `mapstructure:"command"`
526+
AgentID string `mapstructure:"agent_id"`
527+
Name string `mapstructure:"name"`
528+
Icon string `mapstructure:"icon"`
529+
URL string `mapstructure:"url"`
530+
Command string `mapstructure:"command"`
531+
RelativePath bool `mapstructure:"relative_path"`
531532
}
532533
// Associate Apps with agents.
533534
for _, resource := range state.Values.RootModule.Resources {
@@ -548,10 +549,11 @@ func parseTerraformApply(ctx context.Context, terraform *tfexec.Terraform, state
548549
continue
549550
}
550551
agent.Apps = append(agent.Apps, &proto.App{
551-
Name: attrs.Name,
552-
Command: attrs.Command,
553-
Target: attrs.Target,
554-
Icon: attrs.Icon,
552+
Name: attrs.Name,
553+
Command: attrs.Command,
554+
Url: attrs.URL,
555+
Icon: attrs.Icon,
556+
RelativePath: attrs.RelativePath,
555557
})
556558
}
557559
}

provisioner/terraform/provision_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ terraform {
3030
required_providers {
3131
coder = {
3232
source = "coder/coder"
33-
version = "0.4.0"
33+
version = "0.4.2"
3434
}
3535
}
3636
}

0 commit comments

Comments
 (0)