Skip to content

Commit 91c5e50

Browse files
authored
Merge pull request #1 from Cloud2BR-MSFTLearningHub/feature/terraform-infrastructure
Add terraform infrastructure sample
2 parents e4d66bc + 3036a48 commit 91c5e50

11 files changed

Lines changed: 559 additions & 19 deletions

File tree

.github/workflows/update-md-date.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,6 @@ jobs:
2525
with:
2626
python-version: '3.x'
2727

28-
- name: Install dependencies
29-
run: pip install python-dateutil
30-
3128
- name: Configure Git
3229
run: |
3330
git config --global user.email "github-actions[bot]@users.noreply.github.com"

.github/workflows/update_date.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import os
21
import subprocess
32
from datetime import datetime, timezone
43

@@ -44,6 +43,3 @@ def update_date_in_file(file_path):
4443
print(f"Updating file: {file_path}") # Debugging: Print the file being updated
4544
update_date_in_file(file_path)
4645

47-
# Add and commit changes
48-
subprocess.run(['git', 'add', '-A'])
49-
subprocess.run(['git', 'commit', '-m', 'Update last modified date in Markdown files'])

.github/workflows/use-visitor-counter.yml

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ jobs:
2121
uses: actions/checkout@v4
2222
with:
2323
fetch-depth: 0
24+
ref: ${{ github.event_name == 'pull_request' && github.head_ref || github.ref_name }}
2425

2526
- name: Shallow clone visitor counter logic
2627
run: git clone --depth=1 https://github.com/brown9804/github-visitor-counter.git
@@ -63,24 +64,22 @@ jobs:
6364
env:
6465
TOKEN: ${{ secrets.GITHUB_TOKEN }}
6566
run: |
66-
git fetch origin
67-
git checkout ${{ github.head_ref }}
68-
git pull origin ${{ github.head_ref }} || echo "No merge needed"
67+
BRANCH="${{ github.head_ref }}"
68+
git pull origin "$BRANCH" || echo "No merge needed"
6969
git add -A
7070
git commit -m "Update visitor count" || echo "No changes to commit"
7171
git remote set-url origin https://x-access-token:${TOKEN}@github.com/${{ github.repository }}
72-
git push origin HEAD:${{ github.head_ref }}
72+
git push origin HEAD:"$BRANCH"
7373
7474
# Commit and push logic for non-PR events (merge, not rebase)
7575
- name: Commit and push changes (non-PR)
7676
if: github.event_name != 'pull_request'
7777
env:
7878
TOKEN: ${{ secrets.GITHUB_TOKEN }}
7979
run: |
80-
git fetch origin
81-
git checkout ${{ github.ref_name }} || git checkout -b ${{ github.ref_name }} origin/${{ github.ref_name }}
82-
git pull origin ${{ github.ref_name }} || echo "No merge needed"
80+
BRANCH="${{ github.ref_name }}"
81+
git pull origin "$BRANCH" || echo "No merge needed"
8382
git add -A
8483
git commit -m "Update visitor count" || echo "No changes to commit"
8584
git remote set-url origin https://x-access-token:${TOKEN}@github.com/${{ github.repository }}
86-
git push origin HEAD:${{ github.ref_name }}
85+
git push origin HEAD:"$BRANCH"

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ crash.*.log
1313
# password, private keys, and other secrets. These should not be part of version
1414
# control as they are data points which are potentially sensitive and subject
1515
# to change depending on the environment.
16-
*.tfvars
1716
*.tfvars.json
1817

1918
# Ignore override files as they are usually used to override resources locally and so

README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Costa Rica
66
[![GitHub](https://img.shields.io/badge/--181717?logo=github&logoColor=ffffff)](https://github.com/)
77
[brown9804](https://github.com/brown9804)
88

9-
Last updated: 2025-07-30
9+
Last updated: 2026-04-07
1010

1111
-----------------------------
1212

@@ -34,6 +34,8 @@ Last updated: 2025-07-30
3434

3535
## Overview
3636

37+
> The infrastructure sample for this architecture is available in [terraform-infrastructure](terraform-infrastructure/README.md). It provisions the Azure-side resources for the documented workflow, including the Resource Group, Function App dependencies, monitoring, Logic App, Key Vault, SQL, and the AI service account.
38+
3739

3840
<div align="center">
3941
<img src="https://github.com/user-attachments/assets/48774cdd-ba27-404c-b7fc-a124fd176e2a" alt="Centered Image" style="border: 2px solid #4CAF50; border-radius: 5px; padding: 5px;"/>
@@ -73,7 +75,7 @@ Last updated: 2025-07-30
7375

7476
<!-- START BADGE -->
7577
<div align="center">
76-
<img src="https://img.shields.io/badge/Total%20views-1296-limegreen" alt="Total views">
77-
<p>Refresh Date: 2025-11-13</p>
78+
<img src="https://img.shields.io/badge/Total%20views-1282-limegreen" alt="Total views">
79+
<p>Refresh Date: 2026-04-07</p>
7880
</div>
7981
<!-- END BADGE -->

terraform-infrastructure/README.md

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
# Azure Infrastructure Terraform Templates
2+
3+
Costa Rica
4+
5+
[![GitHub](https://img.shields.io/badge/--181717?logo=github&logoColor=ffffff)](https://github.com/)
6+
[Cloud2BR OSS - Learning Hub](https://github.com/Cloud2BR-MSFTLearningHub)
7+
8+
Last updated: 2026-04-07
9+
10+
----------
11+
12+
> This approach focuses on `setting up the required infrastructure via Terraform`. It allows for source control of not only the solution code, connections, and setups `but also the infrastructure itself`.
13+
14+
## Prerequisites
15+
16+
- An `Azure subscription is required`. All other resources, including instructions for creating a Resource Group, are provided in this workshop.
17+
- `Contributor role assigned or any custom role that allows`: access to manage all resources, and the ability to deploy resources within subscription.
18+
- Please ensure that:
19+
- [Terraform is installed on your local machine](https://developer.hashicorp.com/terraform/tutorials/azure-get-started/install-cli#install-terraform).
20+
- [Install the Azure CLI](https://learn.microsoft.com/en-us/cli/azure/install-azure-cli) to work with both Terraform and Azure commands.
21+
22+
## Overview
23+
24+
Templates structure:
25+
26+
```
27+
.
28+
├── README.md
29+
├────── main.tf
30+
├────── variables.tf
31+
├────── provider.tf
32+
├────── terraform.tfvars
33+
├────── outputs.tf
34+
```
35+
36+
- main.tf `(Main Terraform configuration file)`: This file contains the core infrastructure code. It defines the resources you want to create, such as virtual machines, networks, and storage. It's the primary file where you describe your infrastructure in a declarative manner.
37+
- variables.tf `(Variable definitions)`: This file is used to define variables that can be used throughout your Terraform configuration. By using variables, you can make your configuration more flexible and reusable. For example, you can define variables for resource names, sizes, and other parameters that might change between environments.
38+
- provider.tf `(Provider configurations)`: Providers are plugins that Terraform uses to interact with cloud providers, SaaS providers, and other APIs. This file specifies which providers (e.g., AWS, Azure, Google Cloud) you are using and any necessary configuration for them, such as authentication details.
39+
- terraform.tfvars `(Variable values)`: This file contains the actual values for the variables defined in `variables.tf`. By separating variable definitions and values, you can easily switch between different sets of values for different environments (e.g., development, staging, production) without changing the main configuration files.
40+
- outputs.tf `(Output values)`: This file defines the output values that Terraform should return after applying the configuration. Outputs are useful for displaying information about the resources created, such as IP addresses, resource IDs, and other important details. They can also be used as inputs for other Terraform configurations or scripts.
41+
42+
## How to execute it
43+
44+
```mermaid
45+
graph TD;
46+
A[az login] --> B(terraform init)
47+
B --> C{Terraform provisioning stage}
48+
C -->|Review| D[terraform plan]
49+
C -->|Order Now| E[terraform apply]
50+
C -->|Delete Resource if needed| F[terraform destroy]
51+
```
52+
53+
> [!IMPORTANT]
54+
> Please modify `terraform.tfvars` with your information, then run the following flow. If you need more visual guidance, please check the video that illustrates the provisioning steps.
55+
56+
1. **Login to Azure**: This command logs you into your Azure account. It opens a browser window where you can enter your Azure credentials. Once logged in, you can manage your Azure resources from the command line.
57+
58+
> Go to the path where Terraform files are located:
59+
60+
```sh
61+
cd terraform-infrastructure
62+
```
63+
64+
```sh
65+
az login
66+
```
67+
68+
<img width="550" alt="img" src="https://github.com/user-attachments/assets/53b47aa7-134e-4cf7-b0b8-cdebdd0583ed" />
69+
70+
<img width="550" alt="img" src="https://github.com/user-attachments/assets/1d9a247d-3dc9-472f-9305-4e4f0ecb72f1" />
71+
72+
2. **Initialize Terraform**: Initializes the working directory containing the Terraform configuration files. It downloads the necessary provider plugins and sets up the backend for storing the state.
73+
74+
``` sh
75+
terraform init
76+
```
77+
78+
<img width="550" alt="img" src="https://github.com/user-attachments/assets/a7a32891-ad72-423a-a1fe-bdb50925b546" />
79+
80+
3. **Terraform Provisioning Stage**:
81+
82+
- **Review**: Creates an execution plan, showing what actions Terraform will take to achieve the desired state defined in your configuration files. It uses the variable values specified in `terraform.tfvars`.
83+
84+
```sh
85+
terraform plan -var-file terraform.tfvars
86+
```
87+
88+
> At the end, you will see a message in green if everything was executed successfully:
89+
90+
<img width="550" alt="Screenshot 2025-03-18 145143" src="https://github.com/user-attachments/assets/4741e863-1ccd-4f2a-a0b8-d5d1964bd890" />
91+
92+
- **Order Now**: Applies the changes required to reach the desired state of the configuration. It prompts for confirmation before making any changes. It also uses the variable values specified in `terraform.tfvars`.
93+
94+
```sh
95+
terraform apply -var-file terraform.tfvars
96+
```
97+
98+
> At the end, you will see a message in green if everything was executed successfully:
99+
100+
<img width="550" alt="image" src="https://github.com/user-attachments/assets/2b32b63f-3e9f-46da-a5e9-c39360135251">
101+
102+
- **Remove**: Destroys the infrastructure managed by Terraform. It prompts for confirmation before deleting any resources. It also uses the variable values specified in `terraform.tfvars`.
103+
104+
```sh
105+
terraform destroy -var-file terraform.tfvars
106+
```
107+
108+
> At the end, you will see a message in green if everything was executed successfully:
109+
110+
<img width="550" alt="image" src="https://github.com/user-attachments/assets/f2089d03-3a3d-431d-b462-8148ef519104">
111+
112+
<!-- START BADGE -->
113+
<div align="center">
114+
<img src="https://img.shields.io/badge/Total%20views-1282-limegreen" alt="Total views">
115+
<p>Refresh Date: 2026-04-07</p>
116+
</div>
117+
<!-- END BADGE -->

0 commit comments

Comments
 (0)