mirror of
https://github.com/MichaelCade/90DaysOfDevOps.git
synced 2024-12-22 15:43:11 +07:00
3.4 KiB
3.4 KiB
Day 57 - A practical guide to Test-Driven Development of infrastructure code
A session describing a CI/CD pipeline in GitHub Actions that uses various tools such as Terraform, Bicep, Azure Policies (PS Rule), Snyk, and Pester to validate the security, compliance, and functionality of infrastructure code before deploying it to the actual environment. Here's a summary of the steps you mentioned:
- Run tests locally using tools like Terraform, Bicep, and Azure Policies (PS Rule) before committing the code. This ensures that the changes are secure, compliant, and follow best practices.
- In the CI/CD pipeline, use a workflow file in GitHub to combine these tests. The workflow includes jobs for linting, validation using pre-flight validation with ARM deploy action, running Azure Policies (PS Rule), Snyk, and Pester tests.
- Use the built-in GitHub actions to run these tests in the pipeline. For example, use the Azure PS rule action to assert against specific Azure Policy modules, provide input path, output format, and file name.
- Approve the test results before deploying changes to the environment. This ensures that it is safe to push the deploy button.
- After deployment, run tests to verify if the deployment succeeded as intended, and if deployed resources have the right properties as declared in the code. Use tools like BenchPress (based on Pasta) or Pester to call the actual deployed resources and assert against their properties.
- Optionally, use infrastructure testing tools such as smoke tests to validate the functionality of the deployed resources (e.g., a website).
- To make it easier to install and configure these tools, consider using a Dev Container in Visual Studio Code. This allows you to define what tools should be pre-installed in the container, making it easy to set up an environment with all the necessary tools for developing infrastructure code.
Overall, this is a great approach to ensure that your infrastructure code is secure, compliant, and functional before deploying it to the actual environment. Thanks for sharing this valuable information!
- Azure DevOps: The speaker discussed using Azure Pipelines to automate infrastructure testing and deployment.
- Security Testing: They mentioned using Snak to run security tests in a continuous integration pipeline, allowing for automated testing and deployment.
- Deployment: The speaker emphasized the importance of testing and verifying the actual deployment before pushing changes to production.
- Testing Types: They introduced three types of tests: unit tests (Pester), infrastructure tests (BenchPress or Pesto), and smoke tests.
- Dev Container: The speaker discussed using a Dev Container in Visual Studio Code to pre-configure and pre-install tools for developing Azure infrastructure code.
These key takeaways summarize the main topics and ideas presented by the speaker:
- Automating infrastructure testing and deployment with Azure Pipelines
- Leveraging Snak for security testing in CI pipelines
- Emphasizing the importance of verifying actual deployments before pushing changes to production
- Introducing different types of tests (unit, infrastructure, smoke) for ensuring the quality of infrastructure code
- Utilizing Dev Containers in Visual Studio Code to streamline development and deployment processes