In Resources section we describe/declare what resources have to be created.
"Resources" : {
"Logical ID" : {
"Type" : "Resource type",
"Properties" : {
Set of properties
}
}
}
Resources:
Logical ID:
Type: Resource type
Properties:
Set of properties
Logical ID is unique id given by template designer/creator
Every resource in AWS has a unique type and it will have set of properties
In the Resources section, we create multiple resources as per the needs of the application / infra to be deployed
Cloudformation template to create a vpc with 4 subnets
Make a note of manual steps
Create a vpc
Create subnet1 and select the vpc created above
Add three more subnets in the same way
Create a new folder ‘vpc’ and add a file ‘vpc.json’ to it
Now lets add the basic structure with Description and template version
{
"AWSTemplateFormatVersion": "2010-09-09",
"Description": "This template is written for learning and it creates vpc with 4 subnets",
}
Now since we need to create vpc, lets add resources section
{
"AWSTemplateFormatVersion": "2010-09-09",
"Description": "This template is written for learning and it creates vpc with 4 subnets",
"Resources": {
}
}
Lets find aws vpc cloudformation resource docs Refer Here and also look into resources section from here and then fill the template
{
"AWSTemplateFormatVersion": "2010-09-09",
"Description": "This template is written for learning and it creates vpc with 4 subnets",
"Resources": {
"myvpc": {
"Type": "AWS::EC2::VPC",
"Properties": {
"CidrBlock": "10.0.0.0/16",
"EnableDnsHostnames": true,
"Tags": [
{
"Key": "Name",
"Value": "myvpc"
}
]
}
}
}
}
Hint: If you have installed vscode extension as mentioned above, you get help (intellisense) from vscode
Now we need to add subnets, As shown below, we need vpc id
While creating template for subnet i need to give vpc id which is not yet created/known i.e. resource with subnet1 id is depending on resource with myvpc id
Now if we were asked to create subnet1 in AZ -a subnet2 in Az B etc we need to understand the impact of the change which is mentioned in Update Requires section in Parameter