Skip to content

Workspace is not built from "included" values, such as workspace outputs #134

Description

@matthewmi

When I request a workspace with values to include, in my case workspace outputs, the outputs are all None

workspace = tfe.workspaces.read_with_options(
    workspace=workspace_name,
    organization=tfe_org,
    options=WorkspaceReadOptions(include=[WorkspaceIncludeOpt.OUTPUTS])
)

The resulting workspace object is not created using the included data, and in my case all my output values on the workspace are None.

workspace.outputs
[WorkspaceOutputs(id='wsout-K2PT7yGGgaNJbEJ8', name=None, sensitive=False, output_type=None, value=None), 
WorkspaceOutputs(id='wsout-TSRRHnWJaLaKa9MU', name=None, sensitive=False, output_type=None, value=None)]

Looking at the code the issue appears to be here

ws = _ws_from(r.json()["data"])

as we are only passing the "data" part of the response to the function that creates the models.

ws = _ws_from(r.json()["data"])

The data portion of the API response only contains the references to the outputs

{
    "data": {
          ## ...<unrelated-keys-removed>
            "outputs": {
                "data": [
                    {"id": "wsout-K2PT7yGGgaNJbEJ8", "type": "workspace-outputs"},
                    {"id": "wsout-TSRRHnWJaLaKa9MU", "type": "workspace-outputs"},
                    {"id": "wsout-LfSQ2wUe9LZCenLj", "type": "workspace-outputs"},
                    {"id": "wsout-RvQjoj3NEr9Ug2qa", "type": "workspace-outputs"},
                    {"id": "wsout-PhGb76PKoQmWvdua", "type": "workspace-outputs"},

Where as the requested "include" values (in this case the workspace outputs) are listed under
r.json()["included"]

    "data": <data section as above>
    "included": [
        {
            "id": "wsout-K2PT7yGGgaNJbEJ8",
            "type": "workspace-outputs",
            "attributes": {
                "name": "<actual-output-name>",
                "value": "<actual-output-value>",
                "sensitive": False,
                "output-type": "string",
                "workspace-attributes": {
                    "id": "ws-8swGiw8wu6xKWbV9",
                    "name": "<actual-value>",
                },
                "organization-attributes": {
                    "id": "org-wMbe3eSP72XGUULw",
                    "name": "<actual-value>",
                },
                "detailed-type": "string",
            },
        },

So it appears that the full response from the API should be used to build the models and not just the "data" portion of the request. The shape of the data is documented here https://developer.hashicorp.com/terraform/cloud-docs/api-docs#inclusion-of-related-resources

Metadata

Metadata

Labels

bugSomething isn't working

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions