services:
  integration-test:
    build:
      context: .
      target: base
    environment:
      - GITHUB_API_KEY
      - GITHUB_REPO_NAME
      - GITHUB_PR_NUM
    volumes:
      - type: bind
        # change to the path of a clone of your forked terraform-infra
        source: ../terraform-infra
        target: /repository
  integration-test-as-github-app:
    build:
      context: .
      target: base
    environment:
      - GITHUB_REPO_NAME
      - GITHUB_PR_NUM
      - GITHUB_APP_CLIENT_ID
      - GITHUB_APP_INSTALLATION_ID
      - GITHUB_APP_PRIVATE_KEY_FILE_LOCATION=/app/private_key.pem
    volumes:
      - type: bind
        # change to the path of a clone of your forked terraform-infra
        source: ../terraform-infra
        target: /repository
      # Change to the path of your GitHub App private key
      # - ./path_to_private_key.pem:/app/private_key.pem
  unit-test:
    build:
      context: .
      target: unit-test
    volumes:
      - ./policies:/app/policies
      - ./terraform-scanner:/app/terraform-scanner
      - ./tests:/app/tests
      - ./checkov.yaml:/app/checkov.yaml
      - ./run-tests.sh:/app/run-tests.sh
  module-integration-tests:
    build:
      context: .
      target: module-integration-tests
      secrets:
        - GITHUB_APP_CLIENT_ID
        - GITHUB_APP_INSTALLATION_ID
        - GITHUB_APP_PRIVATE_KEY
    environment:
      - AWS_DEFAULT_REGION=us-east-1
      - AWS_ACCESS_KEY_ID
      - AWS_SECRET_ACCESS_KEY
      - AWS_SESSION_TOKEN
    volumes:
      - ./policies:/app/policies
      - ./terraform-scanner:/app/terraform-scanner
      - ./tests:/app/tests
      - ./checkov.yaml:/app/checkov.yaml
      - ./run-module-integration-tests.sh:/app/run-module-integration-tests.sh
      # Use local modules if desired
      # - ../terraform-fargate:/app/scan/modules/terraform-fargate

secrets:
  GITHUB_APP_CLIENT_ID:
    environment: GITHUB_APP_CLIENT_ID
  GITHUB_APP_INSTALLATION_ID:
    environment: GITHUB_APP_INSTALLATION_ID
  GITHUB_APP_PRIVATE_KEY:
    file: ${GITHUB_APP_PRIVATE_KEY_FILE_LOCATION}
