{"id":90119,"date":"2023-07-25T06:46:07","date_gmt":"2023-07-25T12:16:07","guid":{"rendered":"https:\/\/www.whizlabs.com\/blog\/?p=90119"},"modified":"2024-03-14T16:51:55","modified_gmt":"2024-03-14T11:21:55","slug":"azure-container-instance-terraform","status":"publish","type":"post","link":"https:\/\/www.whizlabs.com\/blog\/azure-container-instance-terraform\/","title":{"rendered":"How to Create an Azure Container Instance with a public IP address using Terraform : AZ 900 Certification"},"content":{"rendered":"<p><span style=\"font-weight: 400;\">With cloud computing constantly evolving and revolutionizing how organizations deploy and manage their apps, an Azure Container Instance (ACI) has emerged as a powerful solution to enable lightweight and scalable containerized workloads. Azure Container Instance ACI makes it a breeze to execute isolated and serverless containers while ensuring the flexibility of Terraform\u2019s infrastructure as a code approach. <\/span><\/p>\n<p><span style=\"font-weight: 400;\">Organizations can effortlessly create and manage ACI instances with public IP addresses, enabling friction-free connectivity and accessibility for containerized applications.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Suppose you are preparing for Microsoft Azure <a href=\"https:\/\/www.whizlabs.com\/microsoft-azure-certification-az-900\/\" target=\"_blank\" rel=\"noopener\">AZ-900 certification<\/a>, exploring Microsoft Azure, or finding ways to strengthen your understanding of Azure fundamentals and nuances. In that case, creating Azure instances using Terraform is an important concept element. Particularly for the AZ-900 certification course, learning how to create an ACI with a public IP address using Terraform will be valuable.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400;\">This blog will guide you through everything you need to know about creating an Azure Container Instance using Terraform with a Public IP Address. We will dive deeper into how you can manage ACI resources and initialize Terraform. <\/span><\/p>\n<p><span style=\"font-weight: 400;\">Let\u2019s dig in.\u00a0<\/span><\/p>\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_76 ez-toc-wrap-left counter-hierarchy ez-toc-counter ez-toc-custom ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #ea7e02;color:#ea7e02\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #ea7e02;color:#ea7e02\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/www.whizlabs.com\/blog\/azure-container-instance-terraform\/#What_is_an_Azure_Instance\" >What is an Azure Instance?<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/www.whizlabs.com\/blog\/azure-container-instance-terraform\/#Features_of_Azure_Containers_Instance\" >Features of Azure Containers Instance<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/www.whizlabs.com\/blog\/azure-container-instance-terraform\/#Deploying_Azure_Instances_with_Public_IP_using_Terraform\" >Deploying Azure Instances with Public IP using Terraform<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/www.whizlabs.com\/blog\/azure-container-instance-terraform\/#Prerequisites_of_Deploying_an_Azure_Container_Instance_with_Terraform\" >Prerequisites of Deploying an Azure Container Instance with Terraform<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/www.whizlabs.com\/blog\/azure-container-instance-terraform\/#Implementing_Terraform_code\" >Implementing Terraform code<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/www.whizlabs.com\/blog\/azure-container-instance-terraform\/#Initialize_Terraform_Code\" >Initialize Terraform Code\u00a0<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/www.whizlabs.com\/blog\/azure-container-instance-terraform\/#Create_a_Terraform_Execution_Plan\" >Create a Terraform Execution Plan<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/www.whizlabs.com\/blog\/azure-container-instance-terraform\/#Verifying_the_results\" >Verifying the results<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/www.whizlabs.com\/blog\/azure-container-instance-terraform\/#Clean_up_resources\" >Clean up resources<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-10\" href=\"https:\/\/www.whizlabs.com\/blog\/azure-container-instance-terraform\/#Conclusion\" >Conclusion\u00a0<\/a><\/li><\/ul><\/nav><\/div>\n<h2><span class=\"ez-toc-section\" id=\"What_is_an_Azure_Instance\"><\/span><span style=\"font-weight: 400;\">What is an Azure Instance?<\/span><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p><span style=\"font-weight: 400;\">Undoubtedly, <a href=\"https:\/\/www.whizlabs.com\/blog\/containers-in-cloud-computing\/\" target=\"_blank\" rel=\"noopener\">containers<\/a> are becoming the favored method to package, deploy, and oversee cutting-edge applications. Azure Container Instance, therefore, are extensively used to provide the quickest and easiest way to run a container without needing to handle virtual machines or adopt a more advanced service.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Moreover, <a href=\"https:\/\/azure.microsoft.com\/en-in\/products\/container-instances\" target=\"_blank\" rel=\"nofollow noopener\">Azure Container Instance<\/a> is an ideal solution for myriad scenarios like operating within isolated containers offering substantial advantages over VMs regarding startup time. You can launch containers in seconds, eliminating the requirement to set up and manage VMs, making complex processes like deploying applications, task automation, and building jobs a breeze. <span class=\"ui-provider fz b c d e f g h i j k l m n o p q r s t u v w x y z ab ac ae af ag ah ai aj ak\" dir=\"ltr\">ACI shows a good amount of scalability and flexibility.\u00a0<\/span><\/span><\/p>\n<p><span style=\"font-weight: 400;\">Azure Container Instance pricing varies based on factors such as the container size, region, and usage duration.<\/span><\/p>\n<h3><span class=\"ez-toc-section\" id=\"Features_of_Azure_Containers_Instance\"><\/span><span style=\"font-weight: 400;\">Features of Azure Containers Instance<\/span><span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-90232\" src=\"https:\/\/www.whizlabs.com\/blog\/wp-content\/uploads\/2023\/07\/features-of-azure-container-instance-infographics-1.png\" alt=\"azure-container-instance\" width=\"2954\" height=\"2677\" srcset=\"https:\/\/www.whizlabs.com\/blog\/wp-content\/uploads\/2023\/07\/features-of-azure-container-instance-infographics-1.png 2954w, https:\/\/www.whizlabs.com\/blog\/wp-content\/uploads\/2023\/07\/features-of-azure-container-instance-infographics-1-300x272.png 300w, https:\/\/www.whizlabs.com\/blog\/wp-content\/uploads\/2023\/07\/features-of-azure-container-instance-infographics-1-1024x928.png 1024w, https:\/\/www.whizlabs.com\/blog\/wp-content\/uploads\/2023\/07\/features-of-azure-container-instance-infographics-1-768x696.png 768w, https:\/\/www.whizlabs.com\/blog\/wp-content\/uploads\/2023\/07\/features-of-azure-container-instance-infographics-1-1536x1392.png 1536w, https:\/\/www.whizlabs.com\/blog\/wp-content\/uploads\/2023\/07\/features-of-azure-container-instance-infographics-1-2048x1856.png 2048w, https:\/\/www.whizlabs.com\/blog\/wp-content\/uploads\/2023\/07\/features-of-azure-container-instance-infographics-1-150x136.png 150w\" sizes=\"(max-width: 2954px) 100vw, 2954px\" \/><\/p>\n<p>&nbsp;<\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Support for both Linux and Windows containers.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Ability to launch new containers through the Azure portal, command line interface (CLI), or preferred automation tools like Terraform, with automatic configuration and scaling of compute resources.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Support standard <a href=\"https:\/\/www.whizlabs.com\/blog\/docker-image-creation-everything-you-should-know\/\" target=\"_blank\" rel=\"noopener\">Docker images<\/a> and public container registries like Docker Hub and Azure Container Registry.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Ability to specify the desired CPU cores and memory for container instances<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Configurable networking features, including assigning a public IP address, adding a domain name prefix, and selecting exposed ports.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Linux containers have faster startup times due to smaller image sizes than Windows containers. However, Windows containers have some limitations and do not support all the same features as Linux containers.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Restart policy available for an Azure container instance to define container behavior upon stopping.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Support mounting volumes, including Azure file share, secret volumes, and git repositories.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Option to specify command line parameters during container instance creation to override the initial default command.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Ability to define environment variables for containers<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Access to logs emitted by an Azure container instance.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Grouping capability to organize multiple containers sharing the same host, storage, and networking resources, similar to pods in Kubernetes<\/span><\/li>\n<\/ul>\n<blockquote><p>Know More : Tips &amp; Tricks to Pass <a href=\"https:\/\/www.whizlabs.com\/blog\/tips-tricks-az-900-certification\/\" target=\"_blank\" rel=\"noopener\">AZ : 900<\/a> Certification Exam<\/p><\/blockquote>\n<h2><span class=\"ez-toc-section\" id=\"Deploying_Azure_Instances_with_Public_IP_using_Terraform\"><\/span><span style=\"font-weight: 400;\">Deploying Azure Instances with Public IP using Terraform<\/span><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p><span style=\"font-weight: 400;\">Deploying Azure instances with public IP addresses using Terraform offers a streamlined and automated approach to provisioning infrastructure in the Azure cloud. By harnessing the power of infrastructure as code, you can define and manage your Azure resources consistently and efficiently. This enables you to deploy virtual machines with public IP addresses effortlessly, facilitating seamless connectivity and accessibility. Here&#8217;s an overview of the entire process of creating ACI using a public IP address.\u00a0<\/span><\/p>\n<ol>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Download and install Terraform on your local machine. Ensure it&#8217;s properly configured to interact with Azure.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Set up an Azure service principal, a security identity Terraform uses to authenticate and interact with Azure resources.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Define the Azure provider block in your Terraform configuration file (usually named main.tf). Configure it with your Azure subscription details and service principal authentication information.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Create a resource group in Azure where you&#8217;ll deploy your instances. Specify the resource group name and location in your Terraform configuration.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Specify a <a href=\"https:\/\/www.whizlabs.com\/blog\/azure-vnet-peering\/\" target=\"_blank\" rel=\"noopener\">virtual network (VNet)<\/a> for deploying your instances. Define the VNet name, address space, and subnet details in your Terraform configuration.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Add a resource block to define the public IP address associated with your instance. Specify the public IP name, allocation method, and additional configuration options.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Create a network interface resource block that connects the public IP with the VNet and subnet. Specify the network interface name, subnet ID, and public IP ID.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Create a virtual machine (VM) resource block that utilizes the network interface. Specify the VM name, size, OS image, authentication details, and additional configuration.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Save your Terraform configuration file, initialize the Terraform working directory with Terraform init, preview changes with Terraform plan, and deploy resources with Terraform apply. Confirm the deployment by entering &#8220;yes&#8221; when prompted.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">After deployment, verify the creation of Azure instances and associated public IP addresses in the Azure portal or by using Azure CLI commands.<\/span><\/li>\n<\/ol>\n<blockquote><p>Also Read : Microsoft Azure Fundamentals: <a href=\"https:\/\/www.whizlabs.com\/blog\/az-900-exam-preparation\/\" target=\"_blank\" rel=\"noopener\">AZ-900<\/a> Preparation Guide<\/p><\/blockquote>\n<h2><span class=\"ez-toc-section\" id=\"Prerequisites_of_Deploying_an_Azure_Container_Instance_with_Terraform\"><\/span><span style=\"font-weight: 400;\">Prerequisites of Deploying an Azure Container Instance with Terraform<\/span><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p><span style=\"font-weight: 400;\">Before deploying an Azure container instance (ACI) using Terraform, there are several prerequisites that you need to have in place:<\/span><\/p>\n<ol>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Azure Subscription<\/b><span style=\"font-weight: 400;\">: You must have an active Azure subscription to provision resources in Azure. You can create a free Azure account if you don&#8217;t have one.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Install Terraform<\/b><span style=\"font-weight: 400;\">: Make sure you have Terraform installed on your local machine. You can download the latest version from the official website and follow the installation instructions for your operating system.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Azure CLI<\/b><span style=\"font-weight: 400;\">: Install the Azure CLI on your machine, as it provides the command-line interface for interacting with Azure resources. You&#8217;ll need it for authentication and resource management. Also, this can also be used as <span class=\"ui-provider fz b c d e f g h i j k l m n o p q r s t u v w x y z ab ac ae af ag ah ai aj ak\" dir=\"ltr\">Azure CLI for ACI deployment.\u00a0<\/span><\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Azure Container Registry (ACR)<\/b><span style=\"font-weight: 400;\">: If you plan to deploy container images from a private registry, set up an Azure Container Registry (ACR) in advance. ACR allows secure storage and management of container images. Ensure you have the necessary permissions to access the ACR.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Terraform Configuration<\/b><span style=\"font-weight: 400;\">: Create a Terraform configuration file (usually named main.tf) where you define your infrastructure as code. This file specifies the Azure provider, resource definitions, and other necessary configurations for deploying ACI.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Azure Authentication<\/b><span style=\"font-weight: 400;\">: Configure your authentication method for Terraform to interact with Azure. This can be done using Azure CLI or setting environment variables for Azure credentials.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><a href=\"https:\/\/www.whizlabs.com\/blog\/an-introduction-to-azure-resource-manager\/\" target=\"_blank\" rel=\"noopener\"><b>Azure Resource Group<\/b><\/a><span style=\"font-weight: 400;\">: Choose or create an Azure resource group where your ACI resources will be deployed. The resource group serves as a logical container for grouping related resources.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Container Image<\/b><span style=\"font-weight: 400;\">: Ensure you have the container image you want to deploy to ACI stored in a registry, such as Azure Container Registry or Docker Hub. In your Terraform configuration, provide the required information about the image, such as the registry URL, image name, and tag.<\/span><\/li>\n<\/ol>\n<h2><span class=\"ez-toc-section\" id=\"Implementing_Terraform_code\"><\/span><span style=\"font-weight: 400;\">Implementing Terraform code<\/span><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p><span style=\"font-weight: 400;\">To implement Terraform, define the Azure provider and create a resource group. Next, we define an Azure Container Instance Group resource called &#8220;example-container-group.&#8221; We provide the container details inside the container group, such as the image to be used, CPU and memory limits, and the ports to expose. <span class=\"ui-provider fz b c d e f g h i j k l m n o p q r s t u v w x y z ab ac ae af ag ah ai aj ak\" dir=\"ltr\">Terraform infrastructure as code allows <em>you to manage infrastructure with configuration files rather than<\/em>\u00a0a graphical user interface.\u00a0<\/span><\/span><\/p>\n<p><span style=\"font-weight: 400;\">The crucial step to enable the public IP address is to set the ip_address_type attribute as &#8220;public&#8221; and specify a dns_name_label. The dns_name_label creates a publicly resolvable DNS name for accessing the container instance.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">To proceed, ensure you have the Azure CLI and Terraform installed on your machine. Before running Terraform commands, it&#8217;s essential to authenticate with Azure using the CLI (az login).<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Please note that these instructions assume familiarity with the Azure CLI and Terraform, and it&#8217;s recommended to refer to the official documentation for detailed guidance.<\/span><\/p>\n<h2><span class=\"ez-toc-section\" id=\"Initialize_Terraform_Code\"><\/span><span style=\"font-weight: 400;\">Initialize Terraform Code\u00a0<\/span><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p><span style=\"font-weight: 400;\">Define the Azure provider and the resource group where you must deploy the container group. Next, describe the parameter name of the container group and ensure that the location specifies the container group&#8217;s name. The resource_group_name parameter refers to the previously created resource group.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Next, to assign a public IP address to the container group, set the ip_address_type to &#8220;public.&#8221; The dns_name_label determines the DNS name label used to access the container group.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Within the azurerm_container_group resource block, we define a single container using the container block. To create the Azure Container Instance with a public IP, save this code in a .tf file, initialize the Terraform environment, and execute Terraform application.<\/span><\/p>\n<h2><span class=\"ez-toc-section\" id=\"Create_a_Terraform_Execution_Plan\"><\/span><span style=\"font-weight: 400;\">Create a Terraform Execution Plan<\/span><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p><span style=\"font-weight: 400;\">In this code, first, define the Azure provider and enable all features. Then, we create an Azure resource group mentioning the location.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Next, create an Azure Container Group within the resource group. It should have a public IP address and a DNS name label for easy access. To generate the Terraform execution plan, follow these steps:<\/span><\/p>\n<ol>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Open a terminal or command prompt and navigate to the directory where the main.tf file is saved.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Initialize the Terraform configuration by running the command<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Verify the configuration by running the command<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Generate the execution plan by running the command<\/span><\/li>\n<\/ol>\n<p><span style=\"font-weight: 400;\"><span class=\"ui-provider fz b c d e f g h i j k l m n o p q r s t u v w x y z ab ac ae af ag ah ai aj ak\" dir=\"ltr\">Terraform applies and execution plan<\/span> that outlines the actions it will take to create the Azure Container Instance with a public IP. Review the program to ensure it aligns with your expectations.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">However, before applying the plan using Terraform apply, ensure you have configured Azure credentials and the necessary permissions to create resources in the specified Azure subscription.\u00a0<\/span><\/p>\n<h2><span class=\"ez-toc-section\" id=\"Verifying_the_results\"><\/span><span style=\"font-weight: 400;\">Verifying the results<\/span><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p><span style=\"font-weight: 400;\">To verify the results of your <a href=\"https:\/\/learn.microsoft.com\/en-us\/azure\/container-instances\/container-instances-quickstart-terraform\" target=\"_blank\" rel=\"nofollow noopener\">Terraform execution<\/a> for launching an Azure container instance (ACI) with a public IP, follow these steps:<\/span><\/p>\n<ol>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">After running terraform plan and reviewing the execution plan, apply the changes by running the command: terraform use.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">When prompted to confirm the changes, type &#8220;yes&#8221; and press Enter to proceed.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Terraform will execute the plan and create the necessary Azure resources, including the ACI with a public IP.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Once the provisioning is complete, Terraform will display the applied changes and provide the output values specified in your configuration.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Check for any error messages during the execution. If there are errors, Terraform will roll back the changes and provide relevant error details for troubleshooting.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">To verify the creation of the ACI with a public IP, you can log in to the Azure portal or use Azure CLI\/PowerShell commands. For example, run the following Azure CLI command to list the container instances in the resource group:<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">shellCopy code<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">az container list &#8211;resource-group aci-example-rg<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Replace &#8220;aci-example-rg&#8221; with the actual name of your resource group.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Ensure that the ACI is running and has a public IP assigned. Check the container group&#8217;s properties, specifically the IP address and DNS name label you specified.<\/span><\/li>\n<\/ol>\n<h2><span class=\"ez-toc-section\" id=\"Clean_up_resources\"><\/span><span style=\"font-weight: 400;\">Clean up resources<\/span><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p><span style=\"font-weight: 400;\">To clean up the resources created by Terraform for launching an Azure container instance (ACI) with a public IP, follow these steps:<\/span><\/p>\n<ol>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Open a terminal or command prompt.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Navigate to the directory where your Terraform configuration files are located.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Run the following command to destroy the infrastructure created by Terraform.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Terraform will ask for confirmation to destroy the resources. Type &#8220;yes&#8221; and press Enter to proceed.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Wait for Terraform to complete the destruction process. It will delete the ACI, public IP, and other associated resources.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Once the resources are successfully deleted, Terraform will display a message indicating the completion of the destruction process.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Verify the deletion of the resources by logging in to the Azure portal or using Azure CLI\/PowerShell commands. Check the resource group to ensure that the ACI and public IP have been removed.<\/span><\/li>\n<\/ol>\n<div class=\"ast-oembed-container \" style=\"height: 100%;\"><iframe title=\"What is Azure Container Instance and how to work with Azure Container Instance (Tutorial) | Whizlabs\" width=\"500\" height=\"281\" src=\"https:\/\/www.youtube.com\/embed\/u1djS-mil6s?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen><\/iframe><\/div>\n<h2><span class=\"ez-toc-section\" id=\"Conclusion\"><\/span><span style=\"font-weight: 400;\">Conclusion\u00a0<\/span><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p><span style=\"font-weight: 400;\">Hope this blog helps you take a deep dive into creating an Azure container instance with a public IP address using a public IP. If you are kick-starting your career in <a href=\"https:\/\/www.whizlabs.com\/microsoft-azure-certification-training-courses\/\" target=\"_blank\" rel=\"noopener\">Azure Certification Path<\/a> infrastructure or preparing for <span class=\"ui-provider fz b c d e f g h i j k l m n o p q r s t u v w x y z ab ac ae af ag ah ai aj ak\" dir=\"ltr\">Azure fundamentals for AZ-900 certification<\/span>, note that this concept is a critical skill to gain.<\/span><\/p>\n<p>However, <span class=\"ui-provider fz b c d e f g h i j k l m n o p q r s t u v w x y z ab ac ae af ag ah ai aj ak\" dir=\"ltr\">Azure Container Instance benefits fast, isolated computing to meet traffic that comes in spikes, without the need to manage servers. However<\/span>, you need authentic resources, guides, and practice labs to launch ACI using Terraform codes for comprehensive upskilling. <span class=\"ui-provider fz b c d e f g h i j k l m n o p q r s t u v w x y z ab ac ae af ag ah ai aj ak\" dir=\"ltr\">ACI cost optimization in Azure will manage your cloud spending and focus on what matters most to your business.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">With this in mind, Whizlabs brings all the materials you need to understand Terraform code and deploy an Azure container instance. You will find video lectures by domain experts, round-the-clock support from the Whizlabs teams, dedicated <a href=\"https:\/\/www.whizlabs.com\/labs\/deploy-azure-container-instances\" target=\"_blank\" rel=\"noopener\">hands-on labs<\/a>, and <a href=\"https:\/\/www.whizlabs.com\/labs\/azure-sandbox\" target=\"_blank\" rel=\"noopener\">Azure sandbox<\/a> to understand the scope and challenges of implementing ACI using Terraform. Does this pique your interest? Reach out to us today!\u00a0<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>With cloud computing constantly evolving and revolutionizing how organizations deploy and manage their apps, an Azure Container Instance (ACI) has emerged as a powerful solution to enable lightweight and scalable containerized workloads. Azure Container Instance ACI makes it a breeze to execute isolated and serverless containers while ensuring the flexibility of Terraform\u2019s infrastructure as a code approach. Organizations can effortlessly create and manage ACI instances with public IP addresses, enabling friction-free connectivity and accessibility for containerized applications.\u00a0 Suppose you are preparing for Microsoft Azure AZ-900 certification, exploring Microsoft Azure, or finding ways to strengthen your understanding of Azure fundamentals and [&hellip;]<\/p>\n","protected":false},"author":386,"featured_media":90147,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_uag_custom_page_level_css":"","site-sidebar-layout":"default","site-content-layout":"default","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","theme-transparent-header-meta":"default","adv-header-id-meta":"","stick-header-meta":"default","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"set","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[15],"tags":[5041,1681],"class_list":["post-90119","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-microsoft-azure","tag-az-900","tag-az-900-exam"],"uagb_featured_image_src":{"full":["https:\/\/www.whizlabs.com\/blog\/wp-content\/uploads\/2023\/07\/how-to-create-an-azure-container-instance.webp",1280,720,false],"thumbnail":["https:\/\/www.whizlabs.com\/blog\/wp-content\/uploads\/2023\/07\/how-to-create-an-azure-container-instance-150x150.webp",150,150,true],"medium":["https:\/\/www.whizlabs.com\/blog\/wp-content\/uploads\/2023\/07\/how-to-create-an-azure-container-instance-300x169.webp",300,169,true],"medium_large":["https:\/\/www.whizlabs.com\/blog\/wp-content\/uploads\/2023\/07\/how-to-create-an-azure-container-instance-768x432.webp",768,432,true],"large":["https:\/\/www.whizlabs.com\/blog\/wp-content\/uploads\/2023\/07\/how-to-create-an-azure-container-instance-1024x576.webp",1024,576,true],"1536x1536":["https:\/\/www.whizlabs.com\/blog\/wp-content\/uploads\/2023\/07\/how-to-create-an-azure-container-instance.webp",1280,720,false],"2048x2048":["https:\/\/www.whizlabs.com\/blog\/wp-content\/uploads\/2023\/07\/how-to-create-an-azure-container-instance.webp",1280,720,false],"profile_24":["https:\/\/www.whizlabs.com\/blog\/wp-content\/uploads\/2023\/07\/how-to-create-an-azure-container-instance.webp",24,14,false],"profile_48":["https:\/\/www.whizlabs.com\/blog\/wp-content\/uploads\/2023\/07\/how-to-create-an-azure-container-instance.webp",48,27,false],"profile_96":["https:\/\/www.whizlabs.com\/blog\/wp-content\/uploads\/2023\/07\/how-to-create-an-azure-container-instance.webp",96,54,false],"profile_150":["https:\/\/www.whizlabs.com\/blog\/wp-content\/uploads\/2023\/07\/how-to-create-an-azure-container-instance.webp",150,84,false],"profile_300":["https:\/\/www.whizlabs.com\/blog\/wp-content\/uploads\/2023\/07\/how-to-create-an-azure-container-instance.webp",300,169,false],"tptn_thumbnail":["https:\/\/www.whizlabs.com\/blog\/wp-content\/uploads\/2023\/07\/how-to-create-an-azure-container-instance-250x250.webp",250,250,true],"web-stories-poster-portrait":["https:\/\/www.whizlabs.com\/blog\/wp-content\/uploads\/2023\/07\/how-to-create-an-azure-container-instance-640x720.webp",640,720,true],"web-stories-publisher-logo":["https:\/\/www.whizlabs.com\/blog\/wp-content\/uploads\/2023\/07\/how-to-create-an-azure-container-instance-96x96.webp",96,96,true],"web-stories-thumbnail":["https:\/\/www.whizlabs.com\/blog\/wp-content\/uploads\/2023\/07\/how-to-create-an-azure-container-instance-150x84.webp",150,84,true]},"uagb_author_info":{"display_name":"Basant Singh","author_link":"https:\/\/www.whizlabs.com\/blog\/author\/basant-singh\/"},"uagb_comment_info":1,"uagb_excerpt":"With cloud computing constantly evolving and revolutionizing how organizations deploy and manage their apps, an Azure Container Instance (ACI) has emerged as a powerful solution to enable lightweight and scalable containerized workloads. Azure Container Instance ACI makes it a breeze to execute isolated and serverless containers while ensuring the flexibility of Terraform\u2019s infrastructure as a&hellip;","_links":{"self":[{"href":"https:\/\/www.whizlabs.com\/blog\/wp-json\/wp\/v2\/posts\/90119","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.whizlabs.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.whizlabs.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.whizlabs.com\/blog\/wp-json\/wp\/v2\/users\/386"}],"replies":[{"embeddable":true,"href":"https:\/\/www.whizlabs.com\/blog\/wp-json\/wp\/v2\/comments?post=90119"}],"version-history":[{"count":16,"href":"https:\/\/www.whizlabs.com\/blog\/wp-json\/wp\/v2\/posts\/90119\/revisions"}],"predecessor-version":[{"id":94165,"href":"https:\/\/www.whizlabs.com\/blog\/wp-json\/wp\/v2\/posts\/90119\/revisions\/94165"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.whizlabs.com\/blog\/wp-json\/wp\/v2\/media\/90147"}],"wp:attachment":[{"href":"https:\/\/www.whizlabs.com\/blog\/wp-json\/wp\/v2\/media?parent=90119"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.whizlabs.com\/blog\/wp-json\/wp\/v2\/categories?post=90119"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.whizlabs.com\/blog\/wp-json\/wp\/v2\/tags?post=90119"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}