Bringing a QA mindset into Infrastructure as Code, Kubernetes, and CI/CD.
In software development, we rarely consider an application ready just because its code compiles. We run unit tests, integration tests, functional tests, and sometimes performance tests to make sure it behaves as expected.
But what about infrastructure?
With Infrastructure as Code (IaC), infrastructure is now defined, versioned, and deployed through code. We can review it, automate it, and reproduce it. Yet, simply being able to deploy infrastructure doesn't mean it is correct, secure, or reliable.
After spending several years in software testing and moving into Cloud and DevOps, I started looking at infrastructure from a QA perspective.
The question is simple:
What if we tested our infrastructure with the same discipline we apply to our applications?
Let's explore how to put this mindset into practice.
The Infrastructure Testing Approach
Infrastructure testing should not be limited to checking whether a configuration can be deployed. It should cover several layers, from static validation to runtime behavior.
flowchart TD A["Infrastructure as Code<br/>Terraform · Kubernetes · Kustomize"] B["Static Validation<br/>Format · Syntax · Security · Policy"] C["Configuration Testing<br/>Manifest Validation · Resource Checks"] D["Deployment"] E["Runtime Testing<br/>Smoke Tests · Health Checks · Connectivity"] F["Resilience Testing<br/>Failure Scenarios · Recovery"] G["Reliable Infrastructure<br/>Confidence · Repeatability · Feedback"] A --> B --> C --> D --> E --> F --> G Each layer catches a different category of potential problems.
1. Infrastructure Is Code. It Can Have Bugs Too.
Infrastructure code can introduce many types of issues:
- Incorrect network configurations.
- Missing permissions or overly permissive IAM policies.
- Misconfigured Kubernetes resources.
- Missing resource limits.
- Incorrect environment variables.
- Security vulnerabilities in infrastructure definitions.
- Services that deploy successfully but cannot communicate with each other.
Some of these issues can be detected before deployment. Others only become visible when the infrastructure is running.
This is exactly why testing should not stop at syntax validation.
Just like application testing, infrastructure testing should cover multiple levels.
2. Level 1 – Validate Before Deployment
The first step is to catch problems as early as possible.
For Terraform, several commands and tools can help:
-
terraform fmt -check: checks whether Terraform files follow the expected formatting. -
terraform validate: checks the syntax and internal consistency of the configuration. - TFLint: identifies potential Terraform configuration issues.
- Checkov: scans Infrastructure as Code for security and compliance misconfigurations.
For example, a basic Terraform validation stage in GitLab CI could look like this:
terraform_validate: stage: validate image: hashicorp/terraform:latest script: - terraform fmt -check -recursive - terraform init -backend=false - terraform validate This stage helps identify formatting and configuration errors before infrastructure is deployed.
However, there is an important distinction: a successful validation does not guarantee that the infrastructure will work correctly in AWS.
It only confirms that certain checks have passed.
3. Level 2 – Test the Configuration
A configuration can be syntactically valid and still be incorrect.
This is particularly important with Kubernetes.
For example, a Deployment manifest might be valid YAML but contain:
- An incorrect container image.
- A missing environment variable.
- An inappropriate number of replicas.
- Missing CPU or memory requests and limits.
- An incorrect Service selector.
Tools such as kubectl and Kustomize help validate and inspect Kubernetes configurations before applying them.
For example:
kubectl apply --dry-run=client -f deployment.yaml This performs client-side validation without creating resources in the cluster.
With Kustomize, we can also generate and inspect the final manifests for each environment:
kubectl kustomize overlays/dev kubectl kustomize overlays/prod This is useful when the same application has different configurations for development and production.
But again, validating a manifest does not prove that the application will behave correctly once deployed.
A valid configuration is not necessarily a correct configuration.
4. Level 3 – Test After Deployment
This is where infrastructure testing becomes closer to functional testing.
Once resources are deployed, we need to verify that they actually work.
Some examples include:
Health checks
- Is the application responding?
- Are Kubernetes Pods ready?
- Are the expected replicas running?
Connectivity tests
- Can the application reach the database?
- Can services communicate with each other?
- Is the application accessible through the Load Balancer?
Smoke tests
- Does the main API endpoint return a successful response?
- Can the application perform a basic database operation?
- Are critical application features available?
For example, a simple HTTP smoke test could be:
curl --fail --retry 5 --retry-delay 3 \ https://my-application.example.com/health This check verifies that the application responds successfully after deployment.
It is a small test, but it can catch issues that static validation cannot detect.
5. Level 4 – Test Failure Scenarios
Testing only the successful path is not enough.
In QA, we also investigate how an application behaves when something goes wrong.
Infrastructure deserves the same attention.
Consider an application running on Amazon EKS:
- What happens when a Pod crashes?
- Does Kubernetes restart it?
- Does the application remain available during a rolling update?
- Does the Horizontal Pod Autoscaler react to increased CPU utilization?
- What happens when a database becomes temporarily unavailable?
These scenarios can be explored through controlled tests in a non-production environment.
For example, deleting a test Pod can help verify whether its Deployment creates a replacement:
kubectl delete pod <pod-name> kubectl get pods -w The goal is not simply to check whether Kubernetes restarts the Pod. We also want to understand whether the application remains available and whether the expected recovery behavior occurs.
This is where testing, observability, and resilience come together.
6. Make Infrastructure Testing Part of CI/CD
All these checks become much more valuable when they are automated.
A possible infrastructure testing workflow could look like this:
- Code validation: formatting, syntax, and static analysis.
- Security checks: scan IaC for common security misconfigurations.
- Configuration testing: validate Kubernetes manifests and generated configurations.
- Infrastructure deployment: apply the reviewed Terraform changes.
- Post-deployment testing: run smoke tests and health checks.
- Monitoring: observe application and infrastructure metrics.
Not every project needs all these stages from day one.
The important thing is to introduce checks progressively and make sure that failures are visible before they reach production.
A successful pipeline should provide more than a green status. It should give us confidence that the infrastructure meets its expected requirements.
7. Final Thoughts: Bring the QA Mindset to Infrastructure
Moving from application testing to Cloud and DevOps doesn't mean leaving QA principles behind.
Quite the opposite.
The habits developed through software testing are directly applicable to infrastructure:
- Think beyond the happy path.
- Validate assumptions.
- Automate repetitive checks.
- Test failure scenarios.
- Investigate unexpected behavior.
- Verify the actual outcome, not just the deployment status.
Infrastructure as Code makes infrastructure easier to reproduce and manage. Testing makes it easier to trust.