Skip to content
This repository has been archived by the owner on Dec 26, 2023. It is now read-only.

Commit

Permalink
fix: handle run-events request from terraform cloud backend (#534)
Browse files Browse the repository at this point in the history
`terraform plan|apply` as of v1.5 sends a request to
`/api/v2/runs/<run_id>/run-events` if using the `cloud` backend. OTF did
not handle this request and hence terraform would error with `resource
not found`.

This PR stubs this endpoint, returning an empty response, which works
around the issue.

(Run events would usually be warnings about various policy issues OTF
doesn't implement anyway).
  • Loading branch information
leg100 committed Jul 25, 2023
1 parent 1979294 commit b1998bd
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
10 changes: 10 additions & 0 deletions internal/api/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ func (a *api) addRunHandlers(r *mux.Router) {

// Apply routes
r.HandleFunc("/applies/{apply_id}", a.getApply).Methods("GET")

// Run events routes
r.HandleFunc("/runs/{id}/run-events", a.listRunEvents).Methods("GET")
}

func (a *api) createRun(w http.ResponseWriter, r *http.Request) {
Expand Down Expand Up @@ -421,3 +424,10 @@ func (a *api) watchRun(w http.ResponseWriter, r *http.Request) {
flusher.Flush()
}
}

// OTF doesn't implement run events but as of terraform v1.5, the cloud backend
// makes a call to this endpoint. OTF therefore stubs this endpoint and sends an
// empty response, to avoid sending a 404 response and triggering an error.
func (a *api) listRunEvents(w http.ResponseWriter, r *http.Request) {
a.writeResponse(w, r, []*types.RunEvent{})
}
25 changes: 25 additions & 0 deletions internal/api/types/run_event.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0

package types

import "time"

// RunEventList represents a list of run events.
type RunEventList struct {
// Pagination is not supported by the API
*Pagination
Items []*RunEvent
}

// RunEvent represents a Terraform Enterprise run event.
type RunEvent struct {
ID string `jsonapi:"primary,run-events"`
Action string `jsonapi:"attr,action"`
CreatedAt time.Time `jsonapi:"attr,created-at,iso8601"`
Description string `jsonapi:"attr,description"`

// Relations - Note that `target` is not supported yet
Actor *User `jsonapi:"relation,actor"`
// Comment *Comment `jsonapi:"relation,comment"`
}

0 comments on commit b1998bd

Please sign in to comment.