Why we should provide standard for IaC on our team
Tags: iac, devops, terraform, productivity
Published: 2023-12-25 05:07:37

😺 Today, let's delve into a common challenge faced by **non-developers** who take on roles that mimic those of actual **developers**, such as `DevOps Engineers`, `Cloud Engineers`, `Automated QA`, and others. As we navigate through the intricate landscape of the modern tech world, we encounter numerous like **application design patterns**, **frameworks**, and **architectural designs**.

In this dynamic environment, the ability to craft applications and share them within your team or with others becomes a pivotal aspect. The cohesion achieved by adopting shared standards and frameworks ensures that your **ideas**, **designs**, and **functionalities** are comprehensible to everyone involved. This shared foundation not only facilitates mutual understanding but also provides a guiding framework and utility tools that enhance overall performance.

By adhering to a common working standard, you not only streamline communication within your team but also benefit from the efficiency and support offered by standardized frameworks. This collaborative approach not only fosters understanding but also contributes to a more efficient and high-performing work environment.


![Team collaboration](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9p2ern3xq4g44ixa3iu1.jpg)

## Understand several software design principle

> 📄 *Understand about several design pattern and framework for programming languages.*
> 

🧑🏼‍💻 Software design principles are fundamental guidelines that software developers follow to achieve high-quality software design. The principles provide a framework for making design decisions that lead to more maintainable, scalable, and robust software.

Example are here:

1. **DRY (Don't Repeat Yourself)**: This principle emphasizes the importance of reducing repetition in code. Every piece of knowledge or logic should be unique and single-represented in a system. This reduces the risk of inconsistencies and makes code more maintainable. Read more [here](https://thevaluable.dev/dry-principle-cost-benefit-example/).
2. **KISS (Keep It Simple, Stupid)**: This principle suggests that systems work better if they are kept simple rather than made complex. Simplicity should be a key goal in design, and unnecessary complexity should be avoided. Read more [here](https://www.freecodecamp.org/news/keep-it-simple-stupid-how-to-use-the-kiss-principle-in-design/).

From the principle of designs, it provide us to Design patterns and Frameworks that we actually do on our application. It just a common standard for our team to collaborative in the same project that we work together. 

## The IaC programmings

> 📄 *Definition of IaC, What is purpose to use programming to control infrastructure.*
> 

🔨 The **Infrastructure as Code**(also IaC) is a key concept in modern software deployment and operation, fundamentally transforming infrastructure managed in IT environment via readable documentation for developer and machine. We’re trying to reduce the manually setting up and configuring resources. We’re use code to automate the process, which can be more consistent and error-free than manual process.

Example tools of IaC.

- **Terraform**: An open-source tool that uses a declarative configuration language for building, changing, and versioning infrastructure safely and efficiently.
- **Ansible**: An open-source tool that uses YAML for defining infrastructure configurations, primarily for automation of application deployment and intra-service orchestration.

## Relationship between IaC and several programming languages

> 📄 *Said about same purpose and different on both*
> 

🤝 We must experience about programming and infrastructure before apply the IaC. The IaC can be implemented using standard programming language like Python, Javascript, Golang or specialized domain-specific language(DSLs). The DSLs are designed specifically for defining and managing infrastructure resources like **Hashicorp’s Terraform** and **AWS Cloudformation**.

📜 In the IaC, script or code are written to automatically set up and manage infrastructure. This code act as a blueprint for our resources. You can be executed to deploy, manage and destroy the infrastructure. We can integrates closely modern deployment practices as the same common programming like CI and CD.

## How to adopt development practices to IaC

> 📄 *Talk about current tools and a community experience to improve IaC writing.*
> 

⚒️ Adoption the software development principle in IaC is essential for maintaining the quality, efficiency, and reliability of our the source code to infrastructure automation. Here are several key programming principle and practices that can be effectively applied to IaC.

1. Use **version control**: Just like code, our infrastructure configuration should be stored in a version control system like Git. This practices allow tracking changes, collaborate with team and maintaining a history of our infrastructure state.
2. Write **modularity**: Write modular script, just as with traditional programming, break down your code into smaller, reusable modules can make them more manageable, and understandable.
3. **DRY principle(Don’t Repeat Yourself)**: Avoid duplication in your code. You can use templates, modules, or function to reuse code as most as possible, which makes it easier to manage and reduces the risk of error.
4. **Code review**: We must implement code review process to IaC, just as you would for code. This principle encourages collaboration, improve code quality, and help in sharing knowledge among team member.
5. Use **automate testing**: Apply automate testing into your IaC. You can implement tools and frameworks to IaC script to ensure they perform as expected before deployment.
6. **Documentation**: Write the document of IaC script and configurations. Good documentation helps in understanding the purpose and function of your infrastructure, especially in complex environment.
7. Keep it **idempotency**: Ensure your script is idempotent, meaning running your script multiple times in the same environment result in the same state, without unintended side effects. This is crucial for reliability and predictability in automated environments.
8. Apply **security practices**: Most important to embedded the security practice on your IaC development process. This includes using secure access credentials, encrypting sensitive data, and should follow the principle of least privilege.
9. Often **refactoring**: Regularly refactor your IaC code for improvements and optimizations, similar to how you would refactor application code for better performance, readability, and maintainability.

By adopting these practices, team can ensure that their IaC approach is as robust, efficient, and maintainable as their software development process. 

## Example guideline to contribute IaC

> 📄 *Show my standard to writing Terraform and Ansible*
> 

You can apply the previous practices into your IaC code and see what happen in your work. I can sharing some guideline to initial your IaC project here.

For the **Hashicorp’s Terraform**: 

1. You might to create a new repository for versioning your script. You can create a folder structure in different purpose like
    1. `components` to store your reusable and maintainable for script in consistent modules.
    2. `deployments` to store your variable files that contain each environment configurations.
    3. `modules` in optional to download and freeze external Terraform’s module for your environments.
2. You can integrates automation plugins for verify syntax, credentials leak, and missing fields. Use third party tools like **Terrasec**, **TFlint**, and other.
3. For documentation, you can use `terraform-docs` for automate provision code spec when you write a description in your scripts.
4. You can integrates your process with CI/CD pipeline for Jenkins, Github-action, and other platforms.
5. For integration testing your script, you can use `Grantwork’s Terratest` to verify your actually provisioning resources.

You can see my example terraform code for initialize from [Github repo](https://github.com/StartloJ/terraform-initial).

## Conclusions

> 📄 *Recap all topics and drop some question to audiences.*
> 

🧳 In our journey towards modernizing infrastructure management, we have embraced to use  modern technology for provisioning, managing, and maintaining infrastructure. This is achieved through programming languages and domain-specific languages(DSLs). By writing code and script, we’re revolutionizing the way we handle infrastructure.

The purpose of this is to establish standard practices for our team in crafting code that enhances collaboration, readability, and maintainability. This adoption will not only streamline our development processes but also significantly improve the quality of code.