name: E2E QEMU test
description: "Test MiniConstellation functionality on Azure VM."

inputs:
  azureClientID:
    description: "Azure client to use for login with OIDC"
    required: true
  azureSubscriptionID:
    description: "Azure subscription to use for login with OIDC"
    required: true
  azureTenantID:
    description: "Azure tenant to use for login with OIDC"
    required: true

runs:
  using: "composite"
  steps:
    - name: Install terraform
      uses: hashicorp/setup-terraform@633666f66e0061ca3b725c73b2ec20cd13a8fdd1 # v2.0.3
      with:
        terraform_wrapper: false

    - name: Setup Go environment
      uses: actions/setup-go@c4a742cab115ed795e34d4513e2cf7d472deb55f # tag=v3.3.1
      with:
        go-version: "1.19.4"

    - name: Build Constellation CLI
      uses: ./.github/actions/build_cli
      with:
        enterpriseCLI: true

    - name: MiniConstellation E2E
      shell: bash
      run: |
        echo "::group::Terraform"
        cd .github/actions/e2e_mini
        terraform init
        terraform apply -auto-approve
        terraform output -raw ssh_private_key > id_rsa
        chmod 600 id_rsa
        export AZURE_VM_IP=$(terraform output -raw public_ip)
        echo "::endgroup::"

        ./wait-for-ssh.sh
        # Copy locally build Constellation CLI and run e2e script.
        scp -i id_rsa ../../../build/constellation adminuser@${AZURE_VM_IP}:.
        ssh -i id_rsa adminuser@${AZURE_VM_IP} 'bash -s' < run-e2e.sh
      env:
        ARM_CLIENT_ID: ${{ inputs.azureClientID }}
        ARM_SUBSCRIPTION_ID: ${{ inputs.azureSubscriptionID }}
        ARM_TENANT_ID: ${{ inputs.azureTenantID }}

    - name: Delete deployment
      if: always()
      shell: bash
      run: |
        echo "::group::Terminate"
        cd .github/actions/e2e_mini
        terraform destroy -auto-approve
        echo "::endgroup::"
      env:
        ARM_CLIENT_ID: ${{ inputs.azureClientID }}
        ARM_SUBSCRIPTION_ID: ${{ inputs.azureSubscriptionID }}
        ARM_TENANT_ID: ${{ inputs.azureTenantID }}
