Skip to content

Commit 55d2af4

Browse files
committed
Merge remote-tracking branch 'origin/main' into stevenmasley/use_static_as_dynamic
2 parents 005a084 + 35a04c7 commit 55d2af4

22 files changed

+228
-119
lines changed

cli/ssh.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ func (r *RootCmd) ssh() *serpent.Command {
9292
Annotations: workspaceCommand,
9393
Use: "ssh <workspace>",
9494
Short: "Start a shell into a workspace",
95+
Long: "This command does not have full parity with the standard SSH command. For users who need the full functionality of SSH, create an ssh configuration with `coder config-ssh`.",
9596
Middleware: serpent.Chain(
9697
serpent.RequireNArgs(1),
9798
r.InitClient(client),

cli/testdata/coder_ssh_--help.golden

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ USAGE:
55

66
Start a shell into a workspace
77

8+
This command does not have full parity with the standard SSH command. For
9+
users who need the full functionality of SSH, create an ssh configuration with
10+
`coder config-ssh`.
11+
812
OPTIONS:
913
--disable-autostart bool, $CODER_SSH_DISABLE_AUTOSTART (default: false)
1014
Disable starting the workspace automatically when connecting via SSH.

coderd/coderd.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1774,6 +1774,7 @@ func (api *API) CreateInMemoryTaggedProvisionerDaemon(dialCtx context.Context, n
17741774
logger := api.Logger.Named(fmt.Sprintf("inmem-provisionerd-%s", name))
17751775
srv, err := provisionerdserver.NewServer(
17761776
api.ctx, // use the same ctx as the API
1777+
daemon.APIVersion,
17771778
api.AccessURL,
17781779
daemon.ID,
17791780
defaultOrg.ID,

coderd/database/dbgen/dbgen.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import (
2929
"github.com/coder/coder/v2/coderd/rbac"
3030
"github.com/coder/coder/v2/codersdk"
3131
"github.com/coder/coder/v2/cryptorand"
32+
"github.com/coder/coder/v2/provisionerd/proto"
3233
"github.com/coder/coder/v2/testutil"
3334
)
3435

@@ -1000,10 +1001,11 @@ func TemplateVersionTerraformValues(t testing.TB, db database.Store, orig databa
10001001
t.Helper()
10011002

10021003
params := database.InsertTemplateVersionTerraformValuesByJobIDParams{
1003-
JobID: takeFirst(orig.JobID, uuid.New()),
1004-
CachedPlan: takeFirstSlice(orig.CachedPlan, []byte("{}")),
1005-
CachedModuleFiles: orig.CachedModuleFiles,
1006-
UpdatedAt: takeFirst(orig.UpdatedAt, dbtime.Now()),
1004+
JobID: takeFirst(orig.JobID, uuid.New()),
1005+
CachedPlan: takeFirstSlice(orig.CachedPlan, []byte("{}")),
1006+
CachedModuleFiles: orig.CachedModuleFiles,
1007+
UpdatedAt: takeFirst(orig.UpdatedAt, dbtime.Now()),
1008+
ProvisionerdVersion: takeFirst(orig.ProvisionerdVersion, proto.CurrentVersion.String()),
10071009
}
10081010

10091011
err := db.InsertTemplateVersionTerraformValuesByJobID(genCtx, params)

coderd/database/dbmem/dbmem.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9343,10 +9343,11 @@ func (q *FakeQuerier) InsertTemplateVersionTerraformValuesByJobID(_ context.Cont
93439343

93449344
// Insert the new row
93459345
row := database.TemplateVersionTerraformValue{
9346-
TemplateVersionID: templateVersion.ID,
9347-
CachedPlan: arg.CachedPlan,
9348-
CachedModuleFiles: arg.CachedModuleFiles,
9349-
UpdatedAt: arg.UpdatedAt,
9346+
TemplateVersionID: templateVersion.ID,
9347+
UpdatedAt: arg.UpdatedAt,
9348+
CachedPlan: arg.CachedPlan,
9349+
CachedModuleFiles: arg.CachedModuleFiles,
9350+
ProvisionerdVersion: arg.ProvisionerdVersion,
93509351
}
93519352
q.templateVersionTerraformValues = append(q.templateVersionTerraformValues, row)
93529353
return nil

coderd/database/dump.sql

Lines changed: 4 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ALTER TABLE template_version_terraform_values DROP COLUMN provisionerd_version;
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
ALTER TABLE template_version_terraform_values ADD COLUMN IF NOT EXISTS provisionerd_version TEXT NOT NULL DEFAULT '';
2+
3+
COMMENT ON COLUMN template_version_terraform_values.provisionerd_version IS
4+
'What version of the provisioning engine was used to generate the cached plan and module files.';

coderd/database/models.go

Lines changed: 2 additions & 0 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: 12 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/database/queries/templateversionterraformvalues.sql

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,14 @@ INSERT INTO
1212
template_version_id,
1313
cached_plan,
1414
cached_module_files,
15-
updated_at
15+
updated_at,
16+
provisionerd_version
1617
)
1718
VALUES
1819
(
1920
(select id from template_versions where job_id = @job_id),
2021
@cached_plan,
2122
@cached_module_files,
22-
@updated_at
23+
@updated_at,
24+
@provisionerd_version
2325
);

coderd/files/overlay.go

Lines changed: 17 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,12 @@ import (
44
"io/fs"
55
"path"
66
"strings"
7-
8-
"golang.org/x/xerrors"
97
)
108

11-
// overlayFS allows you to "join" together the template files tar file fs.FS
12-
// with the Terraform modules tar file fs.FS. We could potentially turn this
13-
// into something more parameterized/configurable, but the requirements here are
14-
// a _bit_ odd, because every file in the modulesFS includes the
15-
// .terraform/modules/ folder at the beginning of it's path.
9+
// overlayFS allows you to "join" together multiple fs.FS. Files in any specific
10+
// overlay will only be accessible if their path starts with the base path
11+
// provided for the overlay. eg. An overlay at the path .terraform/modules
12+
// should contain files with paths inside the .terraform/modules folder.
1613
type overlayFS struct {
1714
baseFS fs.FS
1815
overlays []Overlay
@@ -23,64 +20,32 @@ type Overlay struct {
2320
fs.FS
2421
}
2522

26-
func NewOverlayFS(baseFS fs.FS, overlays []Overlay) (fs.FS, error) {
27-
if err := valid(baseFS); err != nil {
28-
return nil, xerrors.Errorf("baseFS: %w", err)
29-
}
30-
31-
for _, overlay := range overlays {
32-
if err := valid(overlay.FS); err != nil {
33-
return nil, xerrors.Errorf("overlayFS: %w", err)
34-
}
35-
}
36-
23+
func NewOverlayFS(baseFS fs.FS, overlays []Overlay) fs.FS {
3724
return overlayFS{
3825
baseFS: baseFS,
3926
overlays: overlays,
40-
}, nil
27+
}
4128
}
4229

43-
func (f overlayFS) Open(p string) (fs.File, error) {
30+
func (f overlayFS) target(p string) fs.FS {
31+
target := f.baseFS
4432
for _, overlay := range f.overlays {
4533
if strings.HasPrefix(path.Clean(p), overlay.Path) {
46-
return overlay.FS.Open(p)
34+
target = overlay.FS
35+
break
4736
}
4837
}
49-
return f.baseFS.Open(p)
38+
return target
5039
}
5140

52-
func (f overlayFS) ReadDir(p string) ([]fs.DirEntry, error) {
53-
for _, overlay := range f.overlays {
54-
if strings.HasPrefix(path.Clean(p), overlay.Path) {
55-
//nolint:forcetypeassert
56-
return overlay.FS.(fs.ReadDirFS).ReadDir(p)
57-
}
58-
}
59-
//nolint:forcetypeassert
60-
return f.baseFS.(fs.ReadDirFS).ReadDir(p)
41+
func (f overlayFS) Open(p string) (fs.File, error) {
42+
return f.target(p).Open(p)
6143
}
6244

63-
func (f overlayFS) ReadFile(p string) ([]byte, error) {
64-
for _, overlay := range f.overlays {
65-
if strings.HasPrefix(path.Clean(p), overlay.Path) {
66-
//nolint:forcetypeassert
67-
return overlay.FS.(fs.ReadFileFS).ReadFile(p)
68-
}
69-
}
70-
//nolint:forcetypeassert
71-
return f.baseFS.(fs.ReadFileFS).ReadFile(p)
45+
func (f overlayFS) ReadDir(p string) ([]fs.DirEntry, error) {
46+
return fs.ReadDir(f.target(p), p)
7247
}
7348

74-
// valid checks that the fs.FS implements the required interfaces.
75-
// The fs.FS interface is not sufficient.
76-
func valid(fsys fs.FS) error {
77-
_, ok := fsys.(fs.ReadDirFS)
78-
if !ok {
79-
return xerrors.New("overlayFS does not implement ReadDirFS")
80-
}
81-
_, ok = fsys.(fs.ReadFileFS)
82-
if !ok {
83-
return xerrors.New("overlayFS does not implement ReadFileFS")
84-
}
85-
return nil
49+
func (f overlayFS) ReadFile(p string) ([]byte, error) {
50+
return fs.ReadFile(f.target(p), p)
8651
}

coderd/files/overlay_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,10 @@ func TestOverlayFS(t *testing.T) {
2121
afero.WriteFile(b, ".terraform/modules/modules.json", []byte("{}"), 0o644)
2222
afero.WriteFile(b, ".terraform/modules/example_module/main.tf", []byte("terraform {}"), 0o644)
2323

24-
it, err := files.NewOverlayFS(afero.NewIOFS(a), []files.Overlay{{
24+
it := files.NewOverlayFS(afero.NewIOFS(a), []files.Overlay{{
2525
Path: ".terraform/modules",
2626
FS: afero.NewIOFS(b),
2727
}})
28-
require.NoError(t, err)
2928

3029
content, err := fs.ReadFile(it, "main.tf")
3130
require.NoError(t, err)

coderd/parameters.go

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"golang.org/x/sync/errgroup"
1414
"golang.org/x/xerrors"
1515

16+
"github.com/coder/coder/v2/apiversion"
1617
"github.com/coder/coder/v2/coderd/database"
1718
"github.com/coder/coder/v2/coderd/database/dbauthz"
1819
"github.com/coder/coder/v2/coderd/files"
@@ -84,7 +85,7 @@ func (api *API) templateVersionDynamicParameters(rw http.ResponseWriter, r *http
8485
result, diagnostics := render(ctx, map[string]string{})
8586
response := codersdk.DynamicParametersResponse{
8687
ID: -1,
87-
Diagnostics: previewtypes.Diagnostics(diagnostics),
88+
Diagnostics: previewtypes.Diagnostics(diagnostics.Extend(staticDiagnostics)),
8889
}
8990
if result != nil {
9091
response.Parameters = result.Parameters
@@ -111,7 +112,7 @@ func (api *API) templateVersionDynamicParameters(rw http.ResponseWriter, r *http
111112
result, diagnostics := render(ctx, update.Inputs)
112113
response := codersdk.DynamicParametersResponse{
113114
ID: update.ID,
114-
Diagnostics: previewtypes.Diagnostics(diagnostics),
115+
Diagnostics: previewtypes.Diagnostics(diagnostics.Extend(staticDiagnostics)),
115116
}
116117
if result != nil {
117118
response.Parameters = result.Parameters
@@ -337,3 +338,31 @@ func getWorkspaceOwnerData(
337338
Groups: groupNames,
338339
}, nil
339340
}
341+
342+
// parameterProvisionerVersionDiagnostic checks the version of the provisioner
343+
// used to create the template version. If the version is less than 1.5, it
344+
// returns a warning diagnostic. Only versions 1.5+ return the module & plan data
345+
// required.
346+
func parameterProvisionerVersionDiagnostic(tf database.TemplateVersionTerraformValue) hcl.Diagnostics {
347+
missingMetadata := hcl.Diagnostic{
348+
Severity: hcl.DiagError,
349+
Summary: "This template version is missing required metadata to support dynamic parameters. Go back to the classic creation flow.",
350+
Detail: "To restore full functionality, please re-import the terraform as a new template version.",
351+
}
352+
353+
if tf.ProvisionerdVersion == "" {
354+
return hcl.Diagnostics{&missingMetadata}
355+
}
356+
357+
major, minor, err := apiversion.Parse(tf.ProvisionerdVersion)
358+
if err != nil || tf.ProvisionerdVersion == "" {
359+
return hcl.Diagnostics{&missingMetadata}
360+
} else if major < 1 || (major == 1 && minor < 5) {
361+
missingMetadata.Detail = "This template version does not support dynamic parameters. " +
362+
"Some options may be missing or incorrect. " +
363+
"Please contact an administrator to update the provisioner and re-import the template version."
364+
return hcl.Diagnostics{&missingMetadata}
365+
}
366+
367+
return nil
368+
}

0 commit comments

Comments
 (0)