This file contains 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: | |
push: | |
branches: | |
- main | |
jobs: | |
deploy: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Use Node.js | |
uses: actions/setup-node@v4 | |
with: | |
node-version: 14 | |
- name: Checkout repository | |
uses: actions/checkout@v2 | |
- name: Set up Terraform | |
uses: hashicorp/setup-terraform@v1 | |
with: | |
terraform_version: 0.14.11 | |
- name: Terraform Init | |
run: terraform init | |
- name: Terraform Apply | |
run: terraform apply -auto-approve | |
id: set-outputs | |
continue-on-error: true # Esto permite que el flujo de trabajo continúe incluso si hay errores en Terraform | |
- name: Get public IP | |
run: | | |
echo "Public IP: $PUBLIC_IP" | |
env: | |
PUBLIC_IP: ${{ needs.deploy.outputs.public_ip }} | |
- name: Deploy to EC2 | |
run: | | |
PUBLIC_IP=$(terraform output -json public_ip | jq -r '.') | |
echo "Deploying to EC2 at $PUBLIC_IP" | |
# Puedes agregar comandos adicionales para el despliegue, como copiar archivos, etc. | |
- name: Terraform Destroy (cleanup) | |
if: always() | |
run: terraform destroy -auto-approve |