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
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# .tfstate files
*.tfstate
*.tfstate.*
.terraform.lock.hcl

# Crash log files
crash.log
Expand All @@ -13,7 +14,6 @@ crash.*.log
# password, private keys, and other secrets. These should not be part of version
# control as they are data points which are potentially sensitive and subject
# to change depending on the environment.
*.tfvars
*.tfvars.json

# Ignore override files as they are usually used to override resources locally and so
Expand Down
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Costa Rica
[![GitHub](https://img.shields.io/badge/--181717?logo=github&logoColor=ffffff)](https://github.com/)
[brown9804](https://github.com/brown9804)

Last updated: 2025-05-13
Last updated: 2025-05-20

----------

Expand Down Expand Up @@ -114,7 +114,7 @@ Last updated: 2025-05-13

This is an introductory workshop on Microsoft Fabric. Please follow as described below.

- If you're choosing the `Infrastructure via Azure Portal`, please start [here](#step-1-set-up-your-azure-environment).
- If you're choosing the `Infrastructure via Azure Portal`, please start [here in this section](#step-1-set-up-your-azure-environment).
- If you're choosing the `Infrastructure via Terraform` approach:
1. Please follow the [Terraform guide](./terraform-infrastructure/) to deploy the necessary Azure resources for the workshop.
2. Then, follow each [each section](#step-1-set-up-your-azure-environment) but `skip the creation of each resource`.
Expand Down Expand Up @@ -385,6 +385,7 @@ This is an introductory workshop on Microsoft Fabric. Please follow as described
- Click on `Apply` to save your configuration.

### Develop the Function

- You need to install [VSCode](https://code.visualstudio.com/download)
- Install python from Microsoft store:

Expand Down Expand Up @@ -453,7 +454,7 @@ This is an introductory workshop on Microsoft Fabric. Please follow as described

| Template Blob Trigger | Function Code updated |
| --- | --- |
| <img width="550" alt="image" src="https://github.com/user-attachments/assets/a4ac6f2d-1419-4629-8896-de202c76000e"> | <img width="550" alt="image" src="https://github.com/user-attachments/assets/a9e41cd7-9c3f-4da5-8526-5c7f06107a84"> |
| <img width="550" alt="image" src="https://github.com/user-attachments/assets/a4ac6f2d-1419-4629-8896-de202c76000e"> | <img width="550" alt="image" src="https://github.com/user-attachments/assets/a9e41cd7-9c3f-4da5-8526-5c7f06107a84"> |

```python
import azure.functions as func
Expand Down Expand Up @@ -587,7 +588,7 @@ This is an introductory workshop on Microsoft Fabric. Please follow as described

| Template `requirements.txt` | Updated `requirements.txt` |
| --- | --- |
| <img width="550" alt="image" src="https://github.com/user-attachments/assets/d7dec16e-4f78-446d-a7e0-4d3b1d43bec4"> | <img width="550" alt="image" src="https://github.com/user-attachments/assets/b30e6450-515b-4070-b91b-8040ecbde738">
| <img width="550" alt="image" src="https://github.com/user-attachments/assets/d7dec16e-4f78-446d-a7e0-4d3b1d43bec4"> | <img width="550" alt="image" src="https://github.com/user-attachments/assets/b30e6450-515b-4070-b91b-8040ecbde738"> |

```text
azure-functions
Expand Down
113 changes: 113 additions & 0 deletions terraform-infrastructure/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
# Azure Infrastructure Terraform Templates

Costa Rica

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

Last updated: 2025-05-20

----------

<div align="center">
<img src="https://github.com/user-attachments/assets/39dd10d6-ae40-4c6d-8ed4-00551f9785c7" 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/8705bcff-2942-4e04-bfbc-c2881352f557" alt="Centered Image" style="border: 2px solid #4CAF50; border-radius: 5px; padding: 5px;"/>
</div>

## Overview

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

<div align="center">
<h3 style="color: #4CAF50;">Total Visitors</h3>
<img src="https://profile-counter.glitch.me/brown9804/count.svg" alt="Visitor Count" style="border: 2px solid #4CAF50; border-radius: 5px; padding: 5px;"/>
</div>
158 changes: 158 additions & 0 deletions terraform-infrastructure/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
# Resource Group
resource "azurerm_resource_group" "rg" {
name = var.resource_group_name
location = var.location

# Output the resource group name
provisioner "local-exec" {
command = "echo Resource Group: ${self.name}"
}
}
# Storage Account
resource "azurerm_storage_account" "storage" {
name = var.storage_account_name
resource_group_name = azurerm_resource_group.rg.name
location = azurerm_resource_group.rg.location
account_tier = "Standard"
account_replication_type = "LRS"

depends_on = [azurerm_resource_group.rg]

# Output the storage account name
provisioner "local-exec" {
command = "echo Storage Account: ${self.name}"
}
}

# Blob Container for Input Files
resource "azurerm_storage_container" "input_container" {
name = "input"
storage_account_id = azurerm_storage_account.storage.id
container_access_type = "private"

depends_on = [azurerm_storage_account.storage]

# Output the container name
provisioner "local-exec" {
command = "echo Input Container: ${self.name}"
}
}

# Blob Container for Output Files
resource "azurerm_storage_container" "output_container" {
name = "output"
storage_account_id = azurerm_storage_account.storage.id
container_access_type = "private"

depends_on = [azurerm_storage_account.storage]

# Output the container name
provisioner "local-exec" {
command = "echo Output Container: ${self.name}"
}
}

# Linux Function App
resource "azurerm_linux_function_app" "function_app" {
name = var.function_app_name
location = azurerm_resource_group.rg.location
resource_group_name = azurerm_resource_group.rg.name
service_plan_id = azurerm_service_plan.asp.id
storage_account_name = azurerm_storage_account.storage.name
storage_account_access_key = azurerm_storage_account.storage.primary_access_key

site_config {
# Other configurations can go here
}

depends_on = [azurerm_service_plan.asp]

provisioner "local-exec" {
command = "echo Function App: ${self.name}"
}
}


# Service Plan
resource "azurerm_service_plan" "asp" {
name = var.app_service_plan_name
location = azurerm_resource_group.rg.location
resource_group_name = azurerm_resource_group.rg.name
os_type = "Linux"
sku_name = "Y1" # Consumption plan

depends_on = [azurerm_resource_group.rg]

# Output the service plan name
provisioner "local-exec" {
command = "echo Service Plan: ${self.name}"
}
}

# Application Insights
resource "azurerm_application_insights" "appinsights" {
name = var.app_insights_name
location = azurerm_resource_group.rg.location
resource_group_name = azurerm_resource_group.rg.name
application_type = "web"
workspace_id = azurerm_log_analytics_workspace.loganalytics.id

depends_on = [azurerm_resource_group.rg]

provisioner "local-exec" {
command = "echo Application Insights: ${self.name}"
}
}

# Log Analytics Workspace
resource "azurerm_log_analytics_workspace" "loganalytics" {
name = var.log_analytics_workspace_name
location = azurerm_resource_group.rg.location
resource_group_name = azurerm_resource_group.rg.name
sku = "PerGB2018"

depends_on = [azurerm_resource_group.rg]

# Output the log analytics workspace name
provisioner "local-exec" {
command = "echo Log Analytics Workspace: ${self.name}"
}
}

# Key Vault
resource "azurerm_key_vault" "keyvault" {
name = var.key_vault_name
location = azurerm_resource_group.rg.location
resource_group_name = azurerm_resource_group.rg.name
tenant_id = data.azurerm_client_config.current.tenant_id
sku_name = "standard"

depends_on = [azurerm_resource_group.rg]

# Output the key vault name
provisioner "local-exec" {
command = "echo Key Vault: ${self.name}"
}
}

# Data source to get tenant ID
data "azurerm_client_config" "current" {}

# CosmosDB
resource "azurerm_cosmosdb_account" "cosmosdb" {
name = var.cosmosdb_account_name
location = azurerm_resource_group.rg.location
resource_group_name = azurerm_resource_group.rg.name
offer_type = "Standard"
kind = "GlobalDocumentDB"
consistency_policy {
consistency_level = "Session"
}

geo_location {
location = azurerm_resource_group.rg.location
failover_priority = 0
}

depends_on = [azurerm_resource_group.rg]
}
50 changes: 50 additions & 0 deletions terraform-infrastructure/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
output "resource_group_name" {
description = "The name of the resource group."
value = azurerm_resource_group.rg.name
}

output "storage_account_name" {
description = "The name of the storage account"
value = azurerm_storage_account.storage.name
}

output "input_container_name" {
description = "The name of the input container"
value = azurerm_storage_container.input_container.name
}

output "output_container_name" {
description = "The name of the output container"
value = azurerm_storage_container.output_container.name
}

output "function_app_name" {
description = "The name of the Linux Function App."
value = azurerm_linux_function_app.function_app.name
}

output "app_service_plan_name" {
description = "The name of the Service Plan"
value = azurerm_service_plan.asp.name
}

output "app_insights_name" {
description = "The name of the Application Insights instance"
value = azurerm_application_insights.appinsights.name
}

output "log_analytics_workspace_name" {
description = "The name of the Log Analytics workspace"
value = azurerm_log_analytics_workspace.loganalytics.name
}

output "key_vault_name" {
description = "The name of the Key Vault"
value = azurerm_key_vault.keyvault.name
}


output "cosmosdb_account_name" {
description = "The name of the CosmosDB account."
value = azurerm_cosmosdb_account.cosmosdb.name
}
Loading