Skip to content

Updating deploy.yml

Updating deploy.yml #9

Workflow file for this run

name: Deploy EC2 Instances with Terraform
on:
push:
branches:
- ci/cd # Runs the workflow on push to the ci/cd branch. Adjust branch as needed.
workflow_dispatch: # Allows manual triggering
jobs:
terraform:
runs-on: ubuntu-latest
env:
AWS_REGION: us-east-1 # Set your preferred AWS region
steps:
# Step 1: Checkout the code
- name: Checkout repository
uses: actions/checkout@v3
# Step 2: Set up Terraform CLI
- name: Set up Terraform
uses: hashicorp/setup-terraform@v2
with:
terraform_version: 1.9.8 # Replace with the version you use
# Step 3: Configure AWS credentials
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v3
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ env.AWS_REGION }}
# Step 4: Terraform Init
- name: Terraform Init
run: terraform init
# Step 5: Terraform Plan (optional, but recommended)
- name: Terraform Plan
run: terraform plan
# Step 6: Terraform Apply (auto-approve for automation)
- name: Terraform Apply
run: terraform apply -auto-approve