forked from nhsy-hcp/terraform-gcp-runtask-budgets
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathterraformcloud.py
34 lines (25 loc) · 857 Bytes
/
terraformcloud.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
import requests
def download_json_plan(access_token: str, plan_json_api_url: str) -> dict:
"""
Download Terraform plan from TFC API
:param access_token: TFC API access token
:param plan_json_api_url: TFC JSON plan URL
:return: Terraform plan as dict
"""
headers = {
"Authorization": f"Bearer {access_token}",
"Content-Type": "application/vnd.api+json",
}
response = requests.get(plan_json_api_url, headers=headers)
# print(response.status_code)
# print(response.text)
if response.status_code == 200:
return response.json()
else:
return dict()
if __name__ == "__main__":
access_token = ""
plan_json_api_url = ""
plan_json = download_json_plan(access_token, plan_json_api_url)
import terraformplan
print(terraformplan.get_project_ids(plan_json))