Hello Folks,
A metaphor has grabbed my attention about clouds on a very boring weekend of mine and brought lots of thoughts running in the volatile memory.
'Every Cloud has a Silver lining'
This statement has struck me and made me think how this is so apt in the real public cloud like AWS, with the plethora of service offerings provided by AWS, it has been a struggle for the administrators, DevOps engineers to implement the different stacks running in a very less time without any manual errors
How do we overcome this manual configuration and repetition? Do we have to learn programming languages to automate the repetitive tasks and how to start learning programming suddenly after being a network expert for a long time?
Guys!
I would say there is no need of getting panicked because the configuration management tools and the deployment tools have come to us handily to automate such tasks
There has always been a discussion among the DevOps engineers, developers, Architects to define automation and how to bring Infrastructure as a code in the organisation.
Yes, we heard a new term called Infra as a code?
what is Infra as a code?
It is a way of automating the infrastructure tasks using deployment tools and the configuration management tool to avoid repetition and simplify the reuse of configuration
what are those tools?
There are lots of tools for configuration management like Ansible, puppet,chef, terraform and cloud formation templates
Cloud Formation templates are specific to AWS and cannot be used on other clouds, Here is an overview on how to start writing CFTs and bring up the infrastructure within seconds
Components of Cloud Formation template :
- AWSTemplateFormatVersion
- Description
- Resources
- Parameters
- Mappings
- Conditionals
- Transforms
- Outputs
CFT template is a blueprint of the Infrastructure in AWS which can be written either using YAML or JSON formats , If a CFT template is uploaded onto the AWS, a stack is created and the stack can be created , updated and deleted anytime as per the Infrastructure requirement
AWSTemplateFormatVersion:
This particular component in CFT determines the version of the CFT which is determined by the date of the revision of the template version
Description: This component determines the information about the template
Resources: Resources are nothing but components that are present in AWS infrastructure, CFT supports lots of components, Let's see some of the components and their understanding
Example 1: Creation of EC2 instance using CFT
Declaring the template :
There are lots of properties in which some are optional and some are mandatory( some are discussed below)
- AvailabilityZone (Optional): determines the availability zone, if not specified Takes any one default Zone from the region, (Updation requires replacement which means if an AWS instance is mapped to a New AZ in the updated template, AWS creates the New resource in the respective availability zone and maps the resource and delete the old resource)
- ImageId: Image ID of the AMI and is required mandatorily, ( updation requires replacement)
- InstanceType: Type of the instance ( It is a mandatory parameter) and it can be chosen from the set of allowed values that can be mentioned in the parameters
- SecurityGroups: Mention the security group names for non-default VPC and security IDs for default VPC
Example2: Creation of EC2 instance, Mapping the elastic IP and security group to the EC2 instance
- The template is written in YAML and using the AWS CFT designer, The design can be seen Visually, Navigate to AWS CFT-→ DESIGNER and add paste the data to see the view
Dependencies:
From the above template, we could see that Instance creation is dependent on the Security group and that is referenced using the Ref function which is an intrinsic function to call the object assigned to the other Resources/parameter, If Ref is called with a parameter name, it returns the value, if called with a resource, the physical ID of the resource will be returned
Note: There are lots of intrinsic functions like "getattr" and join which we will discuss later
What happens during importing of a template to the CFT on creation?
- AWS uploads the Template to the S3 Bucket
- AWS creates the stack with the template
Expanding the template by adding other components to the template:
Parameters:
Parameters are nothing but the input values mentioned in the template, This helps in the reuse of the template for creating multiple stacks
- Looking at the properties of the parameters, The property called "Type" is the required parameter
- There are two different types of parameters
- Type determines the datatype of the input parameter
- General parameters
- Type: String
- Type: Number
- Type: list<number>--→['1','2','4']
- Commadelimitedlist-→['d','a','b']
- AWS specific parameter types include
- AWS::EC2::AvailabilityZone::Name
- AWS::EC2::Image::Id
- AWS::EC2::Instance::Id
- AWS::EC2::Keypair::KeyName
- There are other properties like MaxLength, MinLength, MaxValue, MinValue which are optional
- From the output, we could see that we have used parameters for inputting InstanceType as well as the key name
- We have used a default parameter type 'string' and AWS specific parameter type
- In the Resource properties, The Instance type values and the Key name is now referred to as the parameters
Outputs:
Outputs are the very essential component in CFT as the outputs can be exported to use in different cloud formation templates and are called Cross CFT
- Here we have outputted the Public IP of the EC2 instance using the "GetATT" function, The main point to be noted about outputs is the values are returned or Exported only after the instance got created or updated and can be used in other CFTs
Note: More on Mappings and Transforms will be on the next blog post