What is infrastructure as a Code ?
Infrastructure as a code – IAC is the management of infrastructure (Virtual machines, Load balancers, connection topology and network) in a descriptive model using the same language as devops teams uses.
As per the principle that states that the same source code generates the same binary and IAC model should create the same environment every time its is utilized. Its becoming a key devops practice and it works in parallel with continuous delivery.
Which real problems does IAC solves ?
IAC came into existence to solve two major problems which are stated below:
1. Environmental drift – Take an example where devops teams are managing 100’s of instance of varied application & they are not using IAC. The cumbersome task would be to maintain the configuration of individual deployment environments. Over the period of time these environments become snowflakes, meaning a devops team cannot reproduce a unique configuration automatically.
Very good chance you will have inconsistency between environments which ultimately leads to issues during the final deployment.
If your system has snowflakes then maintenance and administration of infrastructure are difficult to handle. Ultimately this introduces errors in the system.
2. Idempotence – This is a property which states that a deployment script always sets the target environment into the same set of configuration every time , irrespective of the initial state of environment. It is achieved by two ways:
a. Automatically configuring an existing target environment.
b. Rejecting the existing target environment and recreating it as a fresh system.
You can easily achieve this when you use IAC.
What real benefits does IAC delivers ?
Infrastructure as Code enables
- DevOps teams to test applications in production-like environments early in the development cycle. multiple test environments can be provisioned reliably and on demand.
- Infrastructure represented as code can also be validated and tested to prevent common deployment issues.
- Teams who implement IAC can deliver stable environments rapidly and at scale.
- Teams avoid manual configuration of environments and enforce consistency by representing the desired state of their environments via code.
- DevOps teams can work together with a unified set of practices and tools to deliver applications and their supporting infrastructure rapidly, reliably, and at scale.
Declarative definitions ?
IAC technology we normally use declarative definition where possible.
A definition file specifies the “what” an environment required and not necessarily the “how” part of it. File will describe the specific configuration and versions of a server component from infra point of view, but it does not specify the method for installing and configuring it. This provides an required abstraction which helps in greater flexibility in between.
This declarative way also help to reduce the technical overhead of maintaining multiple scripts over a time. There is no single industry standard for declarative format for IAC. Different platforms support varied and multiple file formats as YAML, JSON and XML. Therefore the selection of declarative format depends on the target platform.
Best practices for IAC ?
Below are the list of best practices which we everyone should follow.
- Code Everything – You should keep everything related to infrastructure in the code.
- Make code your single source of truth – All the infrastructure specifications should be coded in configuration files. Your configuration files should act as the single source of truth for all the infrastructure management activities.
- Maintain version control – Put all your config files under source control.
- Use little documentation or none at all for your infrastructure specifications – Since the configuration files itself will be self explanatory in most of the descriptive languages, devops team does not need to have exhaustive documentation. Instead just enough documentation will be enough.
- Test and Monitor Your Configurations. As IAC is based on coding, therefore anyother code it could be tested and monitored. You can use various tools for it respective which platform you are using. you can check for errors and disparities in your servers before you deploy them to production.
- Modular IAC Code – As in any other language, you can make you scripts modular which could reusable and reconstructed as per the changing deployment configurations.
There are many platform available to implement IAC, Cloud platforms have there own languages to speak as AWS, Azure etc. Third party platforms such as Terraform, Ansible, and Chef are also available to manage automated infrastructure.
In future sessions, we will have hands on session to evaluate platforms one by one.
Explore more at Teknonauts.com
Ashish is technology freak with around 10+ years of experience in IT Landscape. He started his journey as a device driver programmer in 2010. From that point he has evolved as a Mobility and IOT Architect, he completed his M.Tech from BITS Pilani as System Architect. He is working as IOT Architect at Siemens currently.