Steps To Create Terraform Lockerfile
Step 1: Create a sample config by using the code below.
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
}
}
}
provider "aws" {
region = "us-east-1"
access_key = "AKIAWLIWW6OXIMMLZ7LW"
secret_key = "Myn10pJzwa9BrlfoXtTpGnK2MA4x2jjMb0XKBhjv"
}
resource "aws_instance" "Demo_1" {
ami = "ami-0c7217cdde317cfec"
instance_type = "t2.micro"
By using the above code we are creating the basic ec2 instance and before intilizing the terraform init the terraform directory structure will look as shown the image below.
Terraform Directory Structure befpre intializing the terraform init.
Step 2: Know intilize the terraform by the command “terraform init”. After initializing the terraform init command you can see that the terraform lock file was created. Which will consist of the version of the provider and the terraform.
Step 3: Use the vi or cat command to see the details available in the terraform or if you are using the visual studio code then you can just click on the file to see the content avlible init as shown in the image below.
“Terraform.lock.hcl” in the above you can see provider version “5.38.0” lock file will make sure that any one working will use the same version of the provider.
What Is Terraform Lock FIle?
The terraform lock file is named “Terraform. lock.hcl” It will generated by the terraform itself and it will make sure that the same infrastructure will be created if multiple users are working. It serves as a central repository for the particular provider and module versions that you have used in your configuration.