Deploy a Container Instance in Azure

This article was translated from English: Does it need improvement?
Translated
View the article in English

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

Häufig gestellte Fragen

Wie deploye ich einen Docker-Container in Azure mit Terraform?

Um einen Docker-Container in Azure mit Terraform bereitzustellen, müssen Sie die GitHub-Repository-Vorlage für IronSecureDoc klonen, die Ressourcennamen in `variables.tf` ändern und eine Datei `secret.tfvars` mit sensiblen Daten erstellen. Initialisieren Sie dann die Bereitstellung mit terraform init und erstellen und wenden Sie einen Ausführungsplan mit terraform plan und terraform apply an.

Welche Schritte sind notwendig, um Terraform für Azure-Bereitstellungen einzurichten?

Installieren und konfigurieren Sie zuerst Terraform, dann authentifizieren Sie sich bei Azure. Klonen Sie das spezifische GitHub-Repository für IronSecureDoc, ändern Sie Ressourcennamen in der Datei `variables.tf` und verwalten Sie sensible Daten in `secret.tfvars`. Schließlich initialisieren Sie Terraform und erstellen einen Ausführungsplan für die Bereitstellung.

Welche Rolle spielt die Azure Container Registry in dieser Bereitstellung?

Die Azure Container Registry wird verwendet, um die Docker-Images zu speichern. Sie müssen die Registry-Anmeldeinformationen in der `main.tf`-Datei hinzufügen und die Registry-Informationen in `variables.tf` und `secret.tfvars` angeben, damit die Bereitstellung auf die benötigten Docker-Images zugreifen und diese bereitstellen kann.

Wie kann ich überprüfen, ob meine Terraform-Bereitstellung in Azure erfolgreich ist?

Nachdem Sie den Terraform-Ausführungsplan angewendet haben, führen Sie terraform output aus, um die öffentliche IP-Adresse oder den FQDN zu erhalten. Verwenden Sie Tools wie Postman oder curl, um eine Ping-Anfrage an den Dienst zu senden. Eine erfolgreiche Bereitstellung gibt 'pong' zurück.

Welcher Befehl wird verwendet, um Terraform für Azure-Bereitstellungen zu initialisieren?

Um Terraform für Azure-Bereitstellungen zu initialisieren, verwenden Sie den Befehl terraform init -upgrade. Dadurch werden die notwendigen Provider-Plugins heruntergeladen, die zum Verwalten von Azure-Ressourcen benötigt werden.

Wie gehe ich mit sensiblen Daten in Terraform-Konfigurationen um?

Sensible Daten wie Registry-Anmeldeinformationen und Lizenzschlüssel sollten in einer `secret.tfvars` Datei gespeichert werden. Diese Datei wird während der Terraform-Plan- und Anwendungsprozesse referenziert, um sensible Informationen sicher zu verwalten.

Was ist der Prozess zum Zerstören bereitgestellter Ressourcen in Azure mit Terraform?

Um bereitgestellte Ressourcen in Azure mit Terraform zu zerstören, erstellen Sie einen Zerstörungs-Ausführungsplan mit terraform plan -destroy -var-file='secret.tfvars' -out main.tfplan und wenden Sie ihn mit terraform apply main.tfplan an.

Curtis Chau
Technischer Autor

Curtis Chau hat einen Bachelor-Abschluss in Informatik von der Carleton University und ist spezialisiert auf Frontend-Entwicklung mit Expertise in Node.js, TypeScript, JavaScript und React. Leidenschaftlich widmet er sich der Erstellung intuitiver und ästhetisch ansprechender Benutzerschnittstellen und arbeitet gerne mit modernen Frameworks sowie der Erstellung gut strukturierter, optisch ansprechender ...

Weiterlesen
Bereit anzufangen?
Version: 2024.10 gerade veröffentlicht