Create automated pull requests for Terraform-managed AWS infrastructure by using GitHub Actions
Matt Padgett, Ashish Bhatt, Ashwin Divakaran, Sandip Gangapadhyay, and Prafful Gupta, Amazon Web Services
Summary
This pattern presents an automation utility that’s designed to eliminate the manual, repetitive work involved in managing changes across multiple Terraform repositories. Many organizations use Terraform repositories to manage their infrastructure as code (IaC), often with hundreds of separate repositories representing different environments, services, or teams. Managing these repositories at scale presents a significant operational challenge. Routine tasks such as updating a parameter, upgrading module versions, or applying configuration changes often require creating and managing pull requests (PRs) across many repositories multiple times a day.
Even for simple changes, this repetitive and manual process is time-consuming and error prone. Engineers must consistently apply the same change across all targeted repositories and craft meaningful PR titles and descriptions. In addition, they often must interact with external tools like Jira to fetch or include issue tracking references. These tasks, while necessary, are undifferentiated heavy lifting that consume valuable engineering time and reduce overall efficiency. The lack of automation in this workflow creates friction, slows down delivery, and increases the cognitive burden on teams tasked with maintaining large-scale Terraform infrastructures.
Solution overview
To address this challenge, this pattern offers a utility that’s entirely configuration-driven, allowing users to define their desired changes in a structured configuration file. This file specifies the target repositories, modules, parameters, and values using a clearly defined schema.
Once configured, the utility performs the following automated steps:
- Reads the user-defined configuration to determine the scope and nature of changes 
- Creates a new branch in each target repository with the required updates applied 
- Generates a PR for each change, ensuring consistency across all repositories 
- Sends Slack notifications (optional) to alert stakeholders with direct links to the created PRs 
By automating these repetitive tasks, the utility significantly reduces the time, effort, and risk associated with managing large-scale infrastructure updates. It enables teams to focus on higher-value engineering work while helping to ensure that changes are applied consistently and can be traced across all repositories.
Prerequisites and limitations
Prerequisites
- An active AWS account. 
- Python version 3.8 or later. 
- A GitHub personal access token (PAT). For more information, see Creating a personal access token (classic) - in the GitHub documentation. 
- The GitHub PAT can access your target repositories so that the utility can perform operations like creating branches and pull requests. For more information, see this pattern’s GitHub code repository - . 
Limitations
- Configuration complexity presents the primary challenge. The automation's effectiveness is constrained by the capabilities of its configuration file. Although the system handles standard changes efficiently, complex infrastructure modifications might require manual intervention and certain edge cases remain beyond the scope of automated handling. 
- Security and access presents significant considerations particularly in managing GitHub access tokens and API rate limits. Organizations must carefully balance the need for automation with secure credential storage and management, ensuring proper access controls while maintaining operational efficiency. 
- Validation constraints pose another notable limitation because the automated system has limited ability to validate business logic and environment-specific requirements. Complex dependencies and cross-service interactions often necessitate human oversight because automated validation can’t fully capture all contextual nuances and business rules. 
- Scale and performance issues emerge when dealing with large-scale infrastructure changes. The system must operate within GitHub API limits while managing numerous repositories simultaneously. Resource-intensive operations across extensive infrastructure can create performance bottlenecks that require careful management. 
- Integration boundaries restrict the system's flexibility because it's primarily designed to work with specific tools like GitHub and Slack. Organizations that use different tools might need custom solutions and the workflow customization options of this pattern are limited to supported integration points. 
Architecture
The following diagram shows the workflow and components for this solution.

The workflow consists of the following steps:
- The developer triggers GitHub Actions by specifying the Terraform repository. 
- The automation utility reads the defined configurations. 
- The automation utility also pulls the provided Terraform repository. 
- The automation utility creates a new branch and makes updates to Terraform templates locally. 
- The automation utility pushes the new branch to the repository and creates a new PR. 
- The automation utility uses Slack notifications that include PR links to notify developers and enables Terraform templates for AWS Cloud deployment. 
Tools
- GitHub - is a developer platform that developers can use to create, store, manage, and share their code. 
- GitHub Actions - is a continuous integration and continuous delivery (CI/CD) platform that’s tightly integrated with GitHub repositories. You can use GitHub Actions to automate your build, test, and deployment pipeline. 
- HashiCorp Terraform - is an infrastructure as code (IaC) tool that helps you create and manage cloud and on-premises resources. 
- Slack - , a Salesforce offering, is an AI-powered conversational platform that provides chat and video collaboration, automates processes with no code, and supports information sharing. 
Code repository
The code for this pattern is available in the GitHub Automated Terraform Infrastructure Update Workflow using GitHub Actions
Best practices
- Effective change management is crucial for successful implementation. Organizations should adopt a gradual rollout strategy for large-scale changes. Maintain consistent branch naming conventions and PR descriptions and ensure comprehensive documentation of all changes. 
- Security controls must be rigorously implemented, focusing on least-privilege access principles and secure credential management. Enable branch protection rules to prevent unauthorized changes. Conduct regular security audits to maintain system integrity. 
- A robust testing protocol should include automated - terraform planexecution in continuous integration and continuous deployment (CI/CD) pipelines. The protocol should also include pre-commit validation checks, and dedicated review environments for critical changes. This multi-layered testing approach helps catch issues early and ensures infrastructure stability.
- Monitoring strategy needs to encompass comprehensive alerting mechanisms, detailed success/failure metrics tracking, and automated retry mechanisms for failed operations. This strategy helps to ensure operational visibility and enables quick response to any issues that arise. 
- Configuration standards should emphasize version control for all configurations, maintaining modularity for reusability and scalability. Clear documentation of schema and examples helps teams understand and use the automation system effectively. 
Epics
| Task | Description | Skills required | 
|---|---|---|
| Set up the repository. | To set up the repository, run the following commands: 
 | AWS DevOps | 
| Install dependencies. | To install and verify the Python dependencies, run the following commands: 
 | AWS DevOps | 
| Configure the GitHub token. | To configure the GitHub token and then verify that it works, run the following commands: 
 | AWS DevOps | 
| Task | Description | Skills required | 
|---|---|---|
| Set up the  | To define your target repositories and desired changes, edit the  
 | AWS DevOps | 
| Task | Description | Skills required | 
|---|---|---|
| Do pre-flight testing. | Always test your configuration before running it on production repositories. Use the following commands: 
 | AWS DevOps | 
| Verify repository access. | To verify that the GitHub token can access the repository, run the following command: 
 | AWS DevOps | 
| Task | Description | Skills required | 
|---|---|---|
| Run the automation utility by using the GitHub Actions UI. | To run the automation utility using the GitHub Actions UI, do the following: 
 | AWS DevOps | 
| (Alternative) Run the automation utility from the command line. | If you prefer, you can run the automation utility from the command line instead of by using the GitHub Actions UI. Use the following command: 
 | AWS DevOps | 
| Task | Description | Skills required | 
|---|---|---|
| Review the created PRs and changes. | To monitor the results of the GitHub workflow execution, do the following: 
 | AWS DevOps | 
| Task | Description | Skills required | 
|---|---|---|
| (Optional) Clean up PRs. | Close abandoned or unnecessary PRs. | AWS DevOps | 
Related resources
AWS Prescriptive Guidance
GitHub documentation