<commit_before>#! /usr/local/bin/python3
"""
Magic Modules Terraform Scripts testing(helper) tool!

Job of this script to convert .tf into .erb & .yaml file.

## How to use this script?

1. Download this script. Make this scrpt executeable & `pip3 install termcolor`
2. run shell command `./convert2erb.py <....tf file>`
3. Output .erb file is generated from the location where script is executed!
4. Output .erb file will have same name as .tf file (for test.tf, output file is test.tf.erb)

Example:
```
# Download this script to required location
# run - `chmod +x convert2erb.py`
# run - `pip3 install termcolor`. We use pkg this for erros highlighting in terminal!

# example - generating .erb * .yaml
bash$ ./convert2erb.py external_http_lb_mig_backend_custom_header.tf
```
"""
import os
import sys
import re
import logging
from termcolor import colored, cprint


tf_lines = []
resource_lines = []
resource_name_lines = []
resource_regex_pattern = 'resource\s*"([\w, -]+)"\s*"([\w, -]+)"'
resource_name_regex_pattern = 'name\s*=\s*"([\w, -]+)"'
resource_types, resource_tfnames, resource_names = [], [], []

# yaml templates
template_header = """
        name: "{}"<commit_msg>Tweaked the instructions slightly<commit_after>#! /usr/local/bin/python3
"""
Magic Modules Terraform Scripts testing(helper) tool!

Job of this script to convert .tf into .erb & .yaml file.

## How to use this script?

1. Download this script.
2. Make this scrpt executeable: `chmod +x convert2erb.py`.
3. Run `pip3 install termcolor`.
4. Run the script: `./convert2erb.py <filename>.tf`
5. Output .erb file is generated from the location where script is executed!
6. Output .erb file will have same name as .tf file (for test.tf, output file is test.tf.erb)
7. Output terraform.yaml_check file contains content that you can add to your
   product's terraform.yaml file.


Example:
```
# Download this script to required location
# run - `chmod +x convert2erb.py`
# run - `pip3 install termcolor`. We use pkg this for erros highlighting in terminal!

# example - generating .erb * .yaml
bash$ ./convert2erb.py external_http_lb_mig_backend_custom_header.tf
```
"""
import os
import sys
import re
import logging
from termcolor import colored, cprint


tf_lines = []
resource_lines = []
resource_name_lines = []
resource_regex_pattern = 'resource\s*"([\w, -]+)"\s*"([\w, -]+)"'
resource_name_regex_pattern = 'name\s*=\s*"([\w, -]+)"'
resource_types, resource_tfnames, resource_names = [], [], []

# yaml templates
template_header = """
        name: "{}"
{'fraction_non_alphanumeric': 0.1314127861089187, 'fraction_numerical': 0.009471191791633781, 'mean_word_length': 4.22680412371134, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2703506', 'n_tokens_mistral': 842, 'n_tokens_neox': 816, 'n_words': 285}