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

Commit

Permalink
fix: tfe_outputs resource (#599)
Browse files Browse the repository at this point in the history
Fixes #595
  • Loading branch information
leg100 committed Sep 12, 2023
1 parent 518452e commit 89de01d
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 11 deletions.
26 changes: 19 additions & 7 deletions internal/state/tfe.go
Original file line number Diff line number Diff line change
Expand Up @@ -388,14 +388,26 @@ func (a *tfe) includeWorkspaceCurrentOutputs(ctx context.Context, v any) ([]any,
if err != nil {
return nil, err
}
var include []any
include := make([]any, len(sv.Outputs))
// TODO: we both include the full output types and populate the list of IDs
// in ws.Outputs, but really the latter should *always* be populated, and
// that should be the responsibility of the workspace pkg. To avoid an
// import cycle, perhaps the workspace SQL queries could return a list of
// output IDs.
ws.Outputs = make([]*types.WorkspaceOutput, len(sv.Outputs))
var i int
for _, from := range sv.Outputs {
// scrub sensitive values for included outputs
to := a.toOutput(from, true)
include = append(include, to)
ws.Outputs = append(ws.Outputs, &types.StateVersionOutput{
ID: to.ID,
})
include[i] = &types.WorkspaceOutput{
ID: from.ID,
Name: from.Name,
Sensitive: from.Sensitive,
Type: from.Type,
Value: from.Value,
}
ws.Outputs[i] = &types.WorkspaceOutput{
ID: from.ID,
}
i++
}
return include, nil
}
14 changes: 11 additions & 3 deletions internal/tfeapi/types/workspace.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,17 @@ type Workspace struct {
TagNames []string `jsonapi:"attribute" json:"tag-names"`

// Relations
CurrentRun *Run `jsonapi:"relationship" json:"current-run"`
Organization *Organization `jsonapi:"relationship" json:"organization"`
Outputs []*StateVersionOutput `jsonapi:"relationship" json:"outputs"`
CurrentRun *Run `jsonapi:"relationship" json:"current-run"`
Organization *Organization `jsonapi:"relationship" json:"organization"`
Outputs []*WorkspaceOutput `jsonapi:"relationship" json:"outputs"`
}

type WorkspaceOutput struct {
ID string `jsonapi:"primary,workspace-outputs"`
Name string `jsonapi:"attribute" json:"name"`
Sensitive bool `jsonapi:"attribute" json:"sensitive"`
Type string `jsonapi:"attribute" json:"output-type"`
Value any `jsonapi:"attribute" json:"value"`
}

// WorkspaceList represents a list of workspaces.
Expand Down
1 change: 0 additions & 1 deletion internal/workspace/tfe.go
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,6 @@ func (a *tfe) convert(from *Workspace, r *http.Request) (*types.Workspace, error
TagNames: from.Tags,
UpdatedAt: from.UpdatedAt,
Organization: &types.Organization{Name: from.Organization},
Outputs: []*types.StateVersionOutput{},
}
if len(from.TriggerPrefixes) > 0 || len(from.TriggerPatterns) > 0 {
to.FileTriggersEnabled = true
Expand Down

0 comments on commit 89de01d

Please sign in to comment.