Skip to content

Azure resources and setup

The pipeline targets a Python 3.11 Linux Consumption Function App and an Azure Static Web App. OpenTofu manages the resource group and its durable application infrastructure. Separate deployment jobs publish the Function and website code.

Resource checklist

ResourceUsed forSetup notes
Resource groupOrganizes the existing app resourcesManaged in terraform/; matches AZURE_RESOURCE_GROUP
Function App, runtime v4 / Python 3.11Hourly processingMatch the CI Python minor version and runtime locks
Function host storageRuntime and timer coordinationConfigured through AzureWebJobsStorage
Results storage accountPublic JSON and private season stateConfigured through RESULTS_STORAGE_CONNECTION_STRING
Azure Communication Services EmailWinner and recap deliveryConfigure a verified sender and connect it to ACS
Azure Static Web AppBrowser UI in public/No linked API or frontend build is required
Microsoft Entra applicationGitLab deployment identityUses workload identity federation for Function deployment

These are the repository’s deployment assumptions, not an inventory retrieved from a live Azure subscription. Verify the existing resource names and hosting plan in Azure before using the settings below.

Manage Azure infrastructure with OpenTofu

The generated infrastructure reference lists providers, resources, inputs, and outputs. After editing the configuration, run terraform-docs terraform from the repository root using terraform-docs v0.20.0 and commit the updated README. CI checks that it stays current.

The OpenTofu configuration manages the resource group and its durable application infrastructure:

  • Communication Services, Email Communication Services, and the sender domain.
  • Application Insights, its smart detection action group, and alert rule.
  • Both storage accounts, their static website settings, and the private pool-state container.
  • The Consumption service plan and Linux Function App.
  • The Static Web App and its custom domain.

Azure generated Function runtime containers, deployment records, diagnostic tables, the content file share, the deployed function definition, and default host binding remain service-managed. Application code and Function settings keep their existing deployment paths. The Function’s app_settings are intentionally ignored by OpenTofu so CI deployment and secure runtime configuration do not conflict with infrastructure plans.

From the repository root, sign in with an Azure identity that can read and manage the resource group, then select the subscription and inspect the existing group:

Terminal window
az login
az account set --subscription <subscription-id>
az group show --name rg-football-pool --query '{id:id,location:location}' -o json

The configuration records the verified group name rg-football-pool and location eastus. The existing resources have been imported into the GitLab-managed production state. The checked-in import blocks make the import history reproducible and do nothing once their resources are in state. To use that state locally, authenticate with glab, configure the backend, and export the subscription ID for the AzureRM provider:

Terminal window
glab auth login
glab opentofu init production -d terraform
export ARM_SUBSCRIPTION_ID=<subscription-id>
tofu -chdir=terraform plan

Review the plan for unexpected changes. Prefer the saved GitLab plan and its manual tofu:apply job for changes to shared infrastructure. An unchanged group should produce a no-change plan. GitLab runs formatting and validation on branches, then creates a plan on the default branch. If the group already has tags or a managed_by value, add those settings to the resource block before applying so OpenTofu does not remove them. Local state is ignored by Git. Keep the CI variable AZURE_RESOURCE_GROUP equal to the OpenTofu output resource_group_name.

The GitLab workload identity needs Contributor scoped to rg-football-pool to read and manage the imported resources. It cannot assign Azure roles. Its federated credential must accept the default branch subject used by the pipeline. Keep AZURE_CLIENT_ID, AZURE_TENANT_ID, and AZURE_SUBSCRIPTION_ID protected and available to the production/terraform environment. GitLab stores and locks the remote state; users who run apply need Maintainer or Owner access to the project.

1. Prepare storage and email

  1. Configure the Function’s host storage through its Azure runtime setup.
  2. Enable static website hosting on the results account to create $web, or ensure the intended $web container exists. The app expects it to exist.
  3. Allow anonymous blob reads for the published results at the Blob endpoint if using the current direct browser URL. Public access to the Storage website endpoint alone does not establish public Blob endpoint access.
  4. Keep pool-state private. The Function creates it if absent; its credentials need container creation and blob read/write permissions.
  5. Configure Blob service CORS for each browser origin that reads the feed.
  6. Set up the verified ACS email sender and populate the application settings in the configuration reference.

Storage’s *.web.core.windows.net website endpoint and *.blob.core.windows.net/$web/... Blob endpoint behave differently. The website endpoint does not support Storage CORS; the application uses the Blob endpoint for cross-origin JSON. See Azure Storage website behavior and the public website guide.

2. Configure GitLab identity for the Function

sequenceDiagram
    participant Job as GitLab deployment job
    participant Entra as Microsoft Entra ID
    participant Azure as Azure Resource Manager
    Job->>Job: Request job OIDC token
    Job->>Entra: Exchange token using client and tenant IDs
    Entra->>Entra: Validate issuer, subject, and audience
    Entra-->>Job: Short-lived Azure credentials
    Job->>Azure: Configure remote build and deploy ZIP
  1. Create an Entra app registration and its service principal.

  2. Add a federated credential with the following exact values for your project:

    FieldValue
    Issuerhttps://gitlab.com for this repository
    Subjectproject_path:bclingan-development/cloud/azure-ravens-pool:ref_type:branch:ref:main
    Audienceapi://AzureADTokenExchange

    Update the subject if the project path or default branch changes. A self-managed GitLab issuer must expose discovery and signing keys to Azure.

  3. Grant the service principal Contributor scoped to rg-football-pool. OpenTofu needs this scope to manage the imported resources, and the same role permits the Function deployment. It does not permit role assignments.

  4. Protect the default branch and configure the five AZURE_* identity/resource variables listed in configuration.

GitLab generates AZURE_OIDC_TOKEN for the job. Do not store that token or create a client secret to replace it. GitLab’s Azure OIDC guide describes the federation flow.

3. Deploy the Function

The deploy:function job:

  1. Packages function_app.py, host.json, requirements.txt, and .py, .html, .txt, and .css files beneath app/ into /tmp/function.zip.
  2. Logs in with the federated identity and selects the subscription.
  3. Removes WEBSITE_RUN_FROM_PACKAGE and enables SCM_DO_BUILD_DURING_DEPLOYMENT=true and ENABLE_ORYX_BUILD=true.
  4. Submits the ZIP with --build-remote true and a 600-second command timeout.

Azure installs the fully pinned requirements.txt using the Function’s configured Python version. Changes to app settings can restart the Function. The pipeline leaves storage credentials and email settings managed in Azure.

See Python build options for the remote-build model. This ZIP and these settings are specific to the current hosting approach; do not carry them unchanged to another hosting plan.

For a manual code deployment from the repository root, after configuring and verifying the destination:

Terminal window
func azure functionapp publish <function-app-name>

The application exposes only the 15-minute timer. Use Function invocation logs and published data to verify it; do not assume /api/ping exists.

4. Deploy the public website

The deploy:production job installs the locked Static Web Apps CLI and deploys public/ to the production environment with SWA_DEPLOYMENT_TOKEN.

SWA build settingValue
App location/public
API locationEmpty
Output locationEmpty
Frontend build commandNone

The CLI receives Node runtime metadata even though this is a static-only site. No Function source is linked to this deployment. The feed URL and CORS settings are covered in public website.

Custom domains are configured on the Static Web App. Use the DNS record and validation steps shown by Azure, then add the custom domain’s origin to Blob CORS as well. See Static Web Apps custom domains.

Hosting lifecycle

Microsoft lists Linux Consumption retirement as September 30, 2028. Plan a move to Flex Consumption before retirement and revisit packaging, identity, build settings, and operational checks as part of that work. See Azure Functions hosting guidance.