Skip to content

Commit 5ba8c23

Browse files
authored
update azure function module + tests (#402)
1 parent aad5569 commit 5ba8c23

File tree

14 files changed

+382
-365
lines changed

14 files changed

+382
-365
lines changed

infra/modules/providers/azure/function-app/README.md

Lines changed: 27 additions & 209 deletions
Original file line numberDiff line numberDiff line change
@@ -31,216 +31,33 @@ The following app-settings are automatically applied if variables information is
3131
__Application Insights__
3232

3333
```
34-
var.instrumentation_key --> APPINSIGHTS_INSTRUMENTATIONKEY
34+
var.app_insights_instrumentation_key --> APPINSIGHTS_INSTRUMENTATIONKEY
3535
```
3636

3737
__Private Registry Information__ _(All DOCKER variables have to exist)_
3838
```
39-
var.docker_registry_server_url_app_setting --> DOCKER_REGISTRY_SERVER_URL
40-
var.docker_registry_server_username_app_setting --> DOCKER_REGISTRY_SERVER_USERNAME
41-
var.docker_registry_server_password_app_setting --> DOCKER_REGISTRY_SERVER_PASSWORD
39+
var.docker_registry_server_url --> DOCKER_REGISTRY_SERVER_URL
40+
var.docker_registry_server_username --> DOCKER_REGISTRY_SERVER_USERNAME
41+
var.docker_registry_server_password --> DOCKER_REGISTRY_SERVER_PASSWORD
4242
```
4343

4444
### Basic Usage Example
4545

46-
```h
47-
locals {
48-
unique = "${random_id.sample.hex}"
49-
rg = "iac-sample"
50-
storage_name = "${local.unique}sa"
51-
plan_name = "${local.unique}-ap"
52-
functionapp_name = "${local.unique}-fa"
53-
}
54-
55-
resource "azurerm_resource_group" "sample" {
56-
name = local.rg
57-
location = "eastus"
58-
}
59-
60-
resource "random_id" "sample" {
61-
keepers = {
62-
resource_group = azurerm_resource_group.sample.name
63-
}
64-
65-
byte_length = 4
66-
}
67-
68-
module "storage_account" {
69-
source = "../../storage-account"
70-
71-
name = replace(local.storage_name, "-", "")
72-
resource_group_name = azurerm_resource_group.sample.name
73-
74-
container_names = []
75-
}
76-
77-
module "service_plan" {
78-
source = "../../service-plan"
79-
80-
service_plan_name = local.plan_name
81-
resource_group_name = azurerm_resource_group.sample.name
82-
83-
service_plan_tier = "PremiumV2"
84-
service_plan_size = "P1v2"
85-
}
46+
```hcl-terraform
8647
8748
module "function_app" {
88-
source = "../"
89-
90-
name = local.unique
91-
resource_group_name = azurerm_resource_group.sample.name
92-
93-
storage_account_name = module.storage_account.name
94-
service_plan_id = module.service_plan.app_service_plan_id
95-
96-
function_app_config = {
97-
javafunc : {
98-
app_settings = {
99-
"FUNCTIONS_EXTENSION_VERSION" = "~2",
100-
"WEBSITES_ENABLE_APP_SERVICE_STORAGE" = false
101-
"FUNCTIONS_WORKER_RUNTIME" = "java"
102-
}
103-
image = ""
104-
},
105-
dotnetfunc : {
106-
app_settings = {
107-
"FUNCTIONS_EXTENSION_VERSION" = "~2",
108-
"WEBSITES_ENABLE_APP_SERVICE_STORAGE" = false
109-
"FUNCTIONS_WORKER_RUNTIME" = "dotnet"
110-
}
111-
image = ""
112-
}
113-
}
49+
source = "../../modules/providers/azure/function-app"
50+
fn_name_prefix = local.func_app_name_prefix
51+
resource_group_name = azurerm_resource_group.app_rg.name
52+
service_plan_id = module.service_plan.id
53+
storage_account_resource_group_name = module.sys_storage_account.resource_group_name
54+
storage_account_name = module.sys_storage_account.name
55+
vnet_subnet_id = module.network.subnet_ids[0]
56+
fn_app_settings = local.func_app_settings
57+
fn_app_config = var.fn_app_config
11458
}
11559
```
11660

117-
### Advanced Usage Example
118-
119-
```h
120-
locals {
121-
unique = "${random_id.sample.hex}"
122-
rg = "iac-testing"
123-
storage_name = "iac${local.unique}sa"
124-
insights_name = "iac${local.unique}-in"
125-
vault_name = "iac${local.unique}-kv"
126-
plan_name = "iac${local.unique}-ap"
127-
registry_name = "iac${local.unique}cr"
128-
functionapp_name = "${local.unique}-fa"
129-
principal_name = "iac${local.unique}"
130-
131-
secret_map = {
132-
for secret in module.keyvault_container_secrets.keyvault_secret_attributes :
133-
secret.name => secret.id
134-
}
135-
}
136-
137-
resource "azurerm_resource_group" "sample" {
138-
name = local.rg
139-
location = "eastus"
140-
}
141-
142-
resource "random_id" "sample" {
143-
keepers = {
144-
resource_group = azurerm_resource_group.sample.name
145-
}
146-
147-
byte_length = 4
148-
}
149-
150-
module "storage_account" {
151-
source = "../../storage-account"
152-
153-
name = replace(local.storage_name, "-", "")
154-
resource_group_name = azurerm_resource_group.sample.name
155-
156-
container_names = []
157-
}
158-
159-
module "service_plan" {
160-
source = "../../service-plan"
161-
162-
service_plan_name = local.principal_name
163-
resource_group_name = azurerm_resource_group.sample.name
164-
165-
service_plan_tier = "PremiumV2"
166-
service_plan_size = "P1v2"
167-
}
168-
169-
module "keyvault" {
170-
source = "../../keyvault"
171-
172-
keyvault_name = "${local.vault_name}"
173-
resource_group_name = azurerm_resource_group.sample.name
174-
}
175-
176-
module "keyvault_function_app_access_policy" {
177-
source = "../../keyvault-policy"
178-
179-
vault_id = module.keyvault.keyvault_id
180-
tenant_id = module.function_app.identity_tenant_id
181-
object_ids = module.function_app.identity_object_ids
182-
key_permissions = [ "get", "list"]
183-
secret_permissions = [ "get", "list"]
184-
certificate_permissions = [ "get", "list"]
185-
}
186-
187-
module "container_registry" {
188-
source = "../../container-registry"
189-
190-
container_registry_name = local.registry_name
191-
resource_group_name = azurerm_resource_group.sample.name
192-
193-
container_registry_sku = "Standard"
194-
container_registry_admin_enabled = false
195-
}
196-
197-
module "service_principal" {
198-
source = "../../service-principal"
199-
200-
display_name = local.principal_name
201-
202-
create_for_rbac = true
203-
role_name = "Reader"
204-
role_scopes = [module.container_registry.container_registry_id]
205-
}
206-
207-
module "keyvault_container_secrets" {
208-
source = "../../keyvault-secret"
209-
210-
keyvault_id = module.keyvault.keyvault_id
211-
secrets = {
212-
registryusername = module.service_principal.service_principal_application_id
213-
registrypassword = module.service_principal.service_principal_password
214-
}
215-
}
216-
217-
module "function_app" {
218-
source = "../"
219-
220-
name = "iac${local.unique}"
221-
resource_group_name = local.unique
222-
223-
storage_account_name = module.storage_account.name
224-
service_plan_id = module.service_plan.app_service_plan_id
225-
226-
docker_registry_server_url_app_setting = module.container_registry.container_registry_login_server
227-
docker_registry_server_username_app_setting = format("@Microsoft.KeyVault(SecretUri=%s)", local.secret_map.registryusername)
228-
docker_registry_server_password_app_setting = format("@Microsoft.KeyVault(SecretUri=%s)", local.secret_map.registrypassword)
229-
230-
function_app_config = {
231-
function1 : {
232-
app_settings = {
233-
"FUNCTIONS_EXTENSION_VERSION" = "~2",
234-
"WEBSITES_ENABLE_APP_SERVICE_STORAGE" = false
235-
"FUNCTIONS_WORKER_RUNTIME" = "java"
236-
}
237-
image = ""
238-
}
239-
}
240-
}
241-
242-
```
243-
24461

24562
### Prerequisites
24663
This module assumes that there are a [resource group](https://docs.microsoft.com/en-us/azure/azure-resource-manager/manage-resource-groups-portal#create-resource-groups), an [app service plan](https://docs.microsoft.com/en-us/azure/app-service/overview-hosting-plans), and a [storage account resource](https://docs.microsoft.com/en-us/azure/storage/common/storage-account-overview)
@@ -255,14 +72,21 @@ You will need to provide the following information for the dependencies:
25572

25673
This is a map where the key is the `function_app_name` and the definition for the function app:
25774

258-
- **`app_settings`:** The function app settings config map.
259-
- **`image`:** The docker image name.
75+
- For Docker based deployment, the object has one field:
76+
image: which refers to the docker image name to deploy.
77+
- For running from a package, it should contains the fields:
78+
- zip: contains an http reference to the package.
79+
80+
> This will enable your function app to run from a package by adding a WEBSITE_RUN_FROM_PACKAGE setting to your function app settings.
81+
82+
- hash: contains a hash of the zip file for downloads integrity check.
83+
26084

26185
### Manually deploying Private ACR Images
26286

263-
If no image is deployed due to the usage of a Private ACR configuration then the `image` should be left blank and images can be deployed post terraform provisioning has occured by using the Azure CLI or some other process.
87+
If no image is deployed due to the usage of a Private ACR configuration then the `image` should be left blank and images can be deployed post terraform provisioning has occured by using the Azure CLI or some other process. The below example uses the Azure CLI and docker.
26488

265-
```
89+
```bash
26690
RESOURCE_GROUP="<resource_group_name>"
26791
REGISTRY_SERVER="<registry_server_name>"
26892
FUNCTION_APP="<function_app_name>"
@@ -281,16 +105,10 @@ az functionapp config container set --docker-custom-image-name $REGISTRY_SERVER.
281105
```
282106

283107

284-
## Resources
285-
286-
| Resource | Description |
287-
|--------|-------------|
288-
| azurerm_function_app | The actual azure function app resources being created and deployed. |
289-
290108
### Input Variables
291109

292-
Please refer to [variables.tf](./variables.tf).
110+
Please refer to [variables.tf](variables.tf).
293111

294112
### Output Variables
295113

296-
Please refer to [output.tf](./output.tf).
114+
Please refer to [output.tf](output.tf).

infra/modules/providers/azure/function-app/azuredeploy.json

Lines changed: 0 additions & 37 deletions
This file was deleted.

0 commit comments

Comments
 (0)