Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
# v0.1.5

* `pytfe.__version__` added in src/pytfe/init.py via importlib.metadata.version("pytfe"). This will resolve to the version from pyproject.toml.
* Updated comments, sshkey, stateversion and cost-estimate models to have id as mandatory attribute by @isivaselvan [#137](https://github.com/hashicorp/python-tfe/pull/137)
* Updated workspace resource to include additional relationship models include AgentPool, Configuration-version, Run, Variables and State-version by @isivaselvan [#138](https://github.com/hashicorp/python-tfe/pull/138)

## Bug Fixes
* Run.read / Run.create fail with pydantic ValidationError when response has a `cost-estimate` and `comments` relationship.
Expand Down
2 changes: 1 addition & 1 deletion src/pytfe/models/ssh_key.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class SSHKey(BaseModel):

id: str = Field(..., description="The unique identifier for this SSH key")
type: str = Field(default="ssh-keys", description="The type of this resource")
name: str = Field(..., description="A name to identify the SSH key")
name: str = Field(default="", description="A name to identify the SSH key")


class SSHKeyCreateOptions(BaseModel):
Expand Down
2 changes: 1 addition & 1 deletion src/pytfe/models/state_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class StateVersion(BaseModel):
model_config = ConfigDict(populate_by_name=True, validate_by_name=True)

id: str = Field(..., alias="id")
created_at: datetime = Field(..., alias="created-at")
created_at: datetime | None = Field(None, alias="created-at")
hosted_state_download_url: str | None = Field(
None, alias="hosted-state-download-url"
)
Expand Down
14 changes: 10 additions & 4 deletions src/pytfe/models/workspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,13 @@
from ..utils import has_tags_regex_defined, is_valid_workspace_name, valid_string
from .agent import AgentPool
from .common import EffectiveTagBinding, Tag, TagBinding
from .configuration_version import ConfigurationVersion
from .data_retention_policy import DataRetentionPolicyChoice
from .organization import ExecutionMode, Organization
from .project import Project
from .ssh_key import SSHKey
from .state_version import StateVersion
from .variable import Variable

if TYPE_CHECKING:
from .run import Run
Expand Down Expand Up @@ -168,15 +172,17 @@ class Workspace(BaseModel):
# Relations
agent_pool: AgentPool | None = None # AgentPool object
current_run: Run | None = None # Run object
current_state_version: Any | None = None # StateVersion object
current_state_version: StateVersion | None = None # StateVersion object
organization: Organization | None = None
project: Project | None = None
ssh_key: Any | None = None # SSHKey object
ssh_key: SSHKey | None = None # SSHKey object
outputs: list[WorkspaceOutputs] = Field(default_factory=list)
tags: list[Tag] = Field(default_factory=list)
current_configuration_version: Any | None = None # ConfigurationVersion object
current_configuration_version: ConfigurationVersion | None = (
None # ConfigurationVersion object
)
locked_by: LockedByChoice | None = None
variables: list[Any] = Field(default_factory=list) # Variable objects
variables: list[Variable] = Field(default_factory=list) # Variable objects
tag_bindings: list[TagBinding] = Field(default_factory=list)
effective_tag_bindings: list[EffectiveTagBinding] = Field(default_factory=list)

Expand Down
34 changes: 33 additions & 1 deletion src/pytfe/resources/workspaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
from collections.abc import Iterator
from typing import Any

from pytfe.models.ssh_key import SSHKey

from ..errors import (
InvalidOrgError,
InvalidSSHKeyIDError,
Expand All @@ -19,11 +21,13 @@
WorkspaceMinimumLimitError,
WorkspaceRequiredError,
)
from ..models.agent import AgentPool
from ..models.common import (
EffectiveTagBinding,
Tag,
TagBinding,
)
from ..models.configuration_version import ConfigurationVersion
from ..models.data_retention_policy import (
DataRetentionPolicy,
DataRetentionPolicyChoice,
Expand All @@ -34,6 +38,9 @@
)
from ..models.organization import Organization
from ..models.project import Project
from ..models.run import Run
from ..models.state_version import StateVersion
from ..models.variable import Variable
from ..models.workspace import (
ExecutionMode,
LockedByChoice,
Expand Down Expand Up @@ -181,7 +188,32 @@ def _ws_from(d: dict[str, Any]) -> Workspace:
{"id": relationships["project"]["data"].get("id")}
)
if relationships.get("ssh-key", {}).get("data"):
attr["ssh_key"] = relationships["ssh-key"]["data"].get("id")
attr["ssh_key"] = SSHKey.model_validate(
{"id": relationships["ssh-key"]["data"].get("id")}
)
if relationships.get("agent-pool", {}).get("data"):
attr["agent_pools"] = AgentPool.model_validate(
{"id": relationships["agent-pool"]["data"].get("id")}
)
if relationships.get("current-run", {}).get("data"):
attr["current_run"] = Run.model_validate(
{"id": relationships["current-run"]["data"].get("id")}
)
if relationships.get("current-configuration-version", {}).get("data"):
attr["current_configuration_version"] = ConfigurationVersion.model_validate(
{"id": relationships["current-configuration-version"]["data"].get("id")}
)
if relationships.get("vars", {}).get("data"):
attr["variables"] = [
Variable.model_validate({"id": item.get("id")})
for item in relationships["vars"]["data"]
if item.get("id")
]
if relationships.get("current-state-version", {}).get("data"):
attr["current_state_version"] = StateVersion.model_validate(
{"id": relationships["current-state-version"]["data"].get("id")}
)

attr["outputs"] = outputs
attr["locked_by"] = locked_by
attr["data_retention_policy_choice"] = data_retention_policy_choice
Expand Down
Loading