Terraform Deploy #22
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Terraform Deploy | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| aws_access_key_id: | |
| description: "AWS Access Key ID from Learner Lab" | |
| required: true | |
| type: string | |
| aws_secret_access_key: | |
| description: "AWS Secret Access Key from Learner Lab" | |
| required: true | |
| type: string | |
| aws_session_token: | |
| description: "AWS Session Token from Learner Lab" | |
| required: true | |
| type: string | |
| jobs: | |
| deploy: | |
| runs-on: ubuntu-latest | |
| environment: | |
| name: AWS | |
| url: "https://api.${{ steps.terraform.outputs.public_ip }}.nip.io" | |
| steps: | |
| - name: Checkout Code | |
| uses: actions/checkout@v4 | |
| - name: Setup Terraform | |
| uses: hashicorp/setup-terraform@v2 | |
| - name: Terraform Init | |
| run: | | |
| cd infrastructure/terraform | |
| terraform init | |
| - name: Terraform Apply | |
| id: terraform | |
| run: | | |
| cd infrastructure/terraform | |
| terraform apply -auto-approve | |
| IP=$(terraform output -raw public_ip | grep -oE '[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+' | head -n1 | tr -d '\r\n') | |
| echo "public_ip=$IP" >> $GITHUB_OUTPUT | |
| echo "Extrahierte IP: $IP" | |
| env: | |
| TF_VAR_aws_access_key: ${{ github.event.inputs.aws_access_key_id }} | |
| TF_VAR_aws_secret_key: ${{ github.event.inputs.aws_secret_access_key }} | |
| TF_VAR_aws_session_token: ${{ github.event.inputs.aws_session_token }} | |
| - name: Wait for instance to be ready | |
| run: | | |
| echo "Waiting for instance to be ready..." | |
| sleep 60 | |
| echo "Instance should be ready now" | |
| - name: Setup Ansible | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install ansible | |
| - name: Run Ansible Playbook | |
| run: | | |
| cd infrastructure/ansible | |
| EC2_PUBLIC_IP=${{ steps.terraform.outputs.public_ip }} \ | |
| AWS_EC2_USER=${{ vars.AWS_EC2_USER }} \ | |
| ansible-playbook -i inventory.yml playbooks/deploy.yml |