Skip to content

Commit 7b84757

Browse files
committed
infra provisioning template
1 parent 3428bc4 commit 7b84757

5 files changed

Lines changed: 267 additions & 0 deletions

File tree

terraform/src/main.tf

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
# Resource Group
2+
resource "azurerm_resource_group" "rg" {
3+
name = var.resource_group_name
4+
location = var.location
5+
6+
# Output the resource group name
7+
provisioner "local-exec" {
8+
command = "echo Resource Group: ${self.name}"
9+
}
10+
}
11+
12+
# Storage Account
13+
resource "azurerm_storage_account" "storage" {
14+
name = var.storage_account_name
15+
resource_group_name = azurerm_resource_group.rg.name
16+
location = azurerm_resource_group.rg.location
17+
account_tier = "Standard"
18+
account_replication_type = "LRS"
19+
20+
depends_on = [azurerm_resource_group.rg]
21+
22+
# Output the storage account name
23+
provisioner "local-exec" {
24+
command = "echo Storage Account: ${self.name}"
25+
}
26+
}
27+
28+
# Blob Container for Input Files
29+
resource "azurerm_storage_container" "input_container" {
30+
name = "input"
31+
storage_account_name = azurerm_storage_account.storage.name
32+
container_access_type = "private"
33+
34+
depends_on = [azurerm_storage_account.storage]
35+
36+
# Output the container name
37+
provisioner "local-exec" {
38+
command = "echo Input Container: ${self.name}"
39+
}
40+
}
41+
42+
# Blob Container for Output Files
43+
resource "azurerm_storage_container" "output_container" {
44+
name = "output"
45+
storage_account_name = azurerm_storage_account.storage.name
46+
container_access_type = "private"
47+
48+
depends_on = [azurerm_storage_account.storage]
49+
50+
# Output the container name
51+
provisioner "local-exec" {
52+
command = "echo Output Container: ${self.name}"
53+
}
54+
}
55+
56+
# Azure Function App
57+
resource "azurerm_function_app" "function_app" {
58+
name = var.function_app_name
59+
location = azurerm_resource_group.rg.location
60+
resource_group_name = azurerm_resource_group.rg.name
61+
storage_account_name = azurerm_storage_account.storage.name
62+
storage_account_access_key = azurerm_storage_account.storage.primary_access_key
63+
app_service_plan_id = azurerm_service_plan.asp.id
64+
os_type = "linux"
65+
runtime_stack = "python"
66+
67+
depends_on = [azurerm_service_plan.asp]
68+
69+
# Output the function app name
70+
provisioner "local-exec" {
71+
command = "echo Function App: ${self.name}"
72+
}
73+
}
74+
75+
# Service Plan
76+
resource "azurerm_service_plan" "asp" {
77+
name = var.app_service_plan_name
78+
location = azurerm_resource_group.rg.location
79+
resource_group_name = azurerm_resource_group.rg.name
80+
os_type = "Linux"
81+
sku_name = "Y1" # Consumption plan
82+
83+
depends_on = [azurerm_resource_group.rg]
84+
85+
# Output the service plan name
86+
provisioner "local-exec" {
87+
command = "echo Service Plan: ${self.name}"
88+
}
89+
}
90+
91+
# Application Insights
92+
resource "azurerm_application_insights" "appinsights" {
93+
name = var.app_insights_name
94+
location = azurerm_resource_group.rg.location
95+
resource_group_name = azurerm_resource_group.rg.name
96+
application_type = "web"
97+
98+
depends_on = [azurerm_resource_group.rg]
99+
100+
# Output the application insights name
101+
provisioner "local-exec" {
102+
command = "echo Application Insights: ${self.name}"
103+
}
104+
}
105+
106+
# Log Analytics Workspace
107+
resource "azurerm_log_analytics_workspace" "loganalytics" {
108+
name = var.log_analytics_workspace_name
109+
location = azurerm_resource_group.rg.location
110+
resource_group_name = azurerm_resource_group.rg.name
111+
sku = "PerGB2018"
112+
113+
depends_on = [azurerm_resource_group.rg]
114+
115+
# Output the log analytics workspace name
116+
provisioner "local-exec" {
117+
command = "echo Log Analytics Workspace: ${self.name}"
118+
}
119+
}
120+
121+
# Key Vault
122+
resource "azurerm_key_vault" "keyvault" {
123+
name = var.key_vault_name
124+
location = azurerm_resource_group.rg.location
125+
resource_group_name = azurerm_resource_group.rg.name
126+
tenant_id = var.tenant_id
127+
sku_name = "standard"
128+
129+
depends_on = [azurerm_resource_group.rg]
130+
131+
# Output the key vault name
132+
provisioner "local-exec" {
133+
command = "echo Key Vault: ${self.name}"
134+
}
135+
}

terraform/src/outputs.tf

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
output "resource_group_name" {
2+
description = "The name of the resource group"
3+
value = azurerm_resource_group.rg.name
4+
}
5+
6+
output "storage_account_name" {
7+
description = "The name of the storage account"
8+
value = azurerm_storage_account.storage.name
9+
}
10+
11+
output "input_container_name" {
12+
description = "The name of the input container"
13+
value = azurerm_storage_container.input_container.name
14+
}
15+
16+
output "output_container_name" {
17+
description = "The name of the output container"
18+
value = azurerm_storage_container.output_container.name
19+
}
20+
21+
output "function_app_name" {
22+
description = "The name of the Function App"
23+
value = azurerm_function_app.function_app.name
24+
}
25+
26+
output "app_service_plan_name" {
27+
description = "The name of the Service Plan"
28+
value = azurerm_service_plan.asp.name
29+
}
30+
31+
output "app_insights_name" {
32+
description = "The name of the Application Insights instance"
33+
value = azurerm_application_insights.appinsights.name
34+
}
35+
36+
output "log_analytics_workspace_name" {
37+
description = "The name of the Log Analytics workspace"
38+
value = azurerm_log_analytics_workspace.loganalytics.name
39+
}
40+
41+
output "key_vault_name" {
42+
description = "The name of the Key Vault"
43+
value = azurerm_key_vault.keyvault.name
44+
}

terraform/src/provider.tf

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
terraform {
2+
required_version = ">= 1.8, < 2.0"
3+
# Specify the required providers and their versions
4+
required_providers {
5+
azurerm = {
6+
source = "hashicorp/azurerm" # Source of the AzureRM provider
7+
version = "~> 4.16.0" # Version of the AzureRM provider
8+
}
9+
}
10+
}
11+
12+
provider "azurerm" {
13+
features {} # Enable all features for the AzureRM provider
14+
subscription_id = var.subscription_id
15+
}

terraform/src/terraform.tfvars

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Replace the placeholder values
2+
# (e.g., "your-subscription-id",
3+
# "your-resource-group-name", etc.)
4+
# with your actual values.
5+
6+
# Azure subscription ID
7+
subscription_id = "your-subscription-id"
8+
9+
# Resource Group
10+
resource_group_name = "your-resource-group-name"
11+
location = "your-location"
12+
13+
# Storage Account
14+
storage_account_name = "your-storage-account-name"
15+
16+
# Function App
17+
function_app_name = "your-function-app-name"
18+
19+
# App Service Plan
20+
app_service_plan_name = "your-app-service-plan-name"
21+
22+
# Application Insights
23+
app_insights_name = "your-app-insights-name"
24+
25+
# Log Analytics Workspace
26+
log_analytics_workspace_name = "your-log-analytics-workspace-name"
27+
28+
# Key Vault
29+
key_vault_name = "your-key-vault-name"

terraform/src/variables.tf

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
variable "subscription_id" {
2+
description = "The subscription ID for the Azure account"
3+
type = string
4+
}
5+
6+
variable "resource_group_name" {
7+
description = "The name of the resource group"
8+
type = string
9+
}
10+
11+
variable "location" {
12+
description = "The Azure region to deploy resources"
13+
type = string
14+
}
15+
16+
variable "storage_account_name" {
17+
description = "The name of the storage account"
18+
type = string
19+
}
20+
21+
variable "function_app_name" {
22+
description = "The name of the Function App"
23+
type = string
24+
}
25+
26+
variable "app_service_plan_name" {
27+
description = "The name of the App Service plan"
28+
type = string
29+
}
30+
31+
variable "app_insights_name" {
32+
description = "The name of the Application Insights instance"
33+
type = string
34+
}
35+
36+
variable "log_analytics_workspace_name" {
37+
description = "The name of the Log Analytics workspace"
38+
type = string
39+
}
40+
41+
variable "key_vault_name" {
42+
description = "The name of the Key Vault"
43+
type = string
44+
}

0 commit comments

Comments
 (0)