-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.tf
160 lines (134 loc) · 5.42 KB
/
main.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
terraform {
required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = "3.54.0"
}
}
backend "azurerm" {
resource_group_name = "table-storage-experiments"
storage_account_name = "jmorjsmtse"
container_name = "tfstate"
key = "terraform.tfstate"
}
}
provider "azurerm" {
features {}
}
variable "GHCR_USERNAME" {
type = string
}
variable "GHCR_PASSWORD" {
type = string
}
variable "RESULTS_API_ZIP_DEPLOY_FILE" {
type = string
}
resource "azurerm_resource_group" "table_storage_experiments" {
name = "table-storage-experiments-results"
location = "West US"
}
resource "azurerm_storage_account" "table_storage_experiments_results" {
name = "jmorjsmtseresults"
resource_group_name = azurerm_resource_group.table_storage_experiments.name
location = azurerm_resource_group.table_storage_experiments.location
account_tier = "Standard"
account_replication_type = "GRS"
tags = {
environment = "testing"
}
}
resource "azurerm_container_group" "table_storage_experiments" {
name = "storage-experiment-continst"
location = azurerm_resource_group.table_storage_experiments.location
resource_group_name = azurerm_resource_group.table_storage_experiments.name
ip_address_type = "Public"
dns_name_label = "tserunner"
os_type = "Linux"
restart_policy = "Never"
container {
name = "storage-experiment"
image = "ghcr.io/jmorjsm/azure-table-storage-experiments:latest"
cpu = "0.5"
memory = "1.5"
ports {
port = 9998
protocol = "UDP"
}
environment_variables = {
"TABLE_STORAGE_CONNECTION_STRING" = azurerm_storage_account.table_storage_experiments_results.primary_connection_string
}
}
image_registry_credential {
server = "ghcr.io"
username = var.GHCR_USERNAME
password = var.GHCR_PASSWORD
}
tags = {
environment = "testing"
}
}
resource "azurerm_service_plan" "results_service_plan" {
name = "results-service-plan"
resource_group_name = azurerm_resource_group.table_storage_experiments.name
location = azurerm_resource_group.table_storage_experiments.location
os_type = "Linux"
sku_name = "B1"
}
# data "local_file" "results_api_function_app_zip" {
# filename = var.RESULTS_API_ZIP_DEPLOY_FILE
# }
resource "azurerm_storage_container" "results_api_function_app_storage_container" {
name = "results-api-function-app-storage-container"
storage_account_name = azurerm_storage_account.table_storage_experiments_results.name
container_access_type = "private"
}
resource "azurerm_storage_blob" "storage_blob" {
name = "${filesha256(var.RESULTS_API_ZIP_DEPLOY_FILE)}.zip"
storage_account_name = azurerm_storage_account.table_storage_experiments_results.name
storage_container_name = azurerm_storage_container.results_api_function_app_storage_container.name
type = "Block"
source = var.RESULTS_API_ZIP_DEPLOY_FILE
}
data "azurerm_storage_account_blob_container_sas" "storage_account_blob_container_sas" {
connection_string = azurerm_storage_account.table_storage_experiments_results.primary_connection_string
container_name = azurerm_storage_container.results_api_function_app_storage_container.name
start = "${formatdate("YYYY-MM-DD", timestamp())}T00:00:00Z"
expiry = "${formatdate("YYYY-MM-DD", timeadd(timestamp(), "24h"))}T00:00:00Z"
permissions {
read = true
add = false
create = false
write = false
delete = false
list = false
}
}
resource "azurerm_application_insights" "results_api_insights" {
name = "results-api-insights"
location = azurerm_resource_group.table_storage_experiments.location
resource_group_name = azurerm_resource_group.table_storage_experiments.name
application_type = "web"
}
resource "azurerm_linux_function_app" "results_api_function_app" {
name = "results-api-function-app"
resource_group_name = azurerm_resource_group.table_storage_experiments.name
location = azurerm_service_plan.results_service_plan.location
storage_account_name = azurerm_storage_account.table_storage_experiments_results.name
storage_account_access_key = azurerm_storage_account.table_storage_experiments_results.primary_access_key
service_plan_id = azurerm_service_plan.results_service_plan.id
app_settings = {
"WEBSITE_RUN_FROM_PACKAGE" = "https://${azurerm_storage_account.table_storage_experiments_results.name}.blob.core.windows.net/${azurerm_storage_container.results_api_function_app_storage_container.name}/${azurerm_storage_blob.storage_blob.name}${data.azurerm_storage_account_blob_container_sas.storage_account_blob_container_sas.sas}",
"STORAGE_CONNECTION" = "${azurerm_storage_account.table_storage_experiments_results.primary_connection_string}",
"WEBSITE_CONTENTAZUREFILECONNECTIONSTRING" = "${azurerm_storage_account.table_storage_experiments_results.primary_connection_string}",
"WEBSITE_CONTENTSHARE" = "${azurerm_storage_container.results_api_function_app_storage_container.name}",
"APPINSIGHTS_INSTRUMENTATIONKEY" = "${azurerm_application_insights.results_api_insights.instrumentation_key}"
}
site_config {
always_on = false
use_32_bit_worker = true
application_stack {
python_version = "3.10"
}
}
}