I'm currently interning as a PA in computer science, and I've been tasked with establishing a pipeline to deploy our Infrastructure as Code (IaC) in the cloud. I've already set up a basic pipeline where the CI stage selects the deployment environment based on the branch name—Main for production, feature/*, hotfix/*, and bugfix/* branches for development, and pull requests for testing. In the deployment stage, the pipeline runs the IaC using different input variables for the chosen environment.
Now, my senior engineer has asked me to dig into best practices for implementing these three environments both in the pipeline and in general. Our department is fairly new and is in the process of migrating from on-prem servers to Azure cloud. Although my senior engineer has a wealth of DevOps experience, he hasn't worked with a three-environment structure before, as he typically operated with just dev and prod due to budget constraints.
3 Answers
You're on the right track! Your senior engineer is focusing more on the architectural side of environment separation than on the CI syntax. Here are the key points for handling environments effectively:
1. **Environment Separation First**: Start with how environments are isolated before jumping into branch strategies. Usually, teams set it up like this:
- One account for production, and a separate one for non-production which includes development and testing. This helps not just with security but also simplifies identity management and reduces risks of accidental production access.
- Make sure each environment has distinct identities (like service principals), role assignments, and network boundaries.
2. **Environment-Agnostic IaC**: Your Infrastructure as Code should be flexible and not tied to a specific environment. Use reusable modules and specific configs for each environment. Keep state separate for each one to prevent issues down the line.
3. **Mandatory State Isolation**: Every environment should have its own remote state configuration. This ensures that changes in development won’t accidentally impact production and maintains clean separations between deployments.
If you want more in-depth resources, I recommend checking out Kostis and the Codefresh team's blogs. They have some great insights on effectively managing different environments in a CI/CD setup: [Stop Using Branches for Different GitOps Environments](https://codefresh.io/blog/stop-using-branches-deploying-different-gitops-environments/). It's more Kubernetes-focused, but the principles apply regardless of your setup.
Your senior's request might seem like a lot, but remember this kind of work usually requires some solid experience. This setup impacts the long-term foundation of how the infrastructure operates. If it feels overwhelming, it’s fine to push back a bit and express your concerns. Just because someone’s senior doesn't always mean they have all the answers. But it seems like he's got a solid understanding since he's already worked on the network structure.
Yeah, he has a strong background, but I think he just wants me to learn as much as possible by exploring this myself. I appreciate the insight!

Thanks for breaking that down! I suspected it was more about how the environments are structured than just the CI setup, but this really clarifies things.