From 89de01d48c1878982a7f56e436c8904bd3bc0a09 Mon Sep 17 00:00:00 2001 From: Louis Garman <75728+leg100@users.noreply.github.com> Date: Tue, 12 Sep 2023 19:10:00 +0100 Subject: [PATCH] fix: tfe_outputs resource (#599) Fixes #595 --- internal/state/tfe.go | 26 +++++++++++++++++++------- internal/tfeapi/types/workspace.go | 14 +++++++++++--- internal/workspace/tfe.go | 1 - 3 files changed, 30 insertions(+), 11 deletions(-) diff --git a/internal/state/tfe.go b/internal/state/tfe.go index f26e5e94c..a4b6b640d 100644 --- a/internal/state/tfe.go +++ b/internal/state/tfe.go @@ -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 } diff --git a/internal/tfeapi/types/workspace.go b/internal/tfeapi/types/workspace.go index 0fcc18186..187e724c6 100644 --- a/internal/tfeapi/types/workspace.go +++ b/internal/tfeapi/types/workspace.go @@ -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. diff --git a/internal/workspace/tfe.go b/internal/workspace/tfe.go index a62c085b4..924662169 100644 --- a/internal/workspace/tfe.go +++ b/internal/workspace/tfe.go @@ -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