Module for deploying serverless MLflow instance on Azure, using Serverless SQL Server, Container App Service and Azure Blob Storage. Deployed instance has built-in authentication mechanism with support for Azure Active Directory or Google providers (see AUTHENTICATION section).
data "azurerm_resource_group" "this" {
name = "my-resource-group"
}
module "azure_mlfow" {
source = "../.."
context = module.this.context
resource_group = data.azurerm_resource_group.this.name
auth = {
type = "azureActiveDirectory"
client_secret = ""
client_id = ""
azureActiveDirectory = {
tenant_id = ""
}
}
}
Useful docs:
- https://docs.microsoft.com/en-us/azure/container-apps/authentication
- AD: https://docs.microsoft.com/en-us/azure/container-apps/authentication-azure-active-directory
- Google: https://docs.microsoft.com/en-us/azure/container-apps/authentication-google
As of 2022-08-11 the module only supports AD and Google providers.
As far as I've tested, when using Google provider, Authorization: Bearer <token>
header is not supported, so using this with MLflow will require implementing additional mlflow.request_header_provider
.
- Obtain Client ID and Client Secret from GCP OAuth Credentials.
- Set the
auth
variable in the module:
auth = {
type = "google"
client_secret = "<client secret>"
client_id = "<client id>"
}
- Run terraform apply
- Take the
mlflow_tracking_uri
output from the module and set appropriate callback in Google OAuth 2.0 config:<mlflow_tracking_uri>/.auth/login/google/callback
- Save the settings.
Users will login with standard redirect to Google page.
Needs to use: https://docs.microsoft.com/en-us/azure/container-apps/authentication#client-directed-sign-in
- Obtain the token
export T=$(curl -X POST -L https://<mlflow url on .azurecontainerapps.io>/.auth/login/google -d "{\"id_token\": \"$(gcloud auth print-identity-token)\"}" -H "Content-Type: application/json" | jq -r .authenticationToken )
- Use the token
curl -L https://<mlflow url on .azurecontainerapps.io>/api/2.0/mlflow/experiments/list -H "X-Zumo-Auth: $T"
- Create App Registration in Azure Active Directory
- Fill the name (for now, Redirect URL will be empty).
- In the newly created app, open
Certificates & secrets
section. - In
Client secrets
tab, clickNew client secret
and create one. SaveValue
(this value will be only displayed once!). - Set the
auth
variable in the module:
auth = {
type = "azureActiveDirectory"
client_secret = "<client secret>"
client_id = "<Application (client) ID>"
azureActiveDirectory = {
tenant_id = "<Directory (tenant) ID>"
}
}
- Run terraform apply
- Take the
mlflow_tracking_uri
output from the module - Open
Authentication
section, in Platform configurations clickAdd platform
, selectWeb
, fill inRedirect URIs
with<mlflow_tracking_uri>/.auth/login/aad/callback
, selectID tokens (used for implicit and hybrid flows)
and click Configure.
Users will login with standard redirect to Microsoft login page.
- Prepare:
- client id
- client secret
- tenant id
- Obtain the token from Microsoft endpoint
export T=$(curl -X POST -H 'Content-Type: application/x-www-form-urlencoded' \
https://login.microsoftonline.com/<tenant id>/oauth2/v2.0/token \
-d 'client_id=<client id>' \
-d 'grant_type=client_credentials' \
-d 'scope=<client id>%2f.default' \
-d 'client_secret=<client secret>' | jq -r .access_token)
Note that scope
has both <client id>
and a suffix %2f.default
which is a url encoded ./default
.
- Use the token
curl -L https://<mlflow url on .azurecontainerapps.io>/api/2.0/mlflow/experiments/list -H "Authorization: Bearer $T"
data "azurerm_resource_group" "this" {
name = "my-resource-group"
}
module "azure_mlfow" {
source = "../.."
context = module.this.context
resource_group_name = data.azurerm_resource_group.this.name
# auth = {
# type = "google"
# client_secret = ""
# client_id = ""
# }
auth = {
type = "azureActiveDirectory"
client_secret = ""
client_id = ""
azureActiveDirectory = {
tenant_id = ""
}
}
}
Name | Description | Type | Default | Required |
---|---|---|---|---|
additional_tag_map | Additional key-value pairs to add to each map in tags_as_list_of_maps . Not added to tags or id .This is for some rare cases where resources want additional configuration of tags and therefore take a list of maps with tag key, value, and additional configuration. |
map(string) |
{} |
no |
attributes | ID element. Additional attributes (e.g. workers or cluster ) to add to id ,in the order they appear in the list. New attributes are appended to the end of the list. The elements of the list are joined by the delimiter and treated as a single ID element. |
list(string) |
[] |
no |
auth | OAuth2.0 provider configuration for MLflow app instance. Supported types: azureActiveDirectory, google | object({ |
n/a | yes |
context | Single object for setting entire context at once. See description of individual variables for details. Leave string and numeric variables as null to use default value.Individual variable settings (non-null) override settings in context object, except for attributes, tags, and additional_tag_map, which are merged. |
any |
{ |
no |
cpu | Container App CPU requirements | number |
0.75 |
no |
db_admin_username | Database Server root username | string |
"mlflow_root" |
no |
db_backup_type | Storage account type used to store backups for this database. One of: Geo, GeoZone, Local, Zone | string |
"Local" |
no |
db_max_size_gb | Max database size in GB | number |
4 |
no |
delimiter | Delimiter to be used between ID elements. Defaults to - (hyphen). Set to "" to use no delimiter at all. |
string |
null |
no |
descriptor_formats | Describe additional descriptors to be output in the descriptors output map.Map of maps. Keys are names of descriptors. Values are maps of the form {<br> format = string<br> labels = list(string)<br>} (Type is any so the map values can later be enhanced to provide additional options.)format is a Terraform format string to be passed to the format() function.labels is a list of labels, in order, to pass to format() function.Label values will be normalized before being passed to format() so they will beidentical to how they appear in id .Default is {} (descriptors output will be empty). |
any |
{} |
no |
enabled | Set to false to prevent the module from creating any resources | bool |
null |
no |
environment | ID element. Usually used for region e.g. 'uw2', 'us-west-2', OR role 'prod', 'staging', 'dev', 'UAT' | string |
null |
no |
id_length_limit | Limit id to this many characters (minimum 6).Set to 0 for unlimited length.Set to null for keep the existing setting, which defaults to 0 .Does not affect id_full . |
number |
null |
no |
label_key_case | Controls the letter case of the tags keys (label names) for tags generated by this module.Does not affect keys of tags passed in via the tags input.Possible values: lower , title , upper .Default value: title . |
string |
null |
no |
label_order | The order in which the labels (ID elements) appear in the id .Defaults to ["namespace", "environment", "stage", "name", "attributes"]. You can omit any of the 6 labels ("tenant" is the 6th), but at least one must be present. |
list(string) |
null |
no |
label_value_case | Controls the letter case of ID elements (labels) as included in id ,set as tag values, and output by this module individually. Does not affect values of tags passed in via the tags input.Possible values: lower , title , upper and none (no transformation).Set this to title and set delimiter to "" to yield Pascal Case IDs.Default value: lower . |
string |
null |
no |
labels_as_tags | Set of labels (ID elements) to include as tags in the tags output.Default is to include all labels. Tags with empty values will not be included in the tags output.Set to [] to suppress all generated tags.Notes: The value of the name tag, if included, will be the id , not the name .Unlike other null-label inputs, the initial setting of labels_as_tags cannot bechanged in later chained modules. Attempts to change it will be silently ignored. |
set(string) |
[ |
no |
location | Location for all of the resources. Falls back to the Resource Group's default. | string |
null |
no |
log_analytics_workspace_id | Existing log analytics workspace id (or leave null to create one) |
string |
null |
no |
max_replicas | Max number of Container App replicas | number |
1 |
no |
memory | Container App memory requirements | string |
"1.5Gi" |
no |
min_replicas | Min number of Container App replicas | number |
0 |
no |
mlflow_docker_image | MLflow docker image. See https://github.com/getindata/mlflow-docker | string |
"gcr.io/getindata-images-public/mlflow:azure-1.28.0" |
no |
name | ID element. Usually the component or solution name, e.g. 'app' or 'jenkins'. This is the only ID element not also included as a tag .The "name" tag is set to the full id string. There is no tag with the value of the name input. |
string |
null |
no |
namespace | ID element. Usually an abbreviation of your organization name, e.g. 'eg' or 'cp', to help ensure generated IDs are globally unique | string |
null |
no |
regex_replace_chars | Terraform regular expression (regex) string. Characters matching the regex will be removed from the ID elements. If not set, "/[^a-zA-Z0-9-]/" is used to remove all characters other than hyphens, letters and digits. |
string |
null |
no |
resource_group_name | Resource Group name | string |
n/a | yes |
stage | ID element. Usually used to indicate role, e.g. 'prod', 'staging', 'source', 'build', 'test', 'deploy', 'release' | string |
null |
no |
storage_sku | Azure Storage Account SKU. See https://docs.microsoft.com/en-us/rest/api/storagerp/srp_sku_types | string |
"Standard_GRS" |
no |
tags | Additional tags (e.g. {'BusinessUnit': 'XYZ'} ).Neither the tag keys nor the tag values will be modified by this module. |
map(string) |
{} |
no |
tenant | ID element _(Rarely used, not included by default)_. A customer identifier, indicating who this instance of a resource is for | string |
null |
no |
Name | Source | Version |
---|---|---|
storage_account | getindata/storage-account/azurerm | 1.1.0 |
this | cloudposse/label/null | 0.25.0 |
Name | Description |
---|---|
mlflow_tracking_uri | Link to deployed MLflow instance |
storage_connection_string | Connection string to MLflow's blob storage account |
Name | Version |
---|---|
azapi | 0.4.0 |
azurerm | >=3.17.0 |
random | >=3.3.2 |
Name | Version |
---|---|
terraform | >= 1.3.0 |
azapi | 0.4.0 |
azurerm | >=3.17.0 |
random | >=3.3.2 |
Name | Type |
---|---|
azapi_resource.managed_environment | resource |
azapi_resource.mlflow_app | resource |
azapi_resource.mlflow_app_auth | resource |
azurerm_log_analytics_workspace.log_workspace | resource |
azurerm_mssql_database.mlflow_db | resource |
azurerm_mssql_firewall_rule.mlflow_db_firewall_allow_internal | resource |
azurerm_mssql_server.mlflow_db_server | resource |
random_password.db_password | resource |
azurerm_log_analytics_workspace.log_workspace | data source |
azurerm_resource_group.rg | data source |
azurerm_storage_account.storage_account | data source |
Contributions are very welcomed!
Start by reviewing contribution guide and our code of conduct. After that, start coding and ship your changes by creating a new PR.
Apache 2 Licensed. See LICENSE for full details.
Made with contrib.rocks.