예제 #1
0
    def __init__(self, command_executor, **kwargs):
        """
        :type command_executor:  BaseCommandExecutor
        :param command_executor: Command Line Executor
        :type parameters:  dict
        :param parameters: CLI arguments
        """

        self.terraform = Terraform(command_executor, **kwargs)
예제 #2
0
 def test_destroy(self):
     expected_args = [
         'terraform', 'destroy', '-no-color', '-auto-approve', '-var',
         "'test=[\"Test\", \"Test2\"]'"
     ]
     tf = Terraform(self.command_executor_mock,
                    variables={'test': ['Test', 'Test2']})
     tf.destroy()
     self.command_executor_mock.run.assert_called()
     args, kwargs = self.command_executor_mock.run.call_args
     for i in expected_args:
         self.assertIn(i, args[0])
예제 #3
0
 def test_apply(self):
     expected_args = [
         'terraform', 'apply', '-no-color', '-auto-approve', '-var',
         "'test=Test'"
     ]
     tf = Terraform(self.command_executor_mock,
                    variables={
                        'test': 'Test',
                        'no_value': None
                    })
     tf.apply()
     self.command_executor_mock.run.assert_called()
     args, kwargs = self.command_executor_mock.run.call_args
     for i in expected_args:
         self.assertIn(i, args[0])
예제 #4
0
class TerraformServiceProvider(BaseIaCServiceProvider):
    def __init__(self, command_executor, **kwargs):
        """
        :type command_executor:  BaseCommandExecutor
        :param command_executor: Command Line Executor
        :type parameters:  dict
        :param parameters: CLI arguments
        """

        self.terraform = Terraform(command_executor, **kwargs)

    def provision(self):
        """Provision terraform"""

        self.terraform.initialize()
        self.terraform.validate()
        self.terraform.apply()

    def destroy(self):
        """Deploy terraform"""

        self.terraform.initialize()
        self.terraform.validate()
        self.terraform.destroy()

    def output(self):
        """Extract terraform output
        :rtype dict
        """

        return self.terraform.output()
예제 #5
0
 def test_wrong_command_executor(self):
     types = [str, int, list, dict, set, tuple]
     for executor_type in types:
         with self.assertRaises(DLabException):
             Terraform(MagicMock(spec=executor_type))
예제 #6
0
 def test_wrong_parameters_type(self):
     with self.assertRaises(DLabException):
         Terraform(self.command_executor_mock, no_color='')
예제 #7
0
 def test_output(self):
     Terraform(self.command_executor_mock).output()
     self.command_executor_mock.run.assert_called_with(
         'terraform output -json')
예제 #8
0
 def test_validate(self):
     self.command_executor_mock.run.return_value = TF_VALIDATE_SUCCESS_MSG
     Terraform(self.command_executor_mock).validate()
     self.command_executor_mock.run.assert_called_with('terraform validate')
예제 #9
0
 def test_failed_initialize(self):
     self.command_executor_mock.run.return_value = "error"
     with self.assertRaises(TerraformException):
         Terraform(self.command_executor_mock).initialize()
예제 #10
0
 def test_initialize(self):
     self.command_executor_mock.run.return_value = TF_INIT_SUCCESS_MSG
     Terraform(self.command_executor_mock).initialize()
     self.command_executor_mock.run.assert_called_with('terraform init')