Skip to content

Commit 8bee515

Browse files
Merge branch 'next-0.1.1' into kshitija/WorkspaceRunTasksAndWorkspaceResources
2 parents 5de6bc7 + 2a6d5bc commit 8bee515

31 files changed

Lines changed: 3081 additions & 637 deletions

examples/agent.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -36,41 +36,41 @@ def main():
3636
address = os.environ.get("TFE_ADDRESS", "https://app.terraform.io")
3737

3838
if not token:
39-
print(" TFE_TOKEN environment variable is required")
39+
print(" TFE_TOKEN environment variable is required")
4040
return 1
4141

4242
if not org:
43-
print(" TFE_ORG environment variable is required")
43+
print(" TFE_ORG environment variable is required")
4444
return 1
4545

4646
# Create TFE client
4747
config = TFEConfig(token=token, address=address)
4848
client = TFEClient(config)
4949

50-
print(f"🔗 Connected to: {address}")
51-
print(f"🏢 Organization: {org}")
50+
print(f"Connected to: {address}")
51+
print(f" Organization: {org}")
5252

5353
try:
5454
# Example 1: Find agent pools to demonstrate agent operations
55-
print("\n📋 Finding agent pools...")
55+
print("\n Finding agent pools...")
5656
agent_pools = client.agent_pools.list(org)
5757

5858
# Convert to list to check if empty and get count
5959
pool_list = list(agent_pools)
6060
if not pool_list:
61-
print("⚠️ No agent pools found. Create an agent pool first.")
61+
print(" No agent pools found. Create an agent pool first.")
6262
return 1
6363

6464
print(f"Found {len(pool_list)} agent pools:")
6565
for pool in pool_list:
6666
print(f" - {pool.name} (ID: {pool.id}, Agents: {pool.agent_count})")
6767

6868
# Example 2: List agents in each pool
69-
print("\n🤖 Listing agents in each pool...")
69+
print("\n Listing agents in each pool...")
7070
total_agents = 0
7171

7272
for pool in pool_list:
73-
print(f"\n📂 Agents in pool '{pool.name}':")
73+
print(f"\n Agents in pool '{pool.name}':")
7474

7575
# Use optional parameters for listing
7676
list_options = AgentListOptions(page_size=10) # Optional parameter
@@ -91,35 +91,35 @@ def main():
9191
# Example 3: Read detailed agent information
9292
try:
9393
agent_details = client.agents.read(agent.id)
94-
print(" Agent details retrieved successfully")
94+
print(" Agent details retrieved successfully")
9595
print(f" Full name: {agent_details.name or 'Unnamed'}")
9696
print(f" Current status: {agent_details.status}")
9797
except NotFound:
98-
print(" ⚠️ Agent details not accessible")
98+
print(" Agent details not accessible")
9999
except Exception as e:
100-
print(f" Error reading agent details: {e}")
100+
print(f" Error reading agent details: {e}")
101101

102102
print("")
103103
else:
104104
print(" No agents found in this pool")
105105

106106
if total_agents == 0:
107-
print("\n⚠️ No agents found in any pools.")
107+
print("\n No agents found in any pools.")
108108
print("To see agents in action:")
109109
print("1. Create an agent pool")
110110
print("2. Run a Terraform Enterprise agent binary connected to the pool")
111111
print("3. Run this example again")
112112
else:
113-
print(f"\n📊 Total agents found across all pools: {total_agents}")
113+
print(f"\n Total agents found across all pools: {total_agents}")
114114

115-
print("\n🎉 Agent operations completed successfully!")
115+
print("\n Agent operations completed successfully!")
116116
return 0
117117

118118
except NotFound as e:
119-
print(f" Resource not found: {e}")
119+
print(f" Resource not found: {e}")
120120
return 1
121121
except Exception as e:
122-
print(f" Error: {e}")
122+
print(f" Error: {e}")
123123
return 1
124124

125125

examples/agent_pool.py

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -39,23 +39,23 @@ def main():
3939
address = os.environ.get("TFE_ADDRESS", "https://app.terraform.io")
4040

4141
if not token:
42-
print(" TFE_TOKEN environment variable is required")
42+
print(" TFE_TOKEN environment variable is required")
4343
return 1
4444

4545
if not org:
46-
print(" TFE_ORG environment variable is required")
46+
print(" TFE_ORG environment variable is required")
4747
return 1
4848

4949
# Create TFE client
5050
config = TFEConfig(token=token, address=address)
5151
client = TFEClient(config=config)
5252

53-
print(f"🔗 Connected to: {address}")
54-
print(f"🏢 Organization: {org}")
53+
print(f"Connected to: {address}")
54+
print(f" Organization: {org}")
5555

5656
try:
5757
# Example 1: List existing agent pools
58-
print("\n📋 Listing existing agent pools...")
58+
print("\n Listing existing agent pools...")
5959
list_options = AgentPoolListOptions(page_size=10) # Optional parameters
6060
agent_pools = client.agent_pools.list(org, options=list_options)
6161

@@ -66,7 +66,7 @@ def main():
6666
print(f" - {pool.name} (ID: {pool.id}, Agents: {pool.agent_count})")
6767

6868
# Example 2: Create a new agent pool
69-
print("\n🆕 Creating a new agent pool...")
69+
print("\n Creating a new agent pool...")
7070
unique_name = f"sdk-example-pool-{uuid.uuid4().hex[:8]}"
7171

7272
create_options = AgentPoolCreateOptions(
@@ -76,39 +76,39 @@ def main():
7676
)
7777

7878
new_pool = client.agent_pools.create(org, create_options)
79-
print(f"Created agent pool: {new_pool.name} (ID: {new_pool.id})")
79+
print(f"Created agent pool: {new_pool.name} (ID: {new_pool.id})")
8080

8181
# Example 3: Read the agent pool
82-
print("\n📖 Reading agent pool details...")
82+
print("\n Reading agent pool details...")
8383
pool_details = client.agent_pools.read(new_pool.id)
8484
print(f" Name: {pool_details.name}")
8585
print(f" Organization Scoped: {pool_details.organization_scoped}")
8686
print(f" Policy: {pool_details.allowed_workspace_policy}")
8787
print(f" Agent Count: {pool_details.agent_count}")
8888

8989
# Example 4: Update the agent pool
90-
print("\n✏️ Updating agent pool...")
90+
print("\n Updating agent pool...")
9191
update_options = AgentPoolUpdateOptions(
9292
name=f"{unique_name}-updated",
9393
organization_scoped=False, # Making this optional parameter different
9494
)
9595

9696
updated_pool = client.agent_pools.update(new_pool.id, update_options)
97-
print(f"Updated agent pool name to: {updated_pool.name}")
97+
print(f"Updated agent pool name to: {updated_pool.name}")
9898

9999
# Example 5: Create an agent token
100-
print("\n🔑 Creating agent token...")
100+
print("\n Creating agent token...")
101101
token_options = AgentTokenCreateOptions(
102102
description="SDK example token" # Optional description
103103
)
104104

105105
agent_token = client.agent_tokens.create(new_pool.id, token_options)
106-
print(f"Created agent token: {agent_token.id}")
106+
print(f"Created agent token: {agent_token.id}")
107107
if agent_token.token:
108108
print(f" Token (first 10 chars): {agent_token.token[:10]}...")
109109

110110
# Example 6: List agent tokens
111-
print("\n📝 Listing agent tokens...")
111+
print("\n Listing agent tokens...")
112112
tokens = client.agent_tokens.list(new_pool.id)
113113

114114
# Convert to list to get count and iterate
@@ -120,19 +120,19 @@ def main():
120120
# Example 7: Clean up - delete the token and pool
121121
print("\n🧹 Cleaning up...")
122122
client.agent_tokens.delete(agent_token.id)
123-
print("Deleted agent token")
123+
print("Deleted agent token")
124124

125125
client.agent_pools.delete(new_pool.id)
126-
print("Deleted agent pool")
126+
print("Deleted agent pool")
127127

128-
print("\n🎉 Agent pool operations completed successfully!")
128+
print("\n Agent pool operations completed successfully!")
129129
return 0
130130

131131
except NotFound as e:
132-
print(f" Resource not found: {e}")
132+
print(f" Resource not found: {e}")
133133
return 1
134134
except Exception as e:
135-
print(f" Error: {e}")
135+
print(f" Error: {e}")
136136
return 1
137137

138138

0 commit comments

Comments
 (0)