/// <summary>
        /// Processes the inputs.
        /// </summary>
        /// <returns>List of <see cref="InputVariable"/></returns>
        public List <InputVariable> ProcessInputs()
        {
            this.logger.LogInformation("- Importing parameters...");
            var inputVariables = new List <InputVariable>();

            foreach (var p in this.template.Parameters.Concat(this.template.PseudoParameters))
            {
                var inputVariable = InputVariable.CreateParameter(p);

                if (inputVariable == null)
                {
                    var wrn = p is PseudoParameter
                                  ? $"Pseudo-parameter '{p.Name}' cannot be imported as it is not supported by Terraform."
                                  : $"Stack parameter '{p.Name}' cannot be imported.";

                    this.logger.LogWarning(wrn);

                    if (!this.warnings.Contains(wrn))
                    {
                        // When importing multiple stacks, only warn about unsupported pseudo vars once.
                        this.warnings.Add(wrn);
                    }
                }
                else
                {
                    inputVariables.Add(inputVariable);
                }
            }

            return(inputVariables);
        }
Пример #2
0
        public void WhenInputParameterIsListAndOneElementMatchesThenElementIsFound()
        {
            var resource = new StateFileResourceInstance {
                Attributes = resourceAttributes
            };
            var templateParameter = new Mock <IParameter>();

            templateParameter.Setup(p => p.Name).Returns("PrivateSubnets");
            templateParameter.Setup(p => p.Type).Returns("List<AWS::EC2::Subnet::Id>");
            templateParameter.Setup(p => p.GetCurrentValue()).Returns("subnet-00000000,subnet-11111111");

            var inputVariable = InputVariable.CreateParameter(templateParameter.Object);
            var result        = resource.FindId(inputVariable, false);

            result.Should().HaveCount(2, "there should be 1 property match and 1 array match");
        }
Пример #3
0
        public void WhenInputParameterIsStringAndAttributeScalarValueMatchesThenElementIsFound()
        {
            var resource = new StateFileResourceInstance {
                Attributes = resourceAttributes
            };
            var templateParameter = new Mock <IParameter>();

            templateParameter.Setup(p => p.Name).Returns("VpcId");
            templateParameter.Setup(p => p.Type).Returns("AWS::EC2::VPC::Id");
            templateParameter.Setup(p => p.GetCurrentValue()).Returns("vpc-00000000");

            var inputVariable = InputVariable.CreateParameter(templateParameter.Object);

            var result = resource.FindId(inputVariable, false);

            result.Should().HaveCount(1).And
            .AllBeOfType <JProperty>("property returned has the element we are looking for as its value");
        }
Пример #4
0
        public void WhenInputParameterIsStringAndAttributeArrayValueMatchesThenElementIsFound()
        {
            var resource = new StateFileResourceInstance {
                Attributes = resourceAttributes
            };
            var templateParameter = new Mock <IParameter>();

            templateParameter.Setup(p => p.Name).Returns("VpcId");
            templateParameter.Setup(p => p.Type).Returns("AWS::EC2::SecurityGroup::Id");
            templateParameter.Setup(p => p.GetCurrentValue()).Returns("sg-00000000");

            var inputVariable = InputVariable.CreateParameter(templateParameter.Object);

            var result = resource.FindId(inputVariable, false);

            result.Should().HaveCount(1).And
            .AllBeOfType <JArray>("array returned contains the element we are looking for");
        }