-
Notifications
You must be signed in to change notification settings - Fork 4
78 lines (65 loc) · 2.53 KB
/
tf.yaml
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
name: Terraform in Daily Test
on:
workflow_dispatch: #允许手动运行
schedule:
- cron: '0 18 * * *' # 每天 UTC 时间 18:00,即中国时间凌晨 2 点
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Check GitHub Secrets
run: |
if [ -z "${{ secrets.MYAPP_GITHUB_TOKEN }}" ]; then
echo "GitHub Token is missing"
else
echo "GitHub Token is set"
fi
if [ -z "${{ secrets.MYAPP_USER_EMAIL }}" ]; then
echo "User Email is missing"
else
echo "User Email is set"
fi
if [ -z "${{ secrets.MYAPP_USER_NAME }}" ]; then
echo "User Name is missing"
else
echo "User Name is set"
fi
- name: Checkout repository
uses: actions/checkout@v2
- name: Setup Terraform
uses: hashicorp/setup-terraform@v2
with:
terraform_version: 1.9.4
- name: Initialize Terraform
env:
TF_VAR_access_key: ${{ secrets.ALI_ACCESS_KEY }}
TF_VAR_secret_key: ${{ secrets.ALI_SECRET_KEY }}
TF_VAR_github_token: ${{ secrets.MYAPP_GITHUB_TOKEN }}
TF_VAR_user_name: ${{ secrets.MYAPP_USER_NAME }}
TF_VAR_user_email: ${{ secrets.MYAPP_USER_EMAIL }}
run: terraform -chdir=./Terraform/Aliyun init
- name: Apply Terraform Configuration
env:
TF_VAR_access_key: ${{ secrets.ALI_ACCESS_KEY }}
TF_VAR_secret_key: ${{ secrets.ALI_SECRET_KEY }}
TF_VAR_github_token: ${{ secrets.MYAPP_GITHUB_TOKEN }}
TF_VAR_user_name: ${{ secrets.MYAPP_USER_NAME }}
TF_VAR_user_email: ${{ secrets.MYAPP_USER_EMAIL }}
run: terraform -chdir=./Terraform/Aliyun apply -auto-approve
- name: Print current directory and file list
run: |
cd ./Terraform/Aliyun
echo "Current directory:"
pwd
echo "Files in the current directory:"
ls
- name: Wait for 20 minutes before destroying resources
run: sleep 1200 # 等待 20 分钟
- name: Destroy Terraform Configuration
env:
TF_VAR_access_key: ${{ secrets.ALI_ACCESS_KEY }}
TF_VAR_secret_key: ${{ secrets.ALI_SECRET_KEY }}
TF_VAR_github_token: ${{ secrets.MYAPP_GITHUB_TOKEN }}
TF_VAR_user_name: ${{ secrets.MYAPP_USER_NAME }}
TF_VAR_user_email: ${{ secrets.MYAPP_USER_EMAIL }}
run: terraform -chdir=./Terraform/Aliyun destroy -auto-approve