- simple example doing OCR using Azure Function Apps, Cognitive Services Blob Storage in combination with terraform
- prerequisits
azure-cli
,azure subscription
- fork this repo
azure-cli
login
az login
- list subscriptions
az account list
- set correct subscription
az account set --subscription="...<SUBSCRIPTION_ID>..."
- create service account
az ad sp create-for-rbac --role="Contributor" --scopes="/subscriptions/...<SUBSCRIPTION_ID>..."
{
"appId": "...",
"displayName": "...",
"name": "...",
"password": "...",
"tenant": "..."
}
- remember these mappings
ARM_CLIENT_ID = appId
ARM_CLIENT_SECRET = password
ARM_TENANT_ID = tenant
ARM_SUBSCRIPTION_ID can be found in the `Azure Portal` or in the `Service Principal` account `id`
- login as
Service Principal
az login --service-principal -u <client-id> -p <client-secret> --tenant <tenant-id>
- set values in
github
>>settings
>>secrets
ARM_CLIENT_ID="..."
ARM_CLIENT_SECRET="..."
ARM_SUBSCRIPTION_ID="..."
ARM_TENANT_ID="..."
- you need
terraform
installed - follow [setup terraform tfstate in azure](##setup terraform tfstate in azure)
- login as
Service Principal
az login --service-principal -u <client-id> -p <client-secret> --tenant <tenant-id>
- init project
terraform init -reconfigure
- plan, execute following command and enter credentials
terraform plan -out "planfile"
- apply
terraform apply -input=false "planfile"
- generate resource group
azure-terraform-ocr-tfstate
in azure console - generate storage account
tfstatestoraccXYZ
in azure console, this is a custom value and need to be globaly unique in azure, remember thekey
under menuAccess keys
, deactivateEnable blob public access
, choseLRS
- generate storage container
tfstatestorcon
in azure console - set values in
github
>>settings
>>secrets>>actions
AZDO_PERSONAL_ACCESS_TOKEN=...key...
TFSTATE_STORAGE_ACCOUNT_NAME=tfstatestoraccXYZ
TF_VAR_CUSTOMIZERE=...<custom and unique code for url's, e.g. '0815'>...
- select function folder
cd azure_functions
- install function build tools
npm install -g azure-functions-core-tools@3 --unsafe-perm true
or
brew tap azure/functions
brew install azure-functions-core-tools@3
- initialize function project
func init
- start function locally
func start
- deploy function
npm ci
func azure functionapp publish azure-terraform-ocr-node-functions
TODO