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
| Resource | Used for | Setup notes |
|---|---|---|
| Resource group | Organizes the existing app resources | Managed in terraform/; matches AZURE_RESOURCE_GROUP |
| Function App, runtime v4 / Python 3.11 | Hourly processing | Match the CI Python minor version and runtime locks |
| Function host storage | Runtime and timer coordination | Configured through AzureWebJobsStorage |
| Results storage account | Public JSON and private season state | Configured through RESULTS_STORAGE_CONNECTION_STRING |
| Azure Communication Services Email | Winner and recap delivery | Configure a verified sender and connect it to ACS |
| Azure Static Web App | Browser UI in public/ | No linked API or frontend build is required |
| Microsoft Entra application | GitLab deployment identity | Uses 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-statecontainer. - 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:
az loginaz account set --subscription <subscription-id>az group show --name rg-football-pool --query '{id:id,location:location}' -o jsonThe 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:
glab auth loginglab opentofu init production -d terraformexport ARM_SUBSCRIPTION_ID=<subscription-id>tofu -chdir=terraform planReview 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
- Configure the Function’s host storage through its Azure runtime setup.
- Enable static website hosting on the results account to create
$web, or ensure the intended$webcontainer exists. The app expects it to exist. - 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.
- Keep
pool-stateprivate. The Function creates it if absent; its credentials need container creation and blob read/write permissions. - Configure Blob service CORS for each browser origin that reads the feed.
- 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-
Create an Entra app registration and its service principal.
-
Add a federated credential with the following exact values for your project:
Field Value Issuer https://gitlab.comfor this repositorySubject project_path:bclingan-development/cloud/azure-ravens-pool:ref_type:branch:ref:mainAudience api://AzureADTokenExchangeUpdate the subject if the project path or default branch changes. A self-managed GitLab issuer must expose discovery and signing keys to Azure.
-
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. -
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:
- Packages
function_app.py,host.json,requirements.txt, and.py,.html,.txt, and.cssfiles beneathapp/into/tmp/function.zip. - Logs in with the federated identity and selects the subscription.
- Removes
WEBSITE_RUN_FROM_PACKAGEand enablesSCM_DO_BUILD_DURING_DEPLOYMENT=trueandENABLE_ORYX_BUILD=true. - Submits the ZIP with
--build-remote trueand 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:
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 setting | Value |
|---|---|
| App location | /public |
| API location | Empty |
| Output location | Empty |
| Frontend build command | None |
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.