-
Notifications
You must be signed in to change notification settings - Fork 3
/
cleanup.py
63 lines (49 loc) · 1.78 KB
/
cleanup.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import asyncio
import uuid
import logging
import os
from workflows.destroy import DeprovisionInfraWorkflow
from shared.base import TerraformRunDetails, get_temporal_client, TEMPORAL_TASK_QUEUE
from temporalio.common import TypedSearchAttributes, SearchAttributeKey, \
SearchAttributePair
# Get the TF_VAR_prefix environment variable, defaulting to "temporal-sa" if not set
# NOTE: This is a specific env var for mat for Terraform.
TF_VAR_prefix = os.environ.get("TF_VAR_prefix", "temporal-sa")
async def main():
logging.basicConfig(level=logging.INFO)
# Get the Temporal client
client = await get_temporal_client()
# Set the directories for the Terraform configuration files
minikube_kuard_dir = "./terraform/minikube_kuard"
# Set the environment variables for Terraform
tcloud_env_vars = {
"TF_VAR_prefix": TF_VAR_prefix
}
# Generate unique IDs for the workflow
namespace_wf_id = f"deprovision-infra-{uuid.uuid4()}"
user_wf_id = f"deprovision-infra-{uuid.uuid4()}"
# Create the TerraformRunDetails object
tf_namespace_run_details = TerraformRunDetails(
id=namespace_wf_id,
env_vars=tcloud_env_vars,
directory=minikube_kuard_dir
)
# Define the search attributes for the workflow
provision_status_key = SearchAttributeKey.for_text("provisionStatus")
tf_directory_key = SearchAttributeKey.for_text("tfDirectory")
handle = await client.start_workflow(
DeprovisionInfraWorkflow.run,
tf_namespace_run_details,
id=namespace_wf_id,
task_queue=TEMPORAL_TASK_QUEUE,
search_attributes=TypedSearchAttributes([
SearchAttributePair(provision_status_key, ""),
SearchAttributePair(tf_directory_key, minikube_kuard_dir)
])
)
result = await handle.result()
# Print the result
print(f"Result: {result}")
if __name__ == "__main__":
# Run the main function
asyncio.run(main())