-
Notifications
You must be signed in to change notification settings - Fork 1
49 lines (40 loc) · 1.59 KB
/
deploy.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
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