Deploy a Container Instance in Azure

Use Terraform on Azure to deploy the IronSecureDoc Docker container and make it available with a public IP address and FQDN.

Prerequisites

Step 1: Clone GitHub Repository Template

We have the GitHub Repository template ready for you to clone and get started immediately here:

https://github.com/iron-software/IronSecureDoc-Terraform/

Step 2: Modify All Resource Names

Modify All Resource Names in variables.tf

  • resource_group_name: Name of the resource group.
  • resource_group_location: Location of the resource group. You can find the region from REGIONS.md and use the second column to fill in this variable.
  • container_group_name: Name of the container group.
  • container_name: Name of the container.
  • image_tag: The tag of the image to deploy; it can be latest or any specific version number.
  • Other variables do not need to be changed.

Create secret.tfvars to Contain All Sensitive Data

Populate the following variables in secret.tfvars.

Azure Container Registry

Append to main.tf after dns_name_label = var.dns_name_label:

image_registry_credential {
  server   = var.registry_server
  username = var.registry_username
  password = var.registry_password
}

Add to variables.tf:

variable "registry_server" {
  type        = string
  sensitive   = false
  description = "The server for the container registry. Required if the image is stored in a private registry."
}

variable "registry_username" {
  type        = string
  sensitive   = true
  description = "Username for the container registry. Required if the image is stored in a private registry."
}

variable "registry_password" {
  type        = string
  sensitive   = true
  description = "Password for the container registry. Required if the image is stored in a private registry."
}

Add to secret.tfvars:

registry_server   = "<registry-name>.azurecr.io"
registry_username = "YOUR-REGISTRY-USERNAME"
registry_password = "YOUR-REGISTRY-PASSWORD"
license_key       = "YOUR-LICENSE-KEY"

Docker Hub

Add to secret.tfvars:

license_key = "YOUR-LICENSE-KEY"

Step 3: Initialize Terraform

Run terraform init to initialize the Terraform deployment. This command downloads the Azure provider required to manage your Azure resources.

terraform init -upgrade
terraform init -upgrade
SHELL

Step 4: Create a Terraform Execution Plan

Run terraform plan to create an execution plan.

terraform plan -var-file="secret.tfvars" -out main.tfplan
terraform plan -var-file="secret.tfvars" -out main.tfplan
SHELL

Step 5: Apply a Terraform Execution Plan

Run terraform apply to apply the execution plan to your cloud infrastructure.

terraform apply main.tfplan
terraform apply main.tfplan
SHELL

Step 6: Verify the Results

  1. When you apply the execution plan, Terraform outputs the public IP address. To display the IP address again, run terraform output.

    terraform output -raw container_ipv4_address
    terraform output -raw container_ipv4_address
    SHELL

    Or display the FQDN.

    terraform output -raw container_fqdn
    terraform output -raw container_fqdn
    SHELL
  2. Use Postman or curl to validate. The expected result should return pong.

    curl http://<container_ipv4_address>:8080/v1/document-services/ping
    curl http://<container_ipv4_address>:8080/v1/document-services/ping
    SHELL

    Or use the FQDN.

    curl http://<container_fqdn>:8080/v1/document-services/ping
    curl http://<container_fqdn>:8080/v1/document-services/ping
    SHELL

Step 7: Destroy the Resource

  • Create an execution plan for destroying the resource.

    terraform plan -destroy -var-file="secret.tfvars" -out main.tfplan
    terraform plan -destroy -var-file="secret.tfvars" -out main.tfplan
    SHELL
  • Apply an execution destroy plan.

    terraform apply main.tfplan
    terraform apply main.tfplan
    SHELL

Frequently Asked Questions

How do I deploy a Docker container in Azure using Terraform?

To deploy a Docker container in Azure using Terraform, you need to clone the GitHub repository template for IronSecureDoc, modify the resource names in the `variables.tf`, and create a `secret.tfvars` file with sensitive data. Then, initialize the deployment with terraform init, and create and apply an execution plan using terraform plan and terraform apply.

What are the necessary steps to set up Terraform for Azure deployment?

First, install and configure Terraform, then authenticate it to Azure. Clone the specific GitHub repository for IronSecureDoc, modify resource names in the `variables.tf` file and manage sensitive data in `secret.tfvars`. Finally, initialize Terraform and create an execution plan for deployment.

What is the role of Azure Container Registry in this deployment?

Azure Container Registry is used to store the Docker images. You need to append the registry credentials in the `main.tf` file and specify the registry information in `variables.tf` and `secret.tfvars` for the deployment to access and deploy the necessary Docker images.

How can I verify if my Terraform deployment in Azure is successful?

After applying the Terraform execution plan, run terraform output to get the public IP address or FQDN. Use tools like Postman or curl to send a ping request to the service. A successful deployment will return 'pong'.

What command is used to initialize Terraform for Azure deployments?

To initialize Terraform for Azure deployments, use the command terraform init -upgrade. This downloads the necessary provider plugins required for managing Azure resources.

How do I handle sensitive data in Terraform configurations?

Sensitive data such as registry credentials and license keys should be stored in a `secret.tfvars` file. This file is referenced during the Terraform plan and apply processes to securely manage sensitive information.

What is the process for destroying deployed resources in Azure using Terraform?

To destroy deployed resources in Azure using Terraform, create a destroy execution plan with terraform plan -destroy -var-file='secret.tfvars' -out main.tfplan and apply it using terraform apply main.tfplan.

Chaknith Bin
Software Engineer
Chaknith works on IronXL and IronBarcode. He has deep expertise in C# and .NET, helping improve the software and support customers. His insights from user interactions contribute to better products, documentation, and overall experience.
Talk to an Expert Five Star Trust Score Rating

Ready to Get Started?