diff --git a/.github/workflows/integration-test.yml b/.github/workflows/integration-test.yml new file mode 100644 index 0000000..91901e3 --- /dev/null +++ b/.github/workflows/integration-test.yml @@ -0,0 +1,195 @@ +name: SDK Integration Tests + +on: + push: + branches: + - main + pull_request: + branches: + - main + workflow_dispatch: + +jobs: + unit-tests: + name: Unit Tests + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: "3.11" + + - name: Install dependencies + run: make dev-install + + - name: Run format check + run: make fmt-check + + - name: Run lint + run: make lint + + - name: Run unit tests + run: make type-check && .venv/bin/python -m pytest -v tests/ + + integration-tests: + name: Integration Tests (Example Files) + runs-on: ubuntu-latest + needs: unit-tests # only runs if unit tests pass + + env: + TFE_TOKEN: ${{ secrets.TFE_TOKEN }} + TFE_ORG: ${{ secrets.TFE_ORG }} + TFE_ADDRESS: ${{ secrets.TFE_ADDRESS }} + TFE_WORKSPACE_ID: ${{ secrets.TFE_WORKSPACE_ID }} + TFE_WORKSPACE_NAME: ${{ secrets.TFE_WORKSPACE_NAME }} + TFE_TEAM_ID: ${{ secrets.TFE_TEAM_ID }} + TFE_RUN_ID: ${{ secrets.TFE_RUN_ID }} + TFE_APPLY_ID: ${{ secrets.TFE_APPLY_ID }} + TFE_PLAN_ID: ${{ secrets.TFE_PLAN_ID }} + TFE_TASK_STAGE_ID: ${{ secrets.TFE_TASK_STAGE_ID }} + TFE_POLICY_SET_ID: ${{ secrets.TFE_POLICY_SET_ID }} + TFE_POLICY_NAME: ${{ secrets.TFE_POLICY_NAME }} + TFE_REG_PROV_NS: ${{ secrets.TFE_REG_PROV_NS }} + TFE_REG_PROV_NAME: ${{ secrets.TFE_REG_PROV_NAME }} + SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }} + OAUTH_CLIENT_GITHUB_TOKEN: ${{ secrets.OAUTH_CLIENT_GITHUB_TOKEN }} + WEBHOOK_URL: ${{ secrets.WEBHOOK_URL }} + TEAMS_WEBHOOK_URL: ${{ secrets.TEAMS_WEBHOOK_URL }} + TEST_MEMBER_EMAIL: ${{ secrets.TEST_MEMBER_EMAIL }} + TEAM_MEMBERSHIP_ID: ${{secretS.TEAM_MEBERSHIP_ID}} + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: "3.11" + + - name: Install dependencies + run: make dev-install + + - name: agent.py + run: .venv/bin/python examples/agent.py + + - name: agent_pool.py + run: .venv/bin/python examples/agent_pool.py + + - name: apply.py + if: ${{ env.TFE_APPLY_ID != '' }} + run: .venv/bin/python examples/apply.py --apply-id "$TFE_APPLY_ID" + + - name: configuration_version.py + if: ${{ env.TFE_WORKSPACE_ID != '' }} + run: .venv/bin/python examples/configuration_version.py + + - name: notification_configuration.py + if: ${{ env.TFE_WORKSPACE_ID != '' || env.TFE_WORKSPACE_NAME != '' }} + run: .venv/bin/python examples/notification_configuration.py + + - name: oauth_client.py + run: .venv/bin/python examples/oauth_client.py + + - name: oauth_token.py + run: .venv/bin/python examples/oauth_token.py + + - name: org.py + run: .venv/bin/python examples/org.py + + - name: organization_membership.py + run: .venv/bin/python examples/organization_membership.py + + - name: plan.py + if: ${{ env.TFE_PLAN_ID != '' }} + run: .venv/bin/python examples/plan.py --plan-id "$TFE_PLAN_ID" + + - name: policy_check.py + if: ${{ env.TFE_RUN_ID != '' }} + run: .venv/bin/python examples/policy_check.py --run-id "$TFE_RUN_ID" + + - name: policy_evaluation.py + if: ${{ env.TFE_TASK_STAGE_ID != '' }} + run: .venv/bin/python examples/policy_evaluation.py --task-stage-id "$TFE_TASK_STAGE_ID" + + - name: policy_set_parameter.py + if: ${{ env.TFE_POLICY_SET_ID != '' }} + run: .venv/bin/python examples/policy_set_parameter.py --policy-set-id "$TFE_POLICY_SET_ID" + + - name: policy_set.py + run: .venv/bin/python examples/policy_set.py --org "$TFE_ORG" + + - name: policy.py + if: ${{ env.TFE_POLICY_NAME != '' }} + run: .venv/bin/python examples/policy.py --org "$TFE_ORG" --policy-name "$TFE_POLICY_NAME" + + - name: project.py + run: .venv/bin/python examples/project.py --list --organization "$TFE_ORG" + + - name: query_run.py + if: ${{ env.TFE_WORKSPACE_NAME != '' }} + run: .venv/bin/python examples/query_run.py + + - name: registry_module.py + run: .venv/bin/python examples/registry_module.py + + - name: registry_provider_version.py + if: ${{ env.TFE_REG_PROV_NS != '' && env.TFE_REG_PROV_NAME != '' }} + run: | + .venv/bin/python examples/registry_provider_version.py \ + --organization "$TFE_ORG" \ + --namespace "$TFE_REG_PROV_NS" \ + --name "$TFE_REG_PROV_NAME" + + - name: registry_provider.py + run: .venv/bin/python examples/registry_provider.py + + - name: reserved_tag_key.py + run: .venv/bin/python examples/reserved_tag_key.py + + - name: run_events.py + if: ${{ env.TFE_RUN_ID != '' }} + run: .venv/bin/python examples/run_events.py --run-id "$TFE_RUN_ID" + + - name: run_task.py + run: .venv/bin/python examples/run_task.py --org "$TFE_ORG" + + - name: run_trigger.py + run: .venv/bin/python examples/run_trigger.py --org "$TFE_ORG" + + - name: run.py + run: .venv/bin/python examples/run.py --organization "$TFE_ORG" + + - name: ssh_keys.py + if: ${{ env.SSH_PRIVATE_KEY != '' }} + run: .venv/bin/python examples/ssh_keys.py + + - name: state_versions.py + if: ${{ env.TFE_WORKSPACE_ID != '' && env.TFE_WORKSPACE_NAME != '' }} + run: | + .venv/bin/python examples/state_versions.py \ + --org "$TFE_ORG" \ + --workspace "$TFE_WORKSPACE_NAME" \ + --workspace-id "$TFE_WORKSPACE_ID" + + - name: variable_sets.py + run: .venv/bin/python examples/variable_sets.py + + - name: variables.py + if: ${{ env.TFE_WORKSPACE_ID != '' }} + run: .venv/bin/python examples/variables.py + + - name: workspace_resources.py + if: ${{ env.TFE_WORKSPACE_ID != '' }} + run: | + .venv/bin/python examples/workspace_resources.py \ + --list \ + --workspace-id "$TFE_WORKSPACE_ID" \ + --page-size 10 + + - name: workspace.py + run: .venv/bin/python examples/workspace.py --org "$TFE_ORG" --list diff --git a/Makefile b/Makefile index 8eb5654..91d61b8 100644 --- a/Makefile +++ b/Makefile @@ -70,4 +70,4 @@ clean: find . -type d -name ".ruff_cache" -exec rm -rf {} + rm -rf build/ dist/ $(VENV) -all: clean dev-install fmt lint test +all: clean dev-install fmt lint test \ No newline at end of file diff --git a/examples/configuration_version.py b/examples/configuration_version.py index b894c11..72d03bf 100644 --- a/examples/configuration_version.py +++ b/examples/configuration_version.py @@ -178,7 +178,7 @@ def main(): # Initialize the TFE client client = TFEClient(TFEConfig.from_env()) - workspace_id = "ws-zLgDCHFz9mBfri2Q" # Replace with your workspace ID + workspace_id = os.getenv("TFE_WORKSPACE_ID") # Replace with your workspace ID # Variables to store created resources for dependent tests created_cv_id = None diff --git a/examples/notification_configuration.py b/examples/notification_configuration.py index 07e1b85..178c130 100644 --- a/examples/notification_configuration.py +++ b/examples/notification_configuration.py @@ -37,8 +37,8 @@ def main(): # Resolve organization and workspace from environment variables org_name = os.environ["TFE_ORG"] - workspace_name = os.getenv("TFE_WORKSPACE_NAME", "test-api") - workspace_id = os.getenv("TFE_WORKSPACE_ID", "") + workspace_name = os.getenv("TFE_WORKSPACE_NAME") + workspace_id = os.getenv("TFE_WORKSPACE_ID") if not workspace_id: print(f"Looking up workspace '{workspace_name}' in org '{org_name}'...") ws = client.workspaces.read(workspace_name, organization=org_name) @@ -46,7 +46,7 @@ def main(): print(f"Resolved workspace ID: {workspace_id}") print(f"Using workspace: {workspace_name} (ID: {workspace_id})") - team_id = os.getenv("TFE_TEAM_ID", "team-example123456789") + team_id = os.getenv("TFE_TEAM_ID") if team_id == "team-example123456789": print("Using fake team ID for demonstration (teams may require paid plan)") else: diff --git a/examples/oauth_client.py b/examples/oauth_client.py index 5e2ba07..1e39a1c 100644 --- a/examples/oauth_client.py +++ b/examples/oauth_client.py @@ -64,7 +64,7 @@ def main(): # Initialize the TFE client client = TFEClient(TFEConfig.from_env()) - organization_name = "aayush-test" # Replace with your organization + organization_name = os.getenv("TFE_ORG") # Variables to store created resources for dependent tests created_oauth_client = None diff --git a/examples/organization_membership.py b/examples/organization_membership.py index d93071c..1b7c332 100644 --- a/examples/organization_membership.py +++ b/examples/organization_membership.py @@ -14,6 +14,7 @@ python examples/organization_membership.py """ +import os import sys from pytfe import TFEClient @@ -28,7 +29,8 @@ def main(): """Demonstrate organization membership list functionality.""" - organization_name = "aayush-test" + organization_name = os.getenv("TFE_ORG") + team_id = os.getenv("TFE_TEAM_ID") # Initialize the client (reads TFE_TOKEN and TFE_ADDRESS from environment) try: @@ -272,13 +274,13 @@ def main(): from pytfe.models import OrganizationMembershipCreateOptions, Team # Replace with a valid email for your organization - new_member_email = "sivaselvan.i@hashicorp.com" + new_member_email = os.getenv("TEST_MEMBER_EMAIL") # Create membership with teams (uncomment to use) from pytfe.models import OrganizationAccess team = Team( - id="team-dx24FR9xQUuwNTHA", + id=team_id, organization_access=OrganizationAccess(read_workspaces=True), ) # Replace with actual team ID create_options = OrganizationMembershipCreateOptions( @@ -300,7 +302,9 @@ def main(): try: from pytfe.errors import NotFound - membership_id = "ou-9mG77c6uE5GScg9k" # Replace with actual membership ID + membership_id = os.getenv( + "TFE_MEMBERSHIP_ID" + ) # Replace with actual membership ID print(f"Attempting to delete membership: {membership_id}") client.organization_memberships.delete(membership_id) diff --git a/examples/query_run.py b/examples/query_run.py index 1007dcc..5019543 100644 --- a/examples/query_run.py +++ b/examples/query_run.py @@ -37,8 +37,8 @@ def get_client_and_workspace(): """Initialize client and get workspace ID.""" client = TFEClient(TFEConfig.from_env()) - organization = os.getenv("TFE_ORG", "aayush-test") - workspace_name = "query-test" # Default workspace for testing + organization = os.getenv("TFE_ORG") + workspace_name = os.getenv("TFE_WORKSPACE_NAME") # Default workspace for testing # Get workspace workspace = client.workspaces.read(workspace_name, organization=organization) diff --git a/examples/registry_provider.py b/examples/registry_provider.py index ee6b569..e4de81d 100644 --- a/examples/registry_provider.py +++ b/examples/registry_provider.py @@ -40,7 +40,7 @@ def get_client_and_org(): """Initialize client and get organization name.""" client = TFEClient() - organization_name = os.getenv("TFE_ORGANIZATION", "aayush-test") + organization_name = os.environ["TFE_ORG"] return client, organization_name diff --git a/examples/variables.py b/examples/variables.py index bc723b9..f5d5ca6 100644 --- a/examples/variables.py +++ b/examples/variables.py @@ -25,7 +25,9 @@ def main(): client = TFEClient(TFEConfig.from_env()) # Replace this with your actual workspace ID - workspace_id = "ws-example123456789" # Get this from your TFE workspace + workspace_id = os.environ.get( + "TFE_WORKSPACE_ID" + ) # Get this from your TFE workspace print(f"Testing all variable operations in workspace: {workspace_id}") print("=" * 60)