namespace :test do
  namespace :terraform do
    desc 'Terraform Format Check'
    task :format do
      Orchestrator::ConsoleOutputs.header
      Orchestrator::ConsoleOutputs.sub_header('Terraform Format Check')
      command = 'terraform fmt -check -recursive'
      success = Orchestrator::Shell.run_command(command)
      Orchestrator::ConsoleOutputs.message('No Offenses') if success
    end

    desc 'Run Terrascan Security Scanner on Project'
    task :terrascan do
      Orchestrator::ConsoleOutputs.header
      Orchestrator::ConsoleOutputs.sub_header('Terrascan')

      command = "terrascan scan -c #{$project_vars['orchestrator']['orchestrator_path']}/.terrascan/config.toml -i terraform -o yaml -d terraform"
      system(command)
      # Dir.chdir("#{$project_vars['orchestrator']['orchestrator_path']}/terraform") do
      #   command = "terrascan scan -c #{$project_vars['orchestrator']['orchestrator_path']}/terrascan.toml -o yaml"
      #   system(command)
      # end
    end
  end
end

desc 'Alias (test:terraform:format)'
task test_tf_fmt: %w[test:terraform:format]

desc 'Alias (test:terraform:terrascan)'
task test_tf_scan: %w[test:terraform:terrascan]
