{"id":1491,"date":"2022-06-16T09:52:26","date_gmt":"2022-06-16T09:52:26","guid":{"rendered":"https:\/\/www.checkmateq.com\/blog\/?p=1491"},"modified":"2023-08-07T07:39:16","modified_gmt":"2023-08-07T07:39:16","slug":"instance-using-terraform","status":"publish","type":"post","link":"https:\/\/www.checkmateq.com\/blog\/instance-using-terraform","title":{"rendered":"Deploy AWS ec2 Instance using Terraform"},"content":{"rendered":"<p><strong>Terraform<\/strong> is an open-source<a href=\"https:\/\/www.checkmateq.com\/infrastructure-services\"> infrastructure<\/a> as code tool to automate and manage your <a href=\"https:\/\/www.checkmateq.com\/cloud\">cloud<\/a> infrastructure, it uses a declarative language means you just give what you want and terraform will take care of the steps to get it done, you can version, reuse, and share these files, in this blog we will learn how to launch an ec2 instance in AWS using terraform configuration files.<\/p>\n<p>I am going to use an already launched AWS ec2 instance to launch a new instance with terraform, for this the instance used should have permission to do the same which can be done by attaching a IAM role to the instance<\/p>\n<h3><strong>Step-1: Creating IAM role with AmazonEC2FullAccess to Launch AWS ec2 instances.<\/strong><\/h3>\n<p>Create a IAM role and with policy AmazonEC2FullAccess, on your AWS web console search for IAM.<\/p>\n<p><img loading=\"lazy\" class=\" wp-image-1504 aligncenter\" src=\"https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/iam-1-300x153.jpeg\" alt=\"\" width=\"625\" height=\"319\" srcset=\"https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/iam-1-300x153.jpeg 300w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/iam-1-1024x521.jpeg 1024w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/iam-1-768x391.jpeg 768w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/iam-1-1536x782.jpeg 1536w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/iam-1-1200x611.jpeg 1200w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/iam-1.jpeg 1920w\" sizes=\"(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 984px) 61vw, (max-width: 1362px) 45vw, 600px\" \/><\/p>\n<p>on the left plane click on <strong>Roles<\/strong> under <strong>Access management\u00a0<\/strong>then click on create role.<\/p>\n<p><img loading=\"lazy\" class=\" wp-image-1506 aligncenter\" src=\"https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/iam-3-300x152.jpeg\" alt=\"\" width=\"645\" height=\"327\" srcset=\"https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/iam-3-300x152.jpeg 300w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/iam-3-1024x519.jpeg 1024w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/iam-3-768x389.jpeg 768w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/iam-3-1536x778.jpeg 1536w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/iam-3-1200x608.jpeg 1200w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/iam-3.jpeg 1920w\" sizes=\"(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 984px) 61vw, (max-width: 1362px) 45vw, 600px\" \/><\/p>\n<p>Select &#8220;<a href=\"https:\/\/www.checkmateq.com\/aws-cloud\">AWS<\/a>&#8221; service for &#8220;Select type of trusted entity&#8221; , EC2 for &#8220;Choose a use case&#8221;\u00a0 then click on next.<\/p>\n<p><img loading=\"lazy\" class=\" wp-image-1507 aligncenter\" src=\"https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/iam-4-300x153.jpeg\" alt=\"\" width=\"634\" height=\"323\" srcset=\"https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/iam-4-300x153.jpeg 300w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/iam-4-1024x521.jpeg 1024w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/iam-4-768x391.jpeg 768w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/iam-4-1536x782.jpeg 1536w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/iam-4-1200x611.jpeg 1200w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/iam-4.jpeg 1920w\" sizes=\"(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 984px) 61vw, (max-width: 1362px) 45vw, 600px\" \/><\/p>\n<p>search for <strong>AmazonEC2FullAccess\u00a0<\/strong>policy and select it and click &#8220;Next&#8221;<\/p>\n<p><img loading=\"lazy\" class=\" wp-image-1508 aligncenter\" src=\"https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/iam-5-300x152.jpeg\" alt=\"\" width=\"662\" height=\"335\" srcset=\"https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/iam-5-300x152.jpeg 300w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/iam-5-1024x518.jpeg 1024w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/iam-5-768x389.jpeg 768w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/iam-5-1536x778.jpeg 1536w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/iam-5-1200x608.jpeg 1200w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/iam-5.jpeg 1920w\" sizes=\"(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 984px) 61vw, (max-width: 1362px) 45vw, 600px\" \/><\/p>\n<p>then give a meaningful name for the role you are creating, check the details\u00a0 add tags if required scroll down and click on &#8220;create role&#8221;<\/p>\n<p><img loading=\"lazy\" class=\" wp-image-1511 aligncenter\" src=\"https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/iam-6-1-300x154.jpeg\" alt=\"\" width=\"696\" height=\"357\" srcset=\"https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/iam-6-1-300x154.jpeg 300w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/iam-6-1-1024x526.jpeg 1024w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/iam-6-1-768x395.jpeg 768w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/iam-6-1-1536x789.jpeg 1536w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/iam-6-1-1200x617.jpeg 1200w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/iam-6-1.jpeg 1897w\" sizes=\"(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 984px) 61vw, (max-width: 1362px) 45vw, 600px\" \/><\/p>\n<p>Check this blog to know the steps for <a href=\"https:\/\/www.checkmateq.com\/blog\/how-to-launch-ec2-instance-in-aws\/\" target=\"_blank\" rel=\"noopener\">launching a ec2 instance<\/a> , and use below commands to install terraform<\/p>\n<h3><strong>Installing Terraform<\/strong><\/h3>\n<p>execute below command to install yum-config-manager<\/p>\n<pre>sudo yum install -y yum-utils<\/pre>\n<p>your machine may not have terraform repository\u00a0 add it using yum-config-manager, use below commands for this<\/p>\n<pre>sudo yum-config-manager --add-repo https:\/\/rpm.releases.hashicorp.com\/RHEL\/hashicorp.repo<\/pre>\n<p><img loading=\"lazy\" class=\" wp-image-1733 aligncenter\" src=\"https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/tera-300x31.jpeg\" alt=\"\" width=\"640\" height=\"66\" srcset=\"https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/tera-300x31.jpeg 300w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/tera-1024x104.jpeg 1024w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/tera-768x78.jpeg 768w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/tera-1536x156.jpeg 1536w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/tera-1200x122.jpeg 1200w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/tera.jpeg 1827w\" sizes=\"(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 984px) 61vw, (max-width: 1362px) 45vw, 600px\" \/><\/p>\n<p>Execute below command to install terraform<\/p>\n<pre>sudo yum -y install terraform<\/pre>\n<h3><strong>Attaching IAM role to ec2 instance\u00a0<\/strong><\/h3>\n<p>Go to your ec2 instances select the instance which has terraform installed in it.<\/p>\n<p><img loading=\"lazy\" class=\"aligncenter wp-image-1513\" src=\"https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/iam-8-300x152.jpeg\" alt=\"IAM\" width=\"681\" height=\"345\" srcset=\"https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/iam-8-300x152.jpeg 300w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/iam-8-1024x520.jpeg 1024w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/iam-8-768x390.jpeg 768w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/iam-8-1536x780.jpeg 1536w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/iam-8-1200x609.jpeg 1200w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/iam-8.jpeg 1920w\" sizes=\"(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 984px) 61vw, (max-width: 1362px) 45vw, 600px\" \/><\/p>\n<p>Click on <strong>Security <\/strong>under <strong>Actions<\/strong> and click on modify IAM role.<\/p>\n<p><img loading=\"lazy\" class=\" wp-image-1514 aligncenter\" src=\"https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/iam-9-1-300x152.jpeg\" alt=\"\" width=\"708\" height=\"359\" srcset=\"https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/iam-9-1-300x152.jpeg 300w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/iam-9-1-1024x519.jpeg 1024w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/iam-9-1-768x389.jpeg 768w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/iam-9-1-1536x778.jpeg 1536w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/iam-9-1-1200x608.jpeg 1200w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/iam-9-1.jpeg 1920w\" sizes=\"(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 984px) 61vw, (max-width: 1362px) 45vw, 600px\" \/><\/p>\n<p>Select the IAM role that you have created and click on <strong>Update IAM role<\/strong><\/p>\n<p><img loading=\"lazy\" class=\" wp-image-1515 aligncenter\" src=\"https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/iam-10-300x153.jpeg\" alt=\"\" width=\"714\" height=\"364\" srcset=\"https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/iam-10-300x153.jpeg 300w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/iam-10-1024x523.jpeg 1024w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/iam-10-768x392.jpeg 768w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/iam-10-1536x785.jpeg 1536w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/iam-10-1200x613.jpeg 1200w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/iam-10.jpeg 1920w\" sizes=\"(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 984px) 61vw, (max-width: 1362px) 45vw, 600px\" \/><\/p>\n<p>&nbsp;<\/p>\n<h3><strong>Step-3: Create Terraform files to launch an ec2 instance<\/strong><\/h3>\n<p>All the terraform files should be saved with &#8220;.tf&#8221; extension like &#8220;provider.tf&#8221;, syntax used in terraform configuration files in this blog\u00a0 is called as HashiCorp Configuration Language , HCL is human readable and machine friendly, terraform can also read JSON configurations.<\/p>\n<p>On your ec2 instance create a folder for your Terraform files and navigate to it, use below commands on your terminal.<\/p>\n<pre>mkdir project-ec2\r\ncd project-ec2\r\n<\/pre>\n<p><strong>mkdir\u00a0<\/strong>is a command used to create directories<\/p>\n<p><strong>cd\u00a0<\/strong> is used to change the working directory.<\/p>\n<p>we will\u00a0 create 3 files variable.tf, provider.tf, main.tf, follow below process.<\/p>\n<p>create <strong>variable.tf<\/strong> and copy below code to the file, please change the highlighted things as per your requirements and changing the value of variable <strong>key_name<\/strong> is must as <strong>key1\u00a0<\/strong>is the name of the key pair that I already have.<\/p>\n<h3><strong>variables.tf<\/strong><\/h3>\n<pre>variable \"aws_region\" {\r\n  description = \"AWS region in which I want to deploy resources.\"\r\n  default = \"<strong>ap-south-1<\/strong>\"\r\n}\r\n\r\nvariable \"key_name\" {\r\n  description = \" credentials keys to connect to ec2 instance\"\r\n  default = \"<strong>key1<\/strong>\"\r\n}\r\n\r\nvariable \"instance_type\" {\r\n  description = \"instance type for ec2\"\r\n  default = \"<strong>t2.micro<\/strong>\"\r\n}\r\n\r\nvariable \"security_group\" {\r\n  description = \"Name of security group\"\r\n  default = \"<strong>my-Securitygroup<\/strong>\"\r\n}\r\n\r\nvariable \"tag_name\" {\r\n  description = \"Tag Name of for Ec2 instance\"\r\n  default = \"my-ec2-instance\"\r\n}\r\nvariable \"ami_id\" {\r\n  description = \"AMI ID for RHEL Ec2 instance\"\r\n  default = \"<strong>ami-05c8ca4485f8b138a<\/strong>\"\r\n}\r\n<\/pre>\n<p><strong>\u00a0variable.tf<\/strong> file where you will give all the details that you will use to launch a instance like ami, region ,security group, instance type, tags ,you can also give this details directly in the implementation file\u00a0 where you declare the resources you want to deploy but its not recommended to hard code all the details, creating a separate variable file helps easily change the configuration any time with out modifying the main implementation file.<\/p>\n<p>As you can see above syntax each input variable must be declared with a variable block and name for variable is given after the key word <strong>variable<\/strong> ,each variable name must be unique, <strong>description\u00a0<\/strong>and <strong>default\u00a0<\/strong>are arguments I used for variable declaration.<\/p>\n<p><strong>description <\/strong>: is basically like a documentation for the variable.<\/p>\n<p><strong>default:\u00a0<\/strong>when given as default variable is considered as optional and only used if no value is given when running terraform.<\/p>\n<p>Now create a file named <strong>provider.tf<\/strong> and copy below given syntax to it and save.<\/p>\n<h3><strong>provider.tf\u00a0<\/strong><\/h3>\n<pre>provider \"aws\" {\r\n  region = var.aws_region\r\n}\r\n<\/pre>\n<p>Here I gave details of\u00a0 provider<a href=\"https:\/\/www.checkmateq.com\/aws-cloud\">(AWS)\u00a0<\/a> and the AWS region where I want to deploy resources , Terraform uses plugins to communicate with cloud providers and other API&#8217;s to deploy resources, here we are giving details of which plugin to use, below <strong>main.tf\u00a0<\/strong> is the main implementation file to launch where I declared all the resources to be deployed.<\/p>\n<p>then create a file <strong>main.tf\u00a0 <\/strong>here you will declare the resources that you want to deploy, you can use any meaningful name but should be with extension <strong>.tf<\/strong><\/p>\n<h3><strong>main.tf<\/strong><\/h3>\n<pre><strong>#Create security group with firewall rules<\/strong>\r\nresource \"aws_security_group\" \"securitygroup-1\" {\r\n  name = var.security_group\r\n  description = \"security group for instance\"\r\n\r\n<strong>#inbound<\/strong>\r\ningress {\r\n  from_port = 8080\r\n  to_port = 8080\r\n  protocol = \"tcp\"\r\n  cidr_blocks = [\"0.0.0.0\/0\"]\r\n }\r\n\r\ningress {\r\n  from_port = 22\r\n  to_port = 22\r\n  protocol = \"tcp\"\r\n  cidr_blocks = [\"0.0.0.0\/0\"]\r\n }\r\n\r\n<strong># outbound\u00a0<\/strong>\r\negress {\r\n  from_port = 0\r\n  to_port = 65535\r\n  protocol = \"tcp\"\r\n  cidr_blocks = [\"0.0.0.0\/0\"]\r\n }\r\n\r\ntags= {\r\n Name = var.security_group\r\n }\r\n}\r\n\r\n<strong>#declaration to launch instance<\/strong>\r\n\r\nresource \"aws_instance\" \"myFirstInstance\" {\r\n  ami = var.ami_id\r\n  key_name = var.key_name\r\n  instance_type = var.instance_type\r\n  security_groups= [var.security_group]\r\n  tags= {\r\n    Name = var.tag_name\r\n  }\r\n}\r\n<\/pre>\n<p>Let&#8217;s understand the <strong>resource\u00a0<\/strong>block first.<\/p>\n<p>resource &#8220;<strong>resource key word<\/strong>&#8221; &#8220;<strong>resource name to use across terraform module<\/strong>&#8220;{<\/p>\n<p>here give your resource attributes required to provision it&#8230;..<\/p>\n<p>}<\/p>\n<p><strong>resource key word: <\/strong>each resource in AWS will have a unique key word , for example &#8220;aws_instance&#8221; is key word for AWS EC2 instance use the keyword of the resource that you want to deploy.<\/p>\n<p><strong>resource name to use across terraform module:\u00a0<\/strong>name you give here is only to use across terraform module, it has no scope out side the module.<\/p>\n<p>In above given <strong>main.tf<\/strong> file I am creating a security group to attach it for the instance where I am opening ports 22,8080 to be accessed from any where[0.0.0.0\/0] and outbound to any port starting from port 0(zero) to 65535 and giving a tag with key<strong> Name <\/strong>and value it is given from <strong>variable.tf<\/strong> file using var.security_group ,to use a variable declared in variable file use <strong>var.variable name.<\/strong><\/p>\n<h3><strong>Step-3: Terraform commands to deploy resources\u00a0<\/strong><\/h3>\n<p>After creating all 3 files , now use below commands to deploy your resources<\/p>\n<p>Use below command to initialize provider plugins.<\/p>\n<pre>terraform init<\/pre>\n<p>above command is you used to initialize a directory that containing terraform files, it initializes provider plugins ,This is the first command that you have to run after creating a new terraform file in your directory.<\/p>\n<p><img loading=\"lazy\" class=\" wp-image-1519 aligncenter\" src=\"https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/terra-1-300x106.jpeg\" alt=\"\" width=\"750\" height=\"265\" srcset=\"https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/terra-1-300x106.jpeg 300w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/terra-1-1024x362.jpeg 1024w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/terra-1-768x271.jpeg 768w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/terra-1-1536x543.jpeg 1536w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/terra-1-1200x424.jpeg 1200w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/terra-1.jpeg 1698w\" sizes=\"(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 984px) 61vw, (max-width: 1362px) 45vw, 600px\" \/><\/p>\n<p>&nbsp;<\/p>\n<h3><strong>Terraform command to validate configuration files<\/strong><\/h3>\n<pre>terraform validate<\/pre>\n<p><strong>terraform validate\u00a0<\/strong>command will validate configuration files for syntactical errors.<\/p>\n<p><img loading=\"lazy\" class=\" wp-image-1520 aligncenter\" src=\"https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/terra-2-300x24.jpeg\" alt=\"\" width=\"713\" height=\"57\" srcset=\"https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/terra-2-300x24.jpeg 300w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/terra-2-1024x83.jpeg 1024w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/terra-2-768x62.jpeg 768w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/terra-2-1536x125.jpeg 1536w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/terra-2-1200x98.jpeg 1200w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/terra-2.jpeg 1869w\" sizes=\"(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 984px) 61vw, (max-width: 1362px) 45vw, 600px\" \/><\/p>\n<p>&nbsp;<\/p>\n<h3><strong>Command to check what resources are to be created<\/strong><\/h3>\n<pre>terraform plan<\/pre>\n<p><strong>terraform plan\u00a0<\/strong>will evaluate the desired state of resources declared and compares it with the current state in your infrastructure and give a complete output what it is going to do based on your configuration files , it does not create or destroy any resource it only gives the plan.<\/p>\n<p><img loading=\"lazy\" class=\" wp-image-1521 aligncenter\" src=\"https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/terra-3-300x163.jpeg\" alt=\"\" width=\"682\" height=\"371\" srcset=\"https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/terra-3-300x163.jpeg 300w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/terra-3-1024x556.jpeg 1024w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/terra-3-768x417.jpeg 768w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/terra-3-1536x833.jpeg 1536w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/terra-3-1200x651.jpeg 1200w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/terra-3.jpeg 1856w\" sizes=\"(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 984px) 61vw, (max-width: 1362px) 45vw, 600px\" \/><\/p>\n<p>&nbsp;<\/p>\n<h3><strong>Command to deploy your Resources<\/strong><\/h3>\n<pre>terraform apply<\/pre>\n<p><strong>terraform apply\u00a0<\/strong>will do <strong>plan\u00a0<\/strong>same as the terraform plan does and then carries out changes according to the plan using appropriate API&#8217;s for each resource, checks the details and press <strong>yes\u00a0<\/strong>when it prompts as shown in below image.<\/p>\n<p><img loading=\"lazy\" class=\" wp-image-1522 aligncenter\" src=\"https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/terra-4-300x166.jpeg\" alt=\"\" width=\"622\" height=\"344\" srcset=\"https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/terra-4-300x166.jpeg 300w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/terra-4-1024x567.jpeg 1024w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/terra-4-768x425.jpeg 768w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/terra-4-1536x850.jpeg 1536w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/terra-4-1200x664.jpeg 1200w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/terra-4.jpeg 1902w\" sizes=\"(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 984px) 61vw, (max-width: 1362px) 45vw, 600px\" \/><\/p>\n<p>sample final output for <strong>terraform apply\u00a0<\/strong>will as given below if it&#8217;s successfully done.<\/p>\n<p><img loading=\"lazy\" class=\" wp-image-1525 aligncenter\" src=\"https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/terra-5-1-300x152.jpeg\" alt=\"\" width=\"653\" height=\"331\" srcset=\"https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/terra-5-1-300x152.jpeg 300w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/terra-5-1-1024x518.jpeg 1024w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/terra-5-1-768x388.jpeg 768w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/terra-5-1-1536x777.jpeg 1536w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/terra-5-1-1200x607.jpeg 1200w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/terra-5-1.jpeg 1891w\" sizes=\"(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 984px) 61vw, (max-width: 1362px) 45vw, 600px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p>Please<a href=\"https:\/\/www.checkmateq.com\/contact-us\"> contact<\/a> with our technical consultants to discuss <a href=\"https:\/\/www.checkmateq.com\/aws-cloud\">cloud<\/a> infrastructure engineering and SaaS based product development strategies.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Terraform is an open-source infrastructure as code tool to automate and manage your cloud infrastructure, it uses a declarative language means you just give what you want and terraform will take care of the steps to get it done, you can version, reuse, and share these files, in this blog we will learn how to &hellip; <a href=\"https:\/\/www.checkmateq.com\/blog\/instance-using-terraform\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Deploy AWS ec2 Instance using Terraform&#8221;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":1541,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[3,2,12,7,11,23,16,14],"_links":{"self":[{"href":"https:\/\/www.checkmateq.com\/blog\/wp-json\/wp\/v2\/posts\/1491"}],"collection":[{"href":"https:\/\/www.checkmateq.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.checkmateq.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.checkmateq.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.checkmateq.com\/blog\/wp-json\/wp\/v2\/comments?post=1491"}],"version-history":[{"count":32,"href":"https:\/\/www.checkmateq.com\/blog\/wp-json\/wp\/v2\/posts\/1491\/revisions"}],"predecessor-version":[{"id":4306,"href":"https:\/\/www.checkmateq.com\/blog\/wp-json\/wp\/v2\/posts\/1491\/revisions\/4306"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.checkmateq.com\/blog\/wp-json\/wp\/v2\/media\/1541"}],"wp:attachment":[{"href":"https:\/\/www.checkmateq.com\/blog\/wp-json\/wp\/v2\/media?parent=1491"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.checkmateq.com\/blog\/wp-json\/wp\/v2\/categories?post=1491"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.checkmateq.com\/blog\/wp-json\/wp\/v2\/tags?post=1491"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}