-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathidentify_Resource_Provider.py
More file actions
46 lines (34 loc) · 1.43 KB
/
identify_Resource_Provider.py
File metadata and controls
46 lines (34 loc) · 1.43 KB
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
import re
def identify_resources_and_providers(terraform_content):
# Regular expression to find resource blocks
resource_pattern = r'resource\s+"(\w+)"\s+"(\w+)"'
resources = re.findall(resource_pattern, terraform_content)
# Regular expression to find provider blocks
#provider_pattern = r'provider\s+"(\w+)"'
#providers = re.findall(provider_pattern, terraform_content)
# Verificar se o resource começa com "google" e atribuir "GCP" ao provider
for resource_type, _ in resources:
if resource_type.startswith("google"):
provider=("GCP")
#print(f"provider: {provider}")
elif resource_type.startswith("azure"):
provider=("Azure")
elif resource_type.startswith("aws"):
provider=("AWS")
return resources, provider
# Read the content of the terraform file
def readTerraformFile(arquivo):
with open(arquivo, 'r') as file:
terraform_content = file.read()
return terraform_content
# Identify resources and provider
#resources, provider = identify_resources_and_providers(terraform_content)
# Print the identified resources
def printResources():
print("Resources:")
for resource_type, resource_name in resources:
print(f"Resource Type: {resource_type}, Resource Name: {resource_name}")
# Print the identified provider
def printProviders():
print("\nProviders:")
print(f"Provider: {provider}")