Next: Configuration Management (CM), Previous: Virtualization, Up: Infrastructure Provisioning [Contents]
Infrastructure as Code (IaC/IaaC), or Infrastructure as a Service (IaaS), is an approach of provisioning, deploying, managing, and configuring all infrastructure resources using a declarative syntax. This way, they are described as a desired state, enabling developers and operations teams to automate the creation and management of resources in a consistent and repeatable manner.
The most consistent and useful tool to perform this way of administrating and managing the infrastructure, amongst all others, is Terraform, which is an open-source IaC tool developed by HashiCorp that allows access to various on-premise, cloud, data centers and service providers using configuration files written in either HashiCorp Configuration Language (HCL) or JSON.
All code can be written in a single ‘*.tf’ file, but, as it is a codebase that it will be mantained in a Git repository, it is best to separate and modularize code with different roles and purposes. This is a nice and tidy directory structure that will help us collaborating in different parts of the codebase without affecting the rest:
. |-- secrets/ |-- providers/ +-- nodes/
A ‘main.tf’ file can be written to initialize all providers with their desired version to use. This is an example importing the Ansible provider, see Configuration Management (CM) for more information. |
terraform { required_providers { ansible = { version = "~> 1.1.0" source = "ansible/ansible" } } }
All files within the ‘nodes/’ directory are resources definition, which describe the underlaying infrastructure that we want to deploy, while the ‘providers/’ one holds all specific providers initialization and configuration, as well as data structures definitions to be used across all deployable resources. For an actual example using a cloud provider as AWS, see Cloud-based Dependant Infrastructure for more information.
When deploying a Kubernetes cluster using Infrastructure as Code (IaC), Terraform can be utilized to define and provision the underlying infrastructure required for the cluster, including creating VMs, setting up networking, and configuring storage resources. By using this approach, the entire cluster can be managed consistently, version-controlled, and easily replicated.
Next: Configuration Management (CM), Previous: Virtualization, Up: Infrastructure Provisioning [Contents]