Updating deploy.yml #11
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: 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 | |
AWS_PROFILE: wp-migration # Set the profile name for Terraform to use | |
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 | |
working-directory: ./aws_migration # Adjust to your Terraform directory | |
run: terraform init | |
# Step 5: Terraform Plan (optional, but recommended) | |
- name: Terraform Plan | |
working-directory: ./aws_migration # Adjust to your Terraform directory | |
run: terraform plan | |
# Step 6: Terraform Apply (auto-approve for automation) | |
- name: Terraform Apply | |
working-directory: ./aws_migration # Adjust to your Terraform directory | |
run: terraform apply -auto-approve |