AI coding assistants can now generate infrastructure code, create GitHub Actions workflows, configure deployment steps, and suggest changes to Azure resources. This can make cloud deployment faster, especially when developers need to create a new environment or modify an existing application.
However, generating infrastructure code is not the same as deploying it safely.
An AI-generated Bicep template might create a resource with excessive permissions. A workflow might grant more access than necessary. A deployment script might replace an existing resource configuration or expose sensitive values. These problems can become serious when generated code is connected directly to a production Azure environment.
The right approach is to treat AI as an infrastructure development assistant, not as an authority that can approve and deploy its own changes.
GitHub Actions, Azure authentication, infrastructure validation, and deployment approval should work together to ensure that every infrastructure change is reviewed before it reaches Azure.
Why AI-Generated Infrastructure Needs Additional Controls
Consider a developer asking an AI assistant to create an Azure environment for an ASP.NET Core application.
The assistant might generate:
An Azure App Service plan and web application.
An Azure SQL Database.
An Azure Storage Account.
An Application Insights resource.
A Bicep template to deploy these resources.
A GitHub Actions workflow to automate deployment.
The generated code may be syntactically correct and still contain security or operational problems.
For example, an AI-generated workflow might assign Contributor permissions at the subscription level when the application only needs permission to deploy resources into one resource group.
Similarly, a generated storage account configuration might allow public network access when the application should use private connectivity.
The main risks include:
Risk | Possible impact |
|---|
Excessive Azure permissions | Unauthorized resource modifications |
Incorrect resource configuration | Security and availability problems |
Unreviewed infrastructure changes | Accidental deletion or replacement |
Exposed credentials | Unauthorized Azure access |
Unsafe workflow permissions | Compromised deployment pipeline |
Missing environment approval | Uncontrolled production deployments |
Unverified third-party actions | Supply chain security risks |
These problems are not exclusive to AI-generated code. However, AI can produce large infrastructure changes quickly, making it easier for developers to overlook important details.
Separate Infrastructure Generation From Deployment Approval
One of the most important design decisions is to separate the process of generating infrastructure from the process of deploying it.
An AI assistant can help developers create or modify Bicep files and GitHub Actions workflows. However, those changes should go through the same review and validation process as manually written infrastructure code.
A recommended workflow looks like this:
A developer requests an infrastructure change from an AI assistant.
The assistant generates or modifies the Bicep template.
The changes are committed to a feature branch.
GitHub Actions validates the infrastructure code.
Security checks identify risky configurations.
Azure What-If previews the expected infrastructure changes.
Developers review and approve the pull request.
The production deployment waits for the required environment approval.
GitHub Actions authenticates with Azure and deploys the approved infrastructure.
Post-deployment checks verify that the application and resources are working correctly.
This approach allows developers to benefit from AI-generated infrastructure without allowing generated code to bypass existing deployment controls.
Store Infrastructure as Code in GitHub
Infrastructure should be maintained in the same version-controlled repository or a dedicated infrastructure repository.
For Azure environments, Bicep is a useful option because it provides declarative syntax for defining Azure resources.
Consider the following example:
param location string = resourceGroup().location
param appName string
param environmentName string = 'production'
resource appServicePlan 'Microsoft.Web/serverfarms@2024-04-01' = {
name: '${appName}-${environmentName}-plan'
location: location
sku: {
name: 'B1'
capacity: 1
}
kind: 'linux'
properties: {
reserved: true
}
}
resource webApp 'Microsoft.Web/sites@2024-04-01' = {
name: '${appName}-${environmentName}'
location: location
kind: 'app,linux'
properties: {
serverFarmId: appServicePlan.id
httpsOnly: true
siteConfig: {
minTlsVersion: '1.2'
linuxFxVersion: 'DOTNETCORE|8.0'
}
}
}
This template defines an App Service plan and a Linux web application.
An AI assistant can generate an initial version of this template, but developers should verify the selected resource API versions, runtime configuration, pricing tier, networking requirements, and security settings before using it.
For example, the application runtime should match the version supported by the actual application and hosting environment. The example is illustrative and should be adjusted to the target deployment.
A useful repository structure could look like this:
my-application/
│
├── src/
│ └── WebApplication/
│
├── infrastructure/
│ ├── main.bicep
│ ├── parameters/
│ │ ├── development.bicepparam
│ │ └── production.bicepparam
│ └── modules/
│
├── .github/
│ └── workflows/
│ ├── validate-infrastructure.yml
│ └── deploy-infrastructure.yml
│
└── README.md
Keeping infrastructure separate from application code makes it easier to review changes, identify ownership, and maintain environment-specific configurations.
Validate AI-Generated Bicep Templates Before Deployment
A successful Bicep build does not guarantee that the generated infrastructure is secure or suitable for production.
Validation should include syntax checks, template validation, security analysis, and a preview of the changes that Azure will receive.
Start with the Bicep build command:
az bicep build --file infrastructure/main.bicep
This checks the template and generates its corresponding ARM JSON representation.
You can also validate the deployment against the target resource group:
az deployment group validate \
--resource-group rg-myapp-production \
--template-file infrastructure/main.bicep
The next important step is to preview the deployment:
az deployment group what-if \
--resource-group rg-myapp-production \
--template-file infrastructure/main.bicep
The What-If operation predicts the changes that would happen if the template were deployed. It does not apply those changes.
For example, the output might indicate:
A new App Service will be created.
An existing storage account will be modified.
A network configuration will be replaced.
A resource will be deleted.
This information is especially important when AI modifies an existing infrastructure template rather than creating a new one.
Developers should pay particular attention to unexpected resource deletions, replacements, permission changes, and networking modifications.
What-If is a preview, not a complete security guarantee. Some deployment structures and external dependencies may limit what Azure can evaluate. The results still need to be reviewed.
Configure Secure GitHub Actions Authentication With Azure
GitHub Actions needs an identity to access Azure during deployment.
A common mistake is storing a long-lived Azure client secret directly in GitHub repository secrets. Although this can work, it introduces another credential that must be protected, rotated, and monitored.
OpenID Connect provides a better approach for supported GitHub Actions and Azure configurations.
With OIDC, GitHub Actions obtains a short-lived identity token. Microsoft Entra ID validates the federated identity configuration and allows the workflow to authenticate without storing a long-lived Azure client secret.
The Azure identity should trust only the intended GitHub repository and deployment context.
For example, a production identity should be configured to trust the production environment of the correct repository rather than accepting tokens from every branch or repository.
A GitHub Actions workflow can use the Azure Login action:
name: Deploy Azure Infrastructure
on:
push:
branches:
- main
paths:
- 'infrastructure/**'
- '.github/workflows/deploy-infrastructure.yml'
permissions:
contents: read
id-token: write
jobs:
deploy:
runs-on: ubuntu-latest
environment: production
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Login to Azure
uses: azure/login@v2
with:
client-id: ${{ vars.AZURE_CLIENT_ID }}
tenant-id: ${{ vars.AZURE_TENANT_ID }}
subscription-id: ${{ vars.AZURE_SUBSCRIPTION_ID }}
- name: Deploy infrastructure
run: |
az deployment group create \
--resource-group rg-myapp-production \
--template-file infrastructure/main.bicep
This is a simplified example. The action references should be pinned to verified full-length commit SHAs in a hardened production workflow. The Azure identity also needs an appropriately scoped role assignment and a federated credential that matches the GitHub environment.
Notice the permissions section:
permissions:
contents: read
id-token: write
The workflow receives read access to repository contents and permission to request an OIDC token.
Avoid granting additional GitHub token permissions unless the workflow actually requires them.
Use Separate Permissions for Validation and Deployment
Infrastructure validation and infrastructure deployment do not need the same level of access.
A validation workflow should generally use read-only access wherever possible. It can build templates, run static checks, and inspect deployment changes without receiving permission to modify Azure resources.
The deployment workflow needs write access, but that access should be limited to the target resource group or another clearly defined deployment scope.
For example:
Workflow | Required access |
|---|
Bicep build | Repository read access |
Static security analysis | Repository read access |
Azure template validation | Appropriate validation permissions |
Azure What-If | Permissions required for the preview operation |
Development deployment | Scoped development permissions |
Production deployment | Scoped production permissions |
Azure What-If uses the same permission requirements as the corresponding deployment operation. Therefore, a preview identity should not automatically be assumed to need only read access.
Where possible, use separate identities for development and production. This prevents a development workflow from accidentally receiving production deployment permissions.
Protect Production Deployments With GitHub Environments
Even after infrastructure validation succeeds, production deployment should not automatically proceed without considering the impact of the change.
GitHub Environments provide deployment protection rules that can require manual approval, restrict deployments to selected branches, and protect environment-specific secrets and variables.
For example, the following job references the production environment:
jobs:
deploy-production:
runs-on: ubuntu-latest
environment: production
steps:
- name: Deploy infrastructure
run: echo "Deploying approved infrastructure"
The actual approval requirement is configured in the repository's environment settings.
A production environment can be configured to:
Allow deployments only from the main branch.
Require approval from designated reviewers.
Keep production-specific configuration separate.
Prevent unapproved workflows from accessing protected environment secrets.
This creates an important separation of responsibilities.
An AI assistant can generate a deployment workflow, but it cannot independently approve a protected production deployment simply because it generated the infrastructure successfully.
For critical systems, the person reviewing the infrastructure change should understand its impact rather than approving it only because automated checks passed.
Check Security Policies Before Creating Azure Resources
AI-generated infrastructure should be checked against the organization's cloud security requirements.
For example, an organization might require:
HTTPS-only access for web applications.
Approved Azure regions.
Private networking for sensitive resources.
Managed identities instead of embedded credentials.
Diagnostic settings for important resources.
Required resource tags.
Restricted public network access.
Approved SKU and resource configurations.
Azure Policy can help enforce these requirements at the appropriate management group, subscription, or resource group scope.
For example, a policy can deny the creation of resources that do not meet a required configuration.
This is useful because GitHub-based validation alone cannot guarantee that every infrastructure deployment follows the organization's cloud governance requirements.
A developer or AI assistant might accidentally generate a storage account with public access enabled. A policy can prevent that configuration from being deployed when the relevant policy definition and assignment are correctly configured.
Static analysis tools can also inspect Bicep and other infrastructure files before deployment. These checks should complement Azure Policy rather than replace it.
Protect GitHub Actions From Unsafe Workflow Changes
The deployment workflow itself is part of the infrastructure security boundary.
If an AI assistant can modify workflow files, it could unintentionally introduce excessive permissions, untrusted actions, or unsafe deployment triggers.
There are several controls worth implementing.
Pin third-party actions
Avoid depending on mutable action tags for security-sensitive workflows.
For example:
uses: actions/checkout@v4
This is readable, but the tag can move. In a hardened workflow, use the verified full-length commit SHA for the action.
Also review third-party action source code and restrict which actions repositories are allowed to execute.
Avoid exposing deployment credentials to pull requests
Workflows that process code from external contributors should not receive production deployment permissions.
Use pull request workflows for validation and reserve deployment credentials for trusted branches and protected environments.
Be especially careful with the pull_request_target event. It runs in the context of the base repository and can have access to elevated permissions. Checking out and executing untrusted pull request code in such a workflow can create a serious security risk.
Require review for workflow changes
Changes to files under .github/workflows/ should receive additional review.
A generated workflow can change deployment triggers, token permissions, environment references, and the commands executed against Azure. These changes deserve the same attention as modifications to production infrastructure.
Common Mistakes to Avoid
Mistake | Better approach |
|---|
Deploying generated Bicep immediately | Validate and review the template first |
Giving AI-generated workflows subscription-wide access | Use scoped Azure identities |
Storing permanent Azure credentials in GitHub | Prefer OIDC federation |
Running production deployment on every pull request | Deploy from trusted branches and protected environments |
Trusting a successful Bicep build as a security check | Add policy and security validation |
Ignoring What-If output | Review resource additions, changes, and deletions |
Allowing AI to modify workflow permissions without review | Protect workflow files and require approval |
Using the same identity for every environment | Separate development and production identities |
Troubleshooting Deployment Problems
Even a well-designed pipeline can fail. The following situations are common when deploying AI-generated infrastructure.
Azure Login fails with a federated credential error
Check the federated identity credential configured in Microsoft Entra ID or the user-assigned managed identity.
The issuer, audience, and subject must match the token issued by GitHub Actions. A mismatch between the configured subject and the repository's branch or environment context can prevent authentication.
Also verify that the workflow has id-token: write permission.
What-If reports unexpected resource changes
Compare the generated Bicep template with the previous version.
Check whether the AI assistant changed resource names, API versions, properties, dependencies, or parameter values. Resource naming changes can sometimes cause Azure to create a new resource rather than update an existing one.
Do not proceed until the changes are understood.
Deployment fails because of insufficient permissions
Review the role assigned to the deployment identity and the scope at which it was assigned.
The identity may need additional permissions for a particular resource provider or deployment operation. Grant only the required permissions instead of automatically assigning a broad subscription-level role.
Production deployment is waiting for approval
Check the production environment's protection rules and reviewer configuration.
Confirm that the deployment is running from an allowed branch and that an authorized reviewer has approved the deployment.
A pending approval is an expected security control, not necessarily a workflow failure.
Best Practices for AI-Assisted Azure Infrastructure
A reliable deployment process should follow a few consistent rules:
Treat AI-generated infrastructure as proposed code, not trusted production code.
Keep Bicep templates and deployment workflows under version control.
Run syntax, template, and security validation before deployment.
Use Azure What-If to understand the expected impact of infrastructure changes.
Use OIDC instead of long-lived Azure credentials wherever supported.
Separate validation identities from deployment identities.
Apply least-privilege permissions at the smallest practical scope.
Protect production deployments with GitHub Environment approval rules.
Pin third-party GitHub Actions to verified full-length commit SHAs.
Monitor deployed resources and review configuration drift after deployment.
It is also useful to maintain a clear record of who requested an infrastructure change, what the AI assistant generated, which checks passed, who approved the change, and which workflow deployed it.
This makes troubleshooting and security investigations easier when an unexpected infrastructure change occurs.
Summary
AI assistants can reduce the time required to create Azure infrastructure and GitHub Actions workflows. However, faster infrastructure generation should not mean fewer security checks.
The safest approach is to keep AI-generated infrastructure inside a controlled deployment process. Store templates in GitHub, validate Bicep files, inspect Azure What-If results, enforce cloud security policies, and use OIDC for secure authentication.
GitHub Environments and protected branches provide additional control over production deployments, while scoped Azure identities help limit the impact of a compromised workflow.
AI should help developers write infrastructure code and automate repetitive deployment tasks. Decisions about permissions, security policies, and production approval should remain part of a controlled engineering process.
When these controls work together, teams can adopt AI-assisted infrastructure development while maintaining the security, reliability, and accountability expected from production Azure environments.
Join the conversation! Your thoughts help the community grow.