@@ -31,38 +31,106 @@ resource "azurerm_service_plan" "stacklet" {
31
31
tags = local. tags
32
32
}
33
33
34
+ # Generate the function.json with queue name
35
+ resource "local_file" "function_json" {
36
+ content = jsonencode ({
37
+ scriptFile = " __init__.py"
38
+ bindings = [
39
+ {
40
+ name = " msg"
41
+ type = " queueTrigger"
42
+ direction = " in"
43
+ queueName = azurerm_storage_queue.stacklet.name
44
+ connection = " AzureWebJobsStorage"
45
+ }
46
+ ]
47
+ })
48
+ filename = " ${ path . module } /function-app-v1/ProviderRelay/function.json"
49
+ }
50
+
51
+ # Create host.json with enhanced logging configuration
52
+ resource "local_file" "host_json" {
53
+ content = jsonencode ({
54
+ version = " 2.0"
55
+ logging = {
56
+ applicationInsights = {
57
+ samplingSettings = {
58
+ isEnabled = true
59
+ excludedTypes = " Request"
60
+ }
61
+ }
62
+ logLevel = {
63
+ default = " Information"
64
+ " ProviderRelay" = " Information"
65
+ " azure.functions" = " Warning"
66
+ " azure.storage" = " Warning"
67
+ }
68
+ }
69
+ functions = [" ProviderRelay" ]
70
+ extensionBundle = {
71
+ id = " Microsoft.Azure.Functions.ExtensionBundle"
72
+ version = " [4.*, 5.0.0)"
73
+ }
74
+ })
75
+ filename = " ${ path . module } /function-app-v1/host.json"
76
+ }
77
+
78
+ # Create the function app deployment package
79
+ data "archive_file" "function_app" {
80
+ depends_on = [local_file . function_json , local_file . host_json ]
81
+
82
+ type = " zip"
83
+ source_dir = " ${ path . module } /function-app-v1"
84
+ output_path = " ${ path . module } /function-app.zip"
85
+ }
86
+
87
+ # azurerm_linux_function_app's zip_deploy_file will only redeploy the function
88
+ # when the path changes, so copy the zip to a versioned filename.
89
+ resource "local_file" "function_app_versioned" {
90
+ filename = " ${ path . module } /function-app-${ data . archive_file . function_app . output_sha256 } .zip"
91
+ source = " ${ path . module } /function-app.zip"
92
+ }
93
+
34
94
resource "azurerm_linux_function_app" "stacklet" {
35
95
name = " stacklet-${ var . prefix } -function-app-${ substr (random_string. storage_account_suffix . result , 0 , 15 )} "
36
96
resource_group_name = azurerm_resource_group. stacklet_rg . name
37
97
location = azurerm_resource_group. stacklet_rg . location
98
+ service_plan_id = azurerm_service_plan. stacklet . id
38
99
39
100
storage_account_name = azurerm_storage_account. stacklet . name
40
101
storage_account_access_key = azurerm_storage_account. stacklet . primary_access_key
41
- service_plan_id = azurerm_service_plan. stacklet . id
102
+
103
+ # Deploy from zip file
104
+ zip_deploy_file = local_file. function_app_versioned . filename
42
105
43
106
site_config {
107
+ application_insights_key = azurerm_application_insights. stacklet . instrumentation_key
108
+
44
109
application_stack {
45
- python_version = " 3.10 "
110
+ python_version = " 3.12 "
46
111
}
47
- application_insights_key = azurerm_application_insights. stacklet . instrumentation_key
48
112
}
49
113
50
114
app_settings = {
115
+ # Build and deployment settings
51
116
SCM_DO_BUILD_DURING_DEPLOYMENT = true
52
- AZURE_CLIENT_ID = azurerm_user_assigned_identity.stacklet_identity.client_id
53
- AZURE_AUDIENCE = local.audience
54
- AZURE_STORAGE_QUEUE_NAME = azurerm_storage_queue.stacklet.name
55
- AWS_TARGET_ACCOUNT = var.aws_target_account
56
- AWS_TARGET_REGION = var.aws_target_region
57
- AWS_TARGET_ROLE_NAME = var.aws_target_role_name
58
- AWS_TARGET_PARTITION = var.aws_target_partition
59
- AWS_TARGET_EVENT_BUS = var.aws_target_event_bus
117
+
118
+ # Application configuration
119
+ AZURE_CLIENT_ID = azurerm_user_assigned_identity.stacklet_identity.client_id
120
+ AZURE_AUDIENCE = local.audience
121
+ AZURE_STORAGE_QUEUE_NAME = azurerm_storage_queue.stacklet.name
122
+ AWS_TARGET_ACCOUNT = var.aws_target_account
123
+ AWS_TARGET_REGION = var.aws_target_region
124
+ AWS_TARGET_ROLE_NAME = var.aws_target_role_name
125
+ AWS_TARGET_PARTITION = var.aws_target_partition
126
+ AWS_TARGET_EVENT_BUS = var.aws_target_event_bus
60
127
}
61
128
62
129
identity {
63
130
type = " UserAssigned"
64
131
identity_ids = [azurerm_user_assigned_identity . stacklet_identity . id ]
65
132
}
133
+
66
134
tags = local. tags
67
135
68
136
lifecycle {
@@ -71,27 +139,3 @@ resource "azurerm_linux_function_app" "stacklet" {
71
139
]
72
140
}
73
141
}
74
-
75
- resource "local_file" "function_json" {
76
- content = templatefile (
77
- " ${ path . module } /function-app-v1/ProviderRelay/function.json.tmpl" , { queue_name = azurerm_storage_queue.stacklet.name })
78
- filename = " ${ path . module } /function-app-v1/ProviderRelay/function.json"
79
- }
80
-
81
-
82
- resource "null_resource" "function_deploy" {
83
- depends_on = [azurerm_linux_function_app . stacklet , local_file . function_json ]
84
- # ensures that publish always runs
85
- triggers = {
86
- build_number = " ${ timestamp ()} "
87
- }
88
-
89
- # initial deployment of the function-app could race with provisioning, so sleep 10 seconds
90
- provisioner "local-exec" {
91
- command = << EOF
92
- cd ${ path . module } /function-app-v1
93
- sleep 10
94
- func azure functionapp publish ${ azurerm_linux_function_app . stacklet . name } --python
95
- EOF
96
- }
97
- }
0 commit comments