Exemple #1
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()
Exemple #2
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])