コード例 #1
0
 public SetupAction()
 {
     Cli.PrintLine("Setup Initiated.");
     currentDirectory = @"F:\CodeProjects\Taide\terraform";
     //currentDirectory = Directory.GetCurrentDirectory ();
     collectData = new CollectData();
 }
コード例 #2
0
        private bool GetIsEnvVariable()
        {
            Cli.PrintLine("Is this an environment specific variable? (yes/no)", ConsoleColor.Yellow);
            bool   isEnvVariable  = false;
            string response       = null;
            bool   validInputMade = false;

            while (!validInputMade)
            {
                response = Console.ReadLine().ToLower().Trim();
                switch (response)
                {
                case "y":
                case "yes":
                    validInputMade = true;
                    isEnvVariable  = true;
                    break;

                case "n":
                case "no":
                    validInputMade = true;
                    isEnvVariable  = false;
                    break;

                default:
                    Cli.PrintLine("Error: You must enter yes or no, please try again.", ConsoleColor.Red);
                    break;
                }
            }
            return(isEnvVariable);
        }
コード例 #3
0
        private VarTypes GetVariableType()
        {
            Cli.PrintLine("Variable Type (string/integer)", ConsoleColor.Yellow);
            Cli.PrintLine("Note: List and Map types are currently not supported.", ConsoleColor.DarkGray);
            string variableType   = null;
            bool   validInputMade = false;

            while (!validInputMade)
            {
                variableType = Console.ReadLine().ToLower().Trim();
                switch (variableType)
                {
                case "s":
                case "str":
                case "string":
                    validInputMade = true;
                    return(VarTypes.StringType);

                case "i":
                case "int":
                case "integer":
                    validInputMade = true;
                    return(VarTypes.IntegerType);

                default:
                    Cli.PrintLine("Error: You must enter string or integer, please try again.", ConsoleColor.Red);
                    break;
                }
            }
            return(VarTypes.StringType);
        }
コード例 #4
0
        public void Execute()
        {
            if (!CheckFile.CurrentFolderIsEqualTo("terraform", currentDirectory))
            {
                Cli.PrintLine("Error: You must be in a Terraform project folder root when executing this command.", ConsoleColor.Red);
                return;
            }

            Cli.PrintLine("Please enter the following information.");
            varInfo.varName  = GetVariableName();
            varInfo.varType  = GetVariableType();
            varInfo.isEnvVar = GetIsEnvVariable();
            if (varInfo.isEnvVar)
            {
                varInfo.DevValue  = GetVariableValue("Dev");
                varInfo.QaValue   = GetVariableValue("QA");
                varInfo.QtsValue  = GetVariableValue("QTS");
                varInfo.ProdValue = GetVariableValue("Production");
            }
            else
            {
                varInfo.GlobalValue = GetVariableValue("Global");
            }

            var varLists        = collectData.PopulateVarLists(currentDirectory);
            var variableControl = new VariableControl(currentDirectory);

            variableControl.UpsertVariable(varInfo, varLists);
        }
コード例 #5
0
        private string GetVariableValue(string env)
        {
            Cli.PrintLine($"{env} {varInfo.varName} Variable Value", ConsoleColor.Yellow);
            string variableValue = Console.ReadLine().ToLower().Trim();

            return(variableValue);
        }
コード例 #6
0
        private string GetVariableName()
        {
            Cli.PrintLine("Variable Name", ConsoleColor.Yellow);
            string variableName = Console.ReadLine().ToLower().Trim();

            while (string.IsNullOrWhiteSpace(variableName))
            {
                Cli.PrintLine("Error: You must enter a value, please try again.", ConsoleColor.Red);
                variableName = Console.ReadLine().ToLower().Trim();
            }
            return(variableName);
        }
コード例 #7
0
        public void Execute()
        {
            var dir = Directory.GetCurrentDirectory();

            Cli.PrintLine("Do you wish to create a new Terraform project here? (Yes/No)", ConsoleColor.Yellow);
            if (Console.ReadLine().ToLower() != "yes")
            {
                return;
            }

            if (Directory.Exists($"{currentDirectory}\\terraform"))
            {
                Cli.PrintLine("Error: A 'terraform' folder already exists here.", ConsoleColor.Red);
                return;
            }

            Directory.CreateDirectory($"{currentDirectory}\\terraform");
            Cli.PrintLine("Terraform project folder created.");

            Directory.CreateDirectory($"{currentDirectory}\\terraform\\dev");
            Directory.CreateDirectory($"{currentDirectory}\\terraform\\qa");
            Directory.CreateDirectory($"{currentDirectory}\\terraform\\qts");
            Directory.CreateDirectory($"{currentDirectory}\\terraform\\prod");
            Directory.CreateDirectory($"{currentDirectory}\\terraform\\setup");

            Cli.PrintLine("Environment folders created.");

            File.Create($"{currentDirectory}\\terraform\\dev\\main.tf");
            File.Create($"{currentDirectory}\\terraform\\dev\\vars.tf");
            File.Create($"{currentDirectory}\\terraform\\qa\\main.tf");
            File.Create($"{currentDirectory}\\terraform\\qa\\vars.tf");
            File.Create($"{currentDirectory}\\terraform\\qts\\main.tf");
            File.Create($"{currentDirectory}\\terraform\\qts\\vars.tf");
            File.Create($"{currentDirectory}\\terraform\\prod\\main.tf");
            File.Create($"{currentDirectory}\\terraform\\prod\\vars.tf");
            File.Create($"{currentDirectory}\\terraform\\setup\\main.tf");
            File.Create($"{currentDirectory}\\terraform\\setup\\vars.tf");
            Cli.PrintLine("Environment main and vars tf files created.");

            File.Create($"{currentDirectory}\\terraform\\global.tfvars");
            File.Create($"{currentDirectory}\\terraform\\dev.tfvars");
            File.Create($"{currentDirectory}\\terraform\\qa.tfvars");
            File.Create($"{currentDirectory}\\terraform\\qts.tfvars");
            File.Create($"{currentDirectory}\\terraform\\prod.tfvars");
            Cli.PrintLine("Environment tf variable files created.");

            File.Create($"{currentDirectory}\\terraform\\readme.md");
            Cli.PrintLine("Terraform project created!", ConsoleColor.Green);
        }
コード例 #8
0
        public void Execute()
        {
            string[] segments = currentDirectory.Split('\\');
            string   folder   = segments[segments.Length - 1];

            if (folder.ToLower() != "taide")
            {
                Cli.PrintLine("Error: You must be in a Terraform project folder root when executing this command.",
                              ConsoleColor.Red);
                return;
            }

            Cli.PrintLine("Please enter the following information.");
            Cli.PrintLine("Team Name", ConsoleColor.Yellow);
            string teamName = Console.ReadLine().ToLower();

            Cli.PrintLine("AWS Region", ConsoleColor.Yellow);
            Cli.PrintLine("example: us-east-1");
            string regionValue = Console.ReadLine().ToLower();

            Cli.PrintLine("Your Name", ConsoleColor.Yellow);
            string launchedBy = Console.ReadLine().ToLower();

            Cli.PrintLine("S3 Team Package Bucket Name", ConsoleColor.Yellow);
            Cli.PrintLine("If this has previously been setup enter the correct value, " +
                          "otherwise use something like: vin-TEAM-packages");
            string packageBucket = Console.ReadLine();

            Cli.PrintLine("The Full Project Name", ConsoleColor.Yellow);
            Cli.PrintLine("example: vin-cloudstore-bs-api " +
                          "(note: aws can be picky about what special characters are allowed and where.)");
            string projectName = Console.ReadLine().ToLower();

            Cli.PrintLine("A Shortened Version of the Project Name", ConsoleColor.Yellow);
            Cli.PrintLine("example: vin-cloudstore " +
                          "(note: aws can be picky about what special characters are allowed and where.)");
            string projectAbbreviation = Console.ReadLine().ToLower();

            var vl = new List <string> {
                $"team = \"{teamName}\"",
                $"region = \"{regionValue}\"",
                $"launched_by = \"{launchedBy}\"",
                $"s3_package_bucket = \"{packageBucket}\"",
                $"projectName = \"{projectName}\"",
                $"projectAbbreviation = \"{projectAbbreviation}\""
            };

            var varLists = collectData.PopulateVarLists(currentDirectory);

            StringBuilder globalSb = new StringBuilder();
            StringBuilder devSb    = new StringBuilder();
            StringBuilder qaSb     = new StringBuilder();
            StringBuilder qtsSb    = new StringBuilder();
            StringBuilder prodSb   = new StringBuilder();

            Regex rgx = new Regex("(?<=\").*(?=\")");

            foreach (string line in varLists.GlobalList)
            {
                switch (line.Split(' ') [0].Trim())
                {
                case "team":
                    vl.RemoveAll(x => x.Split(' ') [0].Trim() == "team");
                    vl.Add(rgx.Replace(line, teamName));
                    break;

                case "region":
                    vl.RemoveAll(x => x.Split(' ') [0].Trim() == "region");
                    vl.Add(rgx.Replace(line, regionValue));
                    break;

                case "launched_by":
                    vl.RemoveAll(x => x.Split(' ') [0].Trim() == "launched_by");
                    vl.Add(rgx.Replace(line, launchedBy));
                    break;

                case "s3_package_bucket":
                    vl.RemoveAll(x => x.Split(' ') [0].Trim() == "s3_package_bucket");
                    vl.Add(rgx.Replace(line, packageBucket));
                    break;

                case "projectName":
                    vl.RemoveAll(x => x.Split(' ') [0].Trim() == "projectName");
                    vl.Add(rgx.Replace(line, projectName));
                    break;

                case "projectAbbreviation":
                    vl.RemoveAll(x => x.Split(' ') [0].Trim() == "projectAbbreviation");
                    vl.Add(rgx.Replace(line, projectAbbreviation));
                    break;

                default:
                    if (!string.IsNullOrWhiteSpace(line))
                    {
                        vl.Add(line);
                    }
                    break;
                }
            }

            foreach (var item in vl)
            {
                globalSb.AppendLine(item).AppendLine();
                //string varName = "";
                // varsSb.AppendLine ("variable \"" + varName + "\" {");
                // varsSb.AppendLine ("  type = \"string\"");
                // varsSb.AppendLine ("}").AppendLine ();;
            }

            File.WriteAllText($"{currentDirectory}\\terraform\\global.tfvars", globalSb.ToString());
        }
コード例 #9
0
 public CreateAction()
 {
     currentDirectory = Directory.GetCurrentDirectory();
     Cli.PrintLine($"Current path = {currentDirectory}");
 }