Dealing with Declarative Languages
- Any Declartive Language is all about expressing the desired state.
- Most of the tools in Azure, AWS and DevOps use the following languages primarily for desired state
- HCL (Hashicorp Configuration Language)
- Json (ARM Templates, Cloud Formation)
- Bicep
- YAML (Ansible, K8s)
- Our focus is around Infra Provisioning
Datatypes
- text
- number
- boolean
- list/array
-
map/object
-
Terraform data types: Refer Here
-
map in json
{
"networkrange": "10.10.0.0/16",
"subnetcount": 4
}
{
networkrange = "10.10.0.0/16"
subnetcount = 4
}
Resources
-
The infra we want to create for the application to be deployed
-
ARM Template (json)
{
"type": "<type>",
"apiVersion": "2019-06-01",
"properties": {
"accessTier": "Hot"
}
}
"Logical ID" : {
"Type" : "Resource type",
"Properties" : {
Set of properties
}
}
"mys3": {
"Type": "AWS::S3::Bucket",
"Properties" : {
"BucketName" : "idontwants3bucket"
}
}
Logical ID:
Type: Resource type
Properties:
Set of properties
mys3:
Type: "AWS::S3::Bucket"
Properties:
BucketName: "idontwants3bucket"
resource "aws_s3" "mys3" {
bucket = "idontwants3bucket"
}
Parameters
-
these are the values which can be passed by user during execution. In terraform we refer the same as variable.
-
JSON in ARM Refer Here
"parameters" : {
"location": {
"type": "string" //,
//"allowedValues": ["eastus", "westus"]
//"defaultValue": "eastus"
}
}
-
Using this parameter reference in azure
"[parameters('location')]"
-
JSON in CF
"Parameters" : {
"InstanceTypeParameter" : {
"Type" : "String",
"Default" : "t2.micro",
"AllowedValues" : ["t2.micro", "m1.small", "m1.large"],
"Description" : "Enter t2.micro, m1.small, or m1.large. Default is t2.micro."
}
}
-
Using this parameter reference in cf
{"Ref": "InstanceTypeParameter" }
-
Variable in Terraform
variable "instancetype" {
type = "string"
default = "t2.micro"
}
- Using this varaible reference in terraform
var.instancetype
Functions
conditions and loops
Reusability
- In terraform we create modules
- Both ARM Templates and Cloud formation supports calling other templates.
Like this:
Like Loading...