Skip to content

Adding changes to deployment of EC2 #15

Adding changes to deployment of EC2

Adding changes to deployment of EC2 #15

name: Terraform Deployment and Post-Configuration
on:
push:
branches:
- main
jobs:
terraform-deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v2
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: "us-east-1"
# - name: Setup SSH Key
# run: |
# SSH_KEY_PATH=$(mktemp)
# echo "${{ secrets.SSH_PRIVATE_KEY }}" > "$SSH_KEY_PATH"
# chmod 600 "$SSH_KEY_PATH"
# echo "SSH_KEY_PATH=${SSH_KEY_PATH}" >> $GITHUB_ENV
- name: Set up Terraform
uses: hashicorp/setup-terraform@v1
with:
terraform_version: "1.0.0"
# New Step: Print Terraform Version
- name: Print Terraform Version
run: terraform version
working-directory: terraform
- name: Initialize Terraform
run: terraform init
working-directory: terraform
# New Step: List Terraform Outputs Before Apply
- name: List Terraform Outputs Before Apply
run: terraform output
working-directory: terraform
- name: Terraform Plan
run: terraform plan -out=tfplan
working-directory: terraform
- name: Terraform Apply
run: terraform apply -auto-approve tfplan
working-directory: terraform
# - name: Set EC2_INSTANCE_IP environment variable
# run: |
# set -x
# EC2_INSTANCE_IP=$(terraform output -raw ec2_instance_public_ip)
# echo "EC2_INSTANCE_IP=$EC2_INSTANCE_IP" >> $GITHUB_ENV
# - name: Transfer create-milvus.sh to EC2 instance
# run: |
# scp -o StrictHostKeyChecking=no -i $SSH_KEY_PATH ./create-milvus.sh ubuntu@${{ env.EC2_INSTANCE_IP }}:/tmp/create-milvus.sh
# working-directory: terraform
# - name: Execute create-milvus.sh on EC2 instance
# run: |
# ssh -o StrictHostKeyChecking=no -i $SSH_KEY_PATH ubuntu@${{ env.EC2_INSTANCE_IP }} "bash /tmp/create-milvus.sh"