Skip to content

Commit 3380df1

Browse files
committed
Refactor workflows to use workflow_call and add required secrets for Azure deployment
1 parent ceef91b commit 3380df1

File tree

4 files changed

+75
-16
lines changed

4 files changed

+75
-16
lines changed

.github/workflows/ci.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: CI/CD Pipeline
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
types: [opened, synchronize, reopened, closed]
8+
branches: [main]
9+
10+
jobs:
11+
terraform:
12+
uses: ./.github/workflows/terraform.yml
13+
secrets:
14+
AZURE_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }}
15+
AZURE_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }}
16+
AZURE_SUBSCRIPTION_ID: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
17+
18+
deploy:
19+
needs: terraform
20+
uses: ./.github/workflows/deploy.yml
21+
secrets:
22+
AZURE_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }}
23+
AZURE_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }}
24+
AZURE_SUBSCRIPTION_ID: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
25+
AZURE_STATIC_WEB_APPS_API_TOKEN: ${{ secrets.AZURE_STATIC_WEB_APPS_API_TOKEN }}

.github/workflows/deploy.yml

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
name: Deploy to Azure Static Web App
22
on:
3-
push:
4-
branches: [main]
5-
pull_request:
6-
types: [opened, synchronize, reopened, closed]
7-
branches: [main]
8-
3+
workflow_call:
4+
secrets:
5+
AZURE_CLIENT_ID:
6+
required: true
7+
AZURE_TENANT_ID:
8+
required: true
9+
AZURE_SUBSCRIPTION_ID:
10+
required: true
11+
AZURE_STATIC_WEB_APPS_API_TOKEN:
12+
required: true
13+
914
jobs:
1015
deploy:
1116
if: github.event_name == 'push' || (github.event_name == 'pull_request' && github.event.action != 'closed')
@@ -19,10 +24,7 @@ jobs:
1924

2025
steps:
2126
- name: Checkout
22-
uses: actions/checkout@v4
23-
with:
24-
submodules: true
25-
lfs: false
27+
uses: actions/checkout@v5
2628

2729
- name: Azure Login
2830
uses: azure/login@v1
@@ -32,7 +34,7 @@ jobs:
3234
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
3335

3436
- name: Deploy Static Web App
35-
uses: Azure/static-web-apps-deploy@v1
37+
uses: azure/static-web-apps-deploy@v1
3638
with:
3739
azure_static_web_apps_api_token: ${{ secrets.AZURE_STATIC_WEB_APPS_API_TOKEN }}
3840
repo_token: ${{ secrets.GITHUB_TOKEN }}
@@ -46,7 +48,7 @@ jobs:
4648
name: Close Pull Request
4749
steps:
4850
- name: Close Pull Request
49-
uses: Azure/static-web-apps-deploy@v1
51+
uses: azure/static-web-apps-deploy@v1
5052
with:
5153
azure_static_web_apps_api_token: ${{ secrets.AZURE_STATIC_WEB_APPS_API_TOKEN }}
5254
action: "close"

.github/workflows/terraform.yml

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,14 @@
4545
name: 'Terraform'
4646

4747
on:
48-
push:
49-
branches: [ "main" ]
50-
pull_request:
48+
workflow_call:
49+
secrets:
50+
AZURE_CLIENT_ID:
51+
required: true
52+
AZURE_TENANT_ID:
53+
required: true
54+
AZURE_SUBSCRIPTION_ID:
55+
required: true
5156

5257
permissions:
5358
contents: read
@@ -81,7 +86,7 @@ jobs:
8186

8287
# Install the latest version of Terraform CLI and configure the Terraform CLI configuration file with a Terraform Cloud user API token
8388
- name: Setup Terraform
84-
uses: hashicorp/setup-terraform@v1
89+
uses: hashicorp/setup-terraform@v3
8590

8691
# Initialize a new or existing Terraform working directory by creating initial files, loading any remote state, downloading modules, etc.
8792
- name: Terraform Init

README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# GitHub Actions Terraform
2+
3+
Automated Azure infrastructure deployment using Terraform and GitHub Actions with OIDC authentication.
4+
5+
## 🚀 What This Does
6+
7+
- **Terraform** manages Azure infrastructure (Resource Group + Static Web App)
8+
- **GitHub Actions** automatically deploys on push to `main`
9+
- **OIDC** for secure, keyless authentication to Azure
10+
- **Remote State** stored in Azure Storage with locking
11+
12+
## 🔗 Live Site
13+
14+
[https://black-sky-0510e820f.3.azurestaticapps.net](https://black-sky-0510e820f.3.azurestaticapps.net)
15+
16+
## 🏗️ Infrastructure
17+
18+
- Azure Static Web App (Free tier)
19+
- Resource Group: `rg-github-actions-terraform`
20+
- Terraform State: Azure Storage account `tfstate56202`
21+
22+
## 🔐 Security
23+
24+
- OIDC federated identity (no secrets stored)
25+
- Encrypted state at rest
26+
- State locking enabled
27+
- Environment protection: `production`

0 commit comments

Comments
 (0)