Skip to content

Commit 4a6b28f

Browse files
authored
feat(provisioner): add support for workspace_owner_login_type (coder#15499)
- Adds support for the `coder_workspace_owner.login_type` attribute. - Adds a currently disabled test for `coder_workspace_owner.login_type`
1 parent 1c938cd commit 4a6b28f

File tree

7 files changed

+226
-160
lines changed

7 files changed

+226
-160
lines changed

coderd/provisionerdserver/provisionerdserver.go

+1
Original file line numberDiff line numberDiff line change
@@ -614,6 +614,7 @@ func (s *server) acquireProtoJob(ctx context.Context, job database.ProvisionerJo
614614
WorkspaceOwnerSshPublicKey: ownerSSHPublicKey,
615615
WorkspaceOwnerSshPrivateKey: ownerSSHPrivateKey,
616616
WorkspaceBuildId: workspaceBuild.ID.String(),
617+
WorkspaceOwnerLoginType: string(owner.LoginType),
617618
},
618619
LogLevel: input.LogLevel,
619620
},

coderd/provisionerdserver/provisionerdserver_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,7 @@ func TestAcquireJob(t *testing.T) {
377377
WorkspaceOwnerSshPublicKey: sshKey.PublicKey,
378378
WorkspaceOwnerSshPrivateKey: sshKey.PrivateKey,
379379
WorkspaceBuildId: build.ID.String(),
380+
WorkspaceOwnerLoginType: string(user.LoginType),
380381
},
381382
},
382383
})

provisioner/terraform/provision.go

+1
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,7 @@ func provisionEnv(
246246
"CODER_WORKSPACE_OWNER_GROUPS="+string(ownerGroups),
247247
"CODER_WORKSPACE_OWNER_SSH_PUBLIC_KEY="+metadata.GetWorkspaceOwnerSshPublicKey(),
248248
"CODER_WORKSPACE_OWNER_SSH_PRIVATE_KEY="+metadata.GetWorkspaceOwnerSshPrivateKey(),
249+
"CODER_WORKSPACE_OWNER_LOGIN_TYPE="+metadata.GetWorkspaceOwnerLoginType(),
249250
"CODER_WORKSPACE_ID="+metadata.GetWorkspaceId(),
250251
"CODER_WORKSPACE_OWNER_ID="+metadata.GetWorkspaceOwnerId(),
251252
"CODER_WORKSPACE_OWNER_SESSION_TOKEN="+metadata.GetWorkspaceOwnerSessionToken(),

provisioner/terraform/provision_test.go

+46
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,8 @@ func TestProvision(t *testing.T) {
383383
ExpectLogContains string
384384
// If Apply is true, then send an Apply request and check we get the same Resources as in Response.
385385
Apply bool
386+
// Some tests may need to be skipped until the relevant provider version is released.
387+
SkipReason string
386388
}{
387389
{
388390
Name: "missing-variable",
@@ -703,13 +705,57 @@ func TestProvision(t *testing.T) {
703705
}},
704706
},
705707
},
708+
{
709+
Name: "workspace-owner-login-type",
710+
SkipReason: "field will be added in provider version 1.1.0",
711+
Files: map[string]string{
712+
"main.tf": `terraform {
713+
required_providers {
714+
coder = {
715+
source = "coder/coder"
716+
version = "1.1.0"
717+
}
718+
}
719+
}
720+
721+
resource "null_resource" "example" {}
722+
data "coder_workspace_owner" "me" {}
723+
resource "coder_metadata" "example" {
724+
resource_id = null_resource.example.id
725+
item {
726+
key = "login_type"
727+
value = data.coder_workspace_owner.me.login_type
728+
}
729+
}
730+
`,
731+
},
732+
Request: &proto.PlanRequest{
733+
Metadata: &proto.Metadata{
734+
WorkspaceOwnerLoginType: "github",
735+
},
736+
},
737+
Response: &proto.PlanComplete{
738+
Resources: []*proto.Resource{{
739+
Name: "example",
740+
Type: "null_resource",
741+
Metadata: []*proto.Resource_Metadata{{
742+
Key: "login_type",
743+
Value: "github",
744+
}},
745+
}},
746+
},
747+
},
706748
}
707749

708750
for _, testCase := range testCases {
709751
testCase := testCase
710752
t.Run(testCase.Name, func(t *testing.T) {
711753
t.Parallel()
712754

755+
if testCase.SkipReason != "" {
756+
t.Skip(testCase.SkipReason)
757+
}
758+
713759
ctx, api := setupProvisioner(t, nil)
714760
sess := configure(ctx, t, api, &proto.Config{
715761
TemplateSourceArchive: makeTar(t, testCase.Files),

provisionersdk/proto/provisioner.pb.go

+172-160
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

provisionersdk/proto/provisioner.proto

+1
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,7 @@ message Metadata {
232232
string workspace_owner_ssh_public_key = 15;
233233
string workspace_owner_ssh_private_key = 16;
234234
string workspace_build_id = 17;
235+
string workspace_owner_login_type = 18;
235236
}
236237

237238
// Config represents execution configuration shared by all subsequent requests in the Session

site/e2e/provisionerGenerated.ts

+4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)