feat: Add Terraform Provider for agent resources (#368)

* ci: Update DataDog GitHub branch to fallback to GITHUB_REF

This was detecting branches, but not our "main" branch before.
Hopefully this fixes it!

* Add basic Terraform Provider

* Rename post files to upload

* Add tests for resources

* Skip instance identity test

* Add tests for ensuring agent get's passed through properly

* Fix linting errors

* Add echo path

* Fix agent authentication

* Update codersdk/files.go

Co-authored-by: Bryan <bryan@coder.com>

Co-authored-by: Bryan <bryan@coder.com>
This commit is contained in:
Kyle Carberry
2022-02-28 17:16:44 +00:00
committed by GitHub
co-authored by Bryan
parent 512e239835
commit 35ae532f7c
18 changed files with 1273 additions and 212 deletions
+2 -2
View File
@@ -116,9 +116,9 @@ func New(options *Options) (http.Handler, func()) {
})
})
r.Route("/files", func(r chi.Router) {
r.Route("/upload", func(r chi.Router) {
r.Use(httpmw.ExtractAPIKey(options.Database, nil))
r.Post("/", api.postFiles)
r.Post("/", api.postUpload)
})
r.Route("/projectimport/{organization}", func(r chi.Router) {
+1 -1
View File
@@ -18,7 +18,7 @@ type UploadFileResponse struct {
Hash string `json:"hash"`
}
func (api *api) postFiles(rw http.ResponseWriter, r *http.Request) {
func (api *api) postUpload(rw http.ResponseWriter, r *http.Request) {
apiKey := httpmw.APIKey(r)
contentType := r.Header.Get("Content-Type")
+1 -1
View File
@@ -10,7 +10,7 @@ import (
"github.com/coder/coder/codersdk"
)
func TestPostFiles(t *testing.T) {
func TestPostUpload(t *testing.T) {
t.Parallel()
t.Run("BadContentType", func(t *testing.T) {
t.Parallel()
+10 -6
View File
@@ -516,16 +516,20 @@ func (server *provisionerdServer) CompleteJob(ctx context.Context, completed *pr
}
// This could be a bulk insert to improve performance.
for _, protoResource := range jobType.WorkspaceProvision.Resources {
var instanceID sql.NullString
if protoResource.Agent != nil && protoResource.Agent.GetGoogleInstanceIdentity() != nil {
instanceID = sql.NullString{
String: protoResource.Agent.GetGoogleInstanceIdentity().InstanceId,
Valid: true,
}
}
_, err = db.InsertWorkspaceResource(ctx, database.InsertWorkspaceResourceParams{
ID: uuid.New(),
CreatedAt: database.Now(),
WorkspaceHistoryID: input.WorkspaceHistoryID,
InstanceID: sql.NullString{
Valid: protoResource.InstanceId != "",
String: protoResource.InstanceId,
},
Type: protoResource.Type,
Name: protoResource.Name,
Type: protoResource.Type,
Name: protoResource.Name,
InstanceID: instanceID,
// TODO: Generate this at the variable validation phase.
// Set the value in `default_source`, and disallow overwrite.
WorkspaceAgentToken: uuid.NewString(),
+9 -3
View File
@@ -74,9 +74,15 @@ func TestPostWorkspaceAgentAuthenticateGoogleInstanceIdentity(t *testing.T) {
Type: &proto.Provision_Response_Complete{
Complete: &proto.Provision_Complete{
Resources: []*proto.Resource{{
Name: "somename",
Type: "someinstance",
InstanceId: instanceID,
Name: "somename",
Type: "someinstance",
Agent: &proto.Agent{
Auth: &proto.Agent_GoogleInstanceIdentity{
GoogleInstanceIdentity: &proto.GoogleInstanceIdentityAuth{
InstanceId: instanceID,
},
},
},
}},
},
},