Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 18 additions & 24 deletions .github/workflows/use-visitor-counter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ jobs:
uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ github.head_ref || github.ref_name }}

- name: Shallow clone visitor counter logic
run: git clone --depth=1 https://github.com/brown9804/github-visitor-counter.git
Expand Down Expand Up @@ -57,30 +58,23 @@ jobs:
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"

# Commit and push logic for PR events (merge, not rebase)
- name: Commit and push changes (PR)
if: github.event_name == 'pull_request'
- name: Commit and merge changes
env:
TOKEN: ${{ secrets.GITHUB_TOKEN }}
PR_BRANCH: ${{ github.head_ref || github.ref_name }}
GIT_AUTHOR_NAME: github-actions[bot]
GIT_AUTHOR_EMAIL: github-actions[bot]@users.noreply.github.com
GIT_COMMITTER_NAME: github-actions[bot]
GIT_COMMITTER_EMAIL: github-actions[bot]@users.noreply.github.com
run: |
git fetch origin
git checkout ${{ github.head_ref }}
git pull origin ${{ github.head_ref }} || echo "No merge needed"
# Ensure we're on the correct branch
git switch -c "$PR_BRANCH" || git switch "$PR_BRANCH"

# Stage and commit changes if any
git add -A
git commit -m "Update visitor count" || echo "No changes to commit"
git remote set-url origin https://x-access-token:${TOKEN}@github.com/${{ github.repository }}
git push origin HEAD:${{ github.head_ref }}

# Commit and push logic for non-PR events (merge, not rebase)
- name: Commit and push changes (non-PR)
if: github.event_name != 'pull_request'
env:
TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
git fetch origin
git checkout ${{ github.ref_name }} || git checkout -b ${{ github.ref_name }} origin/${{ github.ref_name }}
git pull origin ${{ github.ref_name }} || echo "No merge needed"
git add -A
git commit -m "Update visitor count" || echo "No changes to commit"
git remote set-url origin https://x-access-token:${TOKEN}@github.com/${{ github.repository }}
git push origin HEAD:${{ github.ref_name }}
git diff --staged --quiet || git commit -m "Update visitor count"

# Pull and merge existing changes
git pull origin "$PR_BRANCH" --no-rebase

# Push all changes
git push origin "$PR_BRANCH"
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ Last updated: 2025-08-27

<!-- START BADGE -->
<div align="center">
<img src="https://img.shields.io/badge/Total%20views-42-limegreen" alt="Total views">
<img src="https://img.shields.io/badge/Total%20views-1403-limegreen" alt="Total views">
<p>Refresh Date: 2025-09-05</p>
</div>
<!-- END BADGE -->
2 changes: 1 addition & 1 deletion scenario1-high-decay/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ Last updated: 2025-08-27

<!-- START BADGE -->
<div align="center">
<img src="https://img.shields.io/badge/Total%20views-42-limegreen" alt="Total views">
<img src="https://img.shields.io/badge/Total%20views-1403-limegreen" alt="Total views">
<p>Refresh Date: 2025-09-05</p>
</div>
<!-- END BADGE -->
2 changes: 1 addition & 1 deletion scenario1-high-decay/terraform-infrastructure/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ graph TD;

<!-- START BADGE -->
<div align="center">
<img src="https://img.shields.io/badge/Total%20views-42-limegreen" alt="Total views">
<img src="https://img.shields.io/badge/Total%20views-1403-limegreen" alt="Total views">
<p>Refresh Date: 2025-09-05</p>
</div>
<!-- END BADGE -->
132 changes: 132 additions & 0 deletions scenario2-optimized/terraform-infrastructure/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
# Azure Infrastructure Terraform Template

Costa Rica

[![GitHub](https://img.shields.io/badge/--181717?logo=github&logoColor=ffffff)](https://github.com/)
[brown9804](https://github.com/brown9804)

Last updated: 2025-09-05

----------

<details>
<summary><b>Table of content</b> (Click to expand)</summary>

- [Prerequisites](#prerequisites)
- [Overview](#overview)
- [How to execute it](#how-to-execute-it)

</details>

## Prerequisites

- An `Azure subscription is required`. All other resources, including instructions for creating a Resource Group, are provided in this workshop.
- `Contributor role assigned or any custom role that allows`: access to manage all resources, and the ability to deploy resources within subscription.
- If you choose to use the Terraform approach, please ensure that:
- [Terraform is installed on your local machine](https://developer.hashicorp.com/terraform/tutorials/azure-get-started/install-cli#install-terraform).
- [Install the Azure CLI](https://learn.microsoft.com/en-us/cli/azure/install-azure-cli) to work with both Terraform and Azure commands.

## Overview

<div align="center">
<img src="https://github.com/user-attachments/assets/47c6f4a2-7366-410f-ae06-9c1aa9cd6514" alt="Centered Image" style="border: 2px solid #4CAF50; border-radius: 5px; padding: 5px;"/>
</div>

<div align="center">
<img src="https://github.com/user-attachments/assets/e5d47acd-dabd-41b3-8fc5-da5f7c4b5b68" alt="Centered Image" style="border: 2px solid #4CAF50; border-radius: 5px; padding: 5px;"/>
</div>

> Templates structure:

```
.
├── README.md
├────── main.tf
├────── variables.tf
├────── provider.tf
├────── terraform.tfvars
├────── outputs.tf
```

- 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.
- 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.
- 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.
- 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.
- 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.

## How to execute it

```mermaid
graph TD;
A[az login] --> B(terraform init)
B --> C{Terraform provisioning stage}
C -->|Review| D[terraform plan]
C -->|Order Now| E[terraform apply]
C -->|Delete Resource if needed| F[terraform destroy]
```

> [!IMPORTANT]
> 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.

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.

> Go to the path where Terraform files are located:

```sh
cd scenario2-optimized/terraform-infrastructure
```

```sh
az login
```

<img width="550" alt="img" src="https://github.com/user-attachments/assets/53b47aa7-134e-4cf7-b0b8-cdebdd0583ed" />

<img width="550" alt="img" src="https://github.com/user-attachments/assets/1d9a247d-3dc9-472f-9305-4e4f0ecb72f1" />

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.

``` sh
terraform init
```

<img width="550" alt="img" src="https://github.com/user-attachments/assets/a7a32891-ad72-423a-a1fe-bdb50925b546" />

3. **Terraform Provisioning Stage**:

- **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`.

```sh
terraform plan -var-file terraform.tfvars
```

> At the end, you will see a message in green if everything was executed successfully:

<img width="550" alt="Screenshot 2025-03-18 145143" src="https://github.com/user-attachments/assets/4741e863-1ccd-4f2a-a0b8-d5d1964bd890" />

- **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`.

```sh
terraform apply -var-file terraform.tfvars
```

> At the end, you will see a message in green if everything was executed successfully:

<img width="550" alt="image" src="https://github.com/user-attachments/assets/2b32b63f-3e9f-46da-a5e9-c39360135251">

- **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`.

```sh
terraform destroy -var-file terraform.tfvars
```

> At the end, you will see a message in green if everything was executed successfully:

<img width="550" alt="image" src="https://github.com/user-attachments/assets/f2089d03-3a3d-431d-b462-8148ef519104">

<!-- START BADGE -->
<div align="center">
<img src="https://img.shields.io/badge/Total%20views-1403-limegreen" alt="Total views">
<p>Refresh Date: 2025-09-05</p>
</div>
<!-- END BADGE -->
Loading