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()
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])