Skip to content
Closed
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
911 changes: 133 additions & 778 deletions examples/project.py

Large diffs are not rendered by default.

10 changes: 6 additions & 4 deletions examples/variable_sets_example.py → examples/variable_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,8 @@
import os

from tfe import TFEClient, TFEConfig
from tfe.types import (
CategoryType,
from tfe.models import (
Parent,
Project,
VariableSetApplyToProjectsOptions,
VariableSetApplyToWorkspacesOptions,
VariableSetCreateOptions,
Expand All @@ -31,6 +29,10 @@
VariableSetVariableCreateOptions,
VariableSetVariableListOptions,
VariableSetVariableUpdateOptions,
)
from tfe.models.project import Project
from tfe.types import (
CategoryType,
Workspace,
)

Expand Down Expand Up @@ -271,7 +273,7 @@ def variable_set_example():

# 9. Read the variable set with includes
print("9. Reading variable set with includes...")
from tfe.types import VariableSetReadOptions
from tfe.models import VariableSetReadOptions

read_options = VariableSetReadOptions(
include=[VariableSetIncludeOpt.VARS, VariableSetIncludeOpt.WORKSPACES]
Expand Down
59 changes: 58 additions & 1 deletion src/tfe/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@
IngressAttributes,
)

# Re-export all project types
from .project import (
Project,
ProjectAddTagBindingsOptions,
ProjectCreateOptions,
ProjectListOptions,
ProjectUpdateOptions,
)

# Re-export all registry module types
from .registry_module_types import (
AgentExecutionMode,
Expand Down Expand Up @@ -63,6 +72,26 @@
RegistryProviderReadOptions,
)

# Re-export all variable set types
from .variable_set import (
Parent,
VariableSet,
VariableSetApplyToProjectsOptions,
VariableSetApplyToWorkspacesOptions,
VariableSetCreateOptions,
VariableSetIncludeOpt,
VariableSetListOptions,
VariableSetReadOptions,
VariableSetRemoveFromProjectsOptions,
VariableSetRemoveFromWorkspacesOptions,
VariableSetUpdateOptions,
VariableSetUpdateWorkspacesOptions,
VariableSetVariable,
VariableSetVariableCreateOptions,
VariableSetVariableListOptions,
VariableSetVariableUpdateOptions,
)

# Define what should be available when importing with *
__all__ = [
# Configuration version types
Expand All @@ -76,6 +105,12 @@
"ConfigurationVersionUpload",
"ConfigVerIncludeOpt",
"IngressAttributes",
# Project types
"Project",
"ProjectAddTagBindingsOptions",
"ProjectCreateOptions",
"ProjectListOptions",
"ProjectUpdateOptions",
# Registry module types
"AgentExecutionMode",
"Commit",
Expand Down Expand Up @@ -115,6 +150,29 @@
"RegistryProviderListOptions",
"RegistryProviderPermissions",
"RegistryProviderReadOptions",
# Project types
"Project",
"ProjectAddTagBindingsOptions",
"ProjectCreateOptions",
"ProjectListOptions",
"ProjectUpdateOptions",
# Variable set types
"Parent",
"VariableSet",
"VariableSetApplyToProjectsOptions",
"VariableSetApplyToWorkspacesOptions",
"VariableSetCreateOptions",
"VariableSetIncludeOpt",
"VariableSetListOptions",
"VariableSetReadOptions",
"VariableSetRemoveFromProjectsOptions",
"VariableSetRemoveFromWorkspacesOptions",
"VariableSetUpdateOptions",
"VariableSetUpdateWorkspacesOptions",
"VariableSetVariable",
"VariableSetVariableCreateOptions",
"VariableSetVariableListOptions",
"VariableSetVariableUpdateOptions",
# Main types from types.py (will be dynamically added below)
"Capacity",
"DataRetentionPolicy",
Expand All @@ -132,7 +190,6 @@
"OrganizationCreateOptions",
"OrganizationUpdateOptions",
"Pagination",
"Project",
"ReadRunQueueOptions",
"Run",
"RunQueue",
Expand Down
62 changes: 62 additions & 0 deletions src/tfe/models/project.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
"""Project-related types for the Terraform Cloud/Enterprise API.

This module contains all Pydantic models and types related to projects,
including the main Project model and all project-related option classes.
"""

from __future__ import annotations

from typing import Any

from pydantic import BaseModel, Field


class Project(BaseModel):
"""Project represents a Terraform Enterprise project"""

id: str
name: str | None = None
description: str = ""
organization: str | None = None
created_at: str = ""
updated_at: str = ""
workspace_count: int = 0
default_execution_mode: str = "remote"


class ProjectListOptions(BaseModel):
"""Options for listing projects"""

# Optional: String used to filter results by complete project name
name: str | None = None
# Optional: Query string to search projects by names
query: str | None = None
# Optional: Include related resources
include: list[str] | None = None
# Pagination options
page_number: int | None = None
page_size: int | None = None


class ProjectCreateOptions(BaseModel):
"""Options for creating a project"""

# Required: A name to identify the project
name: str
# Optional: A description for the project
description: str | None = None


class ProjectUpdateOptions(BaseModel):
"""Options for updating a project"""

# Optional: A name to identify the project
name: str | None = None
# Optional: A description for the project
description: str | None = None


class ProjectAddTagBindingsOptions(BaseModel):
"""Options for adding tag bindings to a project"""

tag_bindings: list[Any] = Field(default_factory=list)
162 changes: 162 additions & 0 deletions src/tfe/models/variable_set.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
"""Variable set type definitions for the TFE API."""

from __future__ import annotations

from datetime import datetime
from enum import Enum

from pydantic import BaseModel, Field

from ..types import CategoryType, Organization, Workspace
from .project import Project


class VariableSetIncludeOpt(str, Enum):
"""Include options for variable set operations."""

WORKSPACES = "workspaces"
PROJECTS = "projects"
VARS = "vars"
CURRENT_RUN = "current-run"


class Parent(BaseModel):
"""Parent represents the variable set's parent (organizations and projects are supported)."""

organization: Organization | None = None
project: Project | None = None


class VariableSet(BaseModel):
"""Represents a Terraform Enterprise variable set."""

id: str | None = None
name: str | None = None
description: str | None = None
global_: bool | None = Field(default=None, alias="global")
priority: bool | None = None
created_at: datetime | None = None
updated_at: datetime | None = None

# Relations
organization: Organization | None = None
workspaces: list[Workspace] = Field(default_factory=list)
projects: list[Project] = Field(default_factory=list)
vars: list[VariableSetVariable] = Field(default_factory=list)
parent: Parent | None = None


class VariableSetVariable(BaseModel):
"""Represents a variable within a variable set."""

id: str | None = None
key: str
value: str | None = None
description: str | None = None
category: CategoryType
hcl: bool | None = None
sensitive: bool | None = None
version_id: str | None = None

# Relations
variable_set: VariableSet | None = None


# Variable Set Options


class VariableSetListOptions(BaseModel):
"""Options for listing variable sets."""

# Pagination options
page_number: int | None = None
page_size: int | None = None
include: list[VariableSetIncludeOpt] | None = None
query: str | None = None # Filter by name


class VariableSetCreateOptions(BaseModel):
"""Options for creating a variable set."""

name: str
description: str | None = None
global_: bool = Field(alias="global")
priority: bool | None = None
parent: Parent | None = None


class VariableSetReadOptions(BaseModel):
"""Options for reading a variable set."""

include: list[VariableSetIncludeOpt] | None = None


class VariableSetUpdateOptions(BaseModel):
"""Options for updating a variable set."""

name: str | None = None
description: str | None = None
global_: bool | None = Field(alias="global", default=None)
priority: bool | None = None


class VariableSetApplyToWorkspacesOptions(BaseModel):
"""Options for applying a variable set to workspaces."""

workspaces: list[Workspace] = Field(default_factory=list)


class VariableSetRemoveFromWorkspacesOptions(BaseModel):
"""Options for removing a variable set from workspaces."""

workspaces: list[Workspace] = Field(default_factory=list)


class VariableSetApplyToProjectsOptions(BaseModel):
"""Options for applying a variable set to projects."""

projects: list[Project] = Field(default_factory=list)


class VariableSetRemoveFromProjectsOptions(BaseModel):
"""Options for removing a variable set from projects."""

projects: list[Project] = Field(default_factory=list)


class VariableSetUpdateWorkspacesOptions(BaseModel):
"""Options for updating workspaces associated with a variable set."""

workspaces: list[Workspace] = Field(default_factory=list)


# Variable Set Variable Options


class VariableSetVariableListOptions(BaseModel):
"""Options for listing variables in a variable set."""

# Pagination options
page_number: int | None = None
page_size: int | None = None


class VariableSetVariableCreateOptions(BaseModel):
"""Options for creating a variable in a variable set."""

key: str
value: str | None = None
description: str | None = None
category: CategoryType
hcl: bool | None = None
sensitive: bool | None = None


class VariableSetVariableUpdateOptions(BaseModel):
"""Options for updating a variable in a variable set."""

key: str | None = None
value: str | None = None
description: str | None = None
hcl: bool | None = None
sensitive: bool | None = None
Loading
Loading