This directory contains Terraform configuration files to provision all Azure resources needed to run the CAPWATCH synchronization functions.
- Azure CLI installed and authenticated (
az login) - Terraform installed (version >= 1.0)
- Azure subscription with appropriate permissions to create resources
- CAPWATCH credentials (username and password for CAPWATCH API)
-
Clone and navigate to terraform directory:
cd terraform -
Create your configuration file:
cp terraform.tfvars.example terraform.tfvars
-
Edit
terraform.tfvarswith your wing's specific values:wing_designator = "TX" # Your wing's 2-letter code capwatch_org_id = "456" # Your wing's CAPWATCH Organization ID exchange_organization = "TXCivilAirPatrol.onmicrosoft.com"
-
After deployment, add CAPWATCH credentials to Key Vault:
az keyvault secret set --vault-name <your-keyvault-name> --name capwatch-username --value "your-capwatch-username" az keyvault secret set --vault-name <your-keyvault-name> --name capwatch-password --value "your-capwatch-password"
-
Initialize Terraform:
terraform init
-
Plan the deployment:
terraform plan
-
Deploy the infrastructure:
terraform apply
main.tf- Main infrastructure resourcesvariables.tf- Input variables and validationoutputs.tf- Output values and deployment instructionssecrets.tf- Key Vault secrets managementterraform.tfvars.example- Example configuration file
| Resource | Purpose |
|---|---|
| Resource Group | Container for all resources |
| Function App | Hosts the PowerShell automation functions |
| App Service Plan | Consumption plan for serverless execution |
| Storage Account | Required for Function App operation |
| Key Vault | Securely stores CAPWATCH credentials |
| Application Insights | Monitoring and logging |
| Azure AD Application | Enterprise app for Microsoft Graph permissions |
| Service Principal | Identity for API access |
| Variable | Description | Example |
|---|---|---|
wing_designator |
Two-letter wing code | "TX" |
capwatch_org_id |
CAPWATCH Organization ID | "456" |
exchange_organization |
Exchange Online domain | "TXCivilAirPatrol.onmicrosoft.com" |
capwatch_username |
CAPWATCH username | "john.doe" |
capwatch_password |
CAPWATCH password | "secretpassword" |
| Variable | Description | Default |
|---|---|---|
location |
Azure region | "East US" |
timezone |
Function App timezone | "Mountain Standard Time" |
log_email_to_address |
Email for notifications | "" |
log_email_from_address |
Sender email | "" |
- Managed Identity for secure Azure resource access
- Key Vault for credential storage with proper access policies
- Least-privilege permissions on all resources
- No plaintext secrets in configuration files
After successful deployment, follow these steps:
-
Grant Microsoft Graph API permissions in Microsoft Entra ID:
- Go to Azure Portal > Microsoft Entra ID > Manage > App registrations (for application permissions)
- (You can also use Enterprise applications to view the service principal, but admin consent is granted in App registrations)
- Find your app (e.g., CAPWATCHSync-CO)
- Go to API permissions
- Click Grant admin consent for [your tenant]
- Confirm that the required Microsoft Graph permissions are listed and consented
-
Deploy Function App code using Azure Functions Core Tools
-
Test the functions starting with
download-extract-capwatch -
Monitor logs in Application Insights
-
Validate deployment:
terraform validate
-
Check resource status:
az resource list --resource-group $(terraform output -raw resource_group_name) -
Test Key Vault access:
az keyvault secret show --vault-name $(terraform output -raw key_vault_name) --name capwatch-username
To remove all resources:
terraform destroy-
Insufficient permissions:
- Ensure you have
Contributorrole on the subscription - Ensure you have
Application Administratorrole in Azure AD
- Ensure you have
-
Key Vault access denied:
- Verify your user has appropriate Key Vault access policies
- Check that the Function App managed identity is granted access
-
Function App deployment fails:
- Verify all environment variables are set correctly
- Check Application Insights logs for detailed error messages
- Check Terraform plan output before applying
- Review Azure Activity Logs for resource creation issues
- Use
terraform refreshto sync state with actual resources - Enable Terraform debug logging:
export TF_LOG=DEBUG
- The Azure AD application requires admin consent for Microsoft Graph permissions
- CAPWATCH credentials are encrypted at rest in Key Vault
- Function App uses system-assigned managed identity for secure access
- All resources are tagged for easy management and cost tracking