Infrastructure as Code, also known as IaC, is a tool for providing consistent, reliable, repeatable, and automated infrastructure provisioning and management using configuration files rather than the graphical user interface. The infrastructure and resources are defined using configuration files which you can repurpose, collaborate and manage versions.
There are several tools available that provide IaC functionality. These include:
- AWS CloudFormation
- Microsoft Azure Resource Manager
What are the benefits of using Infrastructure as Code?
IaC helps speed up the resources set up so that you spend less time on resource management and more time focusing on the applications running on this infrastructure.
As these templates are text files, you can track differences in your templates to track changes to your infrastructure, similar to the way developers control changes to the application source code.
- Speed and efficiency
- Version control configuration files.
- The configuration file acts as a single source of truth.
- Test and monitor the configuration.
Infrastructure as CodeHow do we select what tools to use?
When selecting a tool, we should consider the target deployment environment. For example, AWS CloudFormation is designed to provision and manage AWS infrastructure and works with other AWS offerings. You can use a single template to create and update an entire environment or separate templates to manage multiple layers within an environment. This enables templates to be modularized and provides a layer of governance that is important for many organizations.
Terraform can manage infrastructure on multiple cloud platforms. Terraform is HashiCorp’s infrastructure as a code tool. It lets you define resources and infrastructure in human-readable, declarative configuration files and manages your infrastructure’s lifecycle.
Azure Resource Manager is the deployment and management service for Azure. It provides a management layer that enables you to create, update, and delete resources in your Azure account.
At Addteq, we use Cloudformation templates to provision the infrastructure on AWS for Atlassian applications.
Sample cloudformation template to provision an EC2 instance
The below sample code provisions an EC2 instance in AWS.
In the below sample code, we define the resource, i.e., EC2, that we want to provision. We can define the instance’s properties using parameters like the instance type, security group to assign to the instance, SSH key pair, and the image id to use to provision the instance.
EC2Instance: Type: AWS::EC2::Instance Properties: InstanceType: Ref: InstanceType SecurityGroups: - Ref: InstanceSecurityGroup KeyName: Ref: KeyName ImageId: Fn::FindInMap: - AWSRegionArch2AMI - Ref: AWS::Region - Fn::FindInMap: - AWSInstanceType2Arch - Ref: InstanceType - Arch
If you are just getting started with AWS Cloudformation templates, you can find more sample templates on AWS – https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/cfn-sample-templates.html