public static string ConvertToTerraform()

in Webapp/SDAF/Controllers/Helper.cs [81:115]


        public static string ConvertToTerraform<T>(T model)
        {
            string modelType = (model.GetType() == typeof(LandscapeModel)) ? "Landscape" : "System";
            string path = $"ParameterDetails/{modelType}Template.txt";

            if (!System.IO.File.Exists(path))
            {
                return $"Error generating terraform variables file: No template file {path} was found";
            }

            StringBuilder stringBuilder = new();

            foreach (string line in System.IO.File.ReadLines(path))
            {
                string lineToAdd = line;
                Regex paramRegex = new(@"\$\$\w*\$\$");

                if (paramRegex.IsMatch(line))
                {
                    string parameter = paramRegex.Match(line).Value.Trim('$');
                    PropertyInfo property = model.GetType().GetProperty(parameter);
                    if (property == null)
                    {
                        lineToAdd = "#" + parameter + " = null";
                    }
                    else
                    {
                        lineToAdd = WriteTfLine(property, model);
                    }
                }
                stringBuilder.AppendLine(lineToAdd);
            }

            return stringBuilder.ToString();
        }