Infrastructure as a code (Iac)



Topic ARM

What is ARM - it is expanded as Azure resource manager ( it is basically a template written in Json format)
Azure understand Json
Aws understand yaml and Json
Json - java script object notation, we will be using the below syntax, you need to know when and where to use.
{}
[]
:
""
,
Always json shoud start with { and end with }
   "Name" = "Microsoft azure cloud"
}

The above line is mentioned in the key = value format.
Here the key is "Name" & value is "Microsoft azure cloud"
Whenever you mention multiple keys you need to give comma, at the end of the command.
for integers no need to give double quotes , only string required double quotes
Imp : at the end of the } you should not use command.

For example :
   "Name" = "Microsoft azure cloud",
   "Owner" = "Microsoft"
   "Established" = 2010
}

They are two types of deployment 
1. Subscription level deployment
2. Resource group level deployment

To perform a deployment, create your arm template in vs code.
Go to az console > search for template deployment > select create > use build your own template.
Select your resource group and copy paste thr Arm template.
Two modes of ARM template deployment 

Incremental :
1. Deploy your code in the az console
2. It won't delete any of the existing resource and default with performed from portal.

Complete :
1. It will delete all the resources which are not part of the template. ( Very risky )
2. Complete mode is allowed from cli only. It's not available from portal.

To deploy the arm template through powershell

1. Install az module in powershell
2. Install your vs code and create a folder and place your template file (sample.json)
3. To perform a deployment, open powershell and type the below commands
To check syntax error :

Test-azresourcegroup deployment -templatefile .\sample.json -resourcegroupname madblue

To deploy the resources:

New-Azresourcegroupdeployment -Name armdeploy1 -resourcegrouponame madblue -templatefile .\sample.json - verbose -force
Hint : if an item was repeated multiple times, then instead of changing manually you can use 'variables'

Modes of deployment:

When ever you run any deployment script by default it will take incremental deployment.
But if you want to intentionally perform a complete deployment, then use the below format.

New-Azresourcegroupdeployment -Name armdeploy1 -resourcegroupname madblue -templatefile .\sample.json - verbose -force -mode complete
Resource group:

Resources can be created using powershell and CLI
But if something goes wrong then the script stops there and from there you need to identify the issue.
Because if you execute the script again it will again start from where it stopped
Because the resources which is already created is not going to create again.
Resource creation will happen parallelly when you run through ARM which saves time
You can add or remove a resource to a resource group at any time
You can move a resource from one resource group to another group or another subscription in same account. 
Resource group can contain resources that reside in different regions.
Resource can interact with resources in another resource groups.
Storing the metadata of the resources is the main purpose of Resource group.
Declarative code is where you write everything in Key value pair.
Imperative code is where you write code in powershell csharp etc (proper scripting)

Variables: 

It is nothing but where you can use it for respective values.
So instead of having the value repeated multiple times in the script lines, we can specify a value in a variable and use it everywhere.

That is it !! You have successfully learnt about the basics of IAAC in Azure.

















Post a Comment

0 Comments