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

よくある質問

Terraformを使用してAzureにDockerコンテナをデプロイする方法は?

Terraformを使用してAzureにDockerコンテナをデプロイするためには、IronSecureDoc用のGitHubリポジトリテンプレートをクローンし、`variables.tf`内のリソース名を変更して、機密データを含む`secret.tfvars`ファイルを作成する必要があります。その後、terraform initを使用してデプロイを初期化し、terraform planterraform applyを使用して実行プランを作成および適用します。

AzureデプロイのためのTerraform設定に必要な手順は何ですか?

まず、Terraformをインストールして設定し、それからAzureに認証します。IronSecureDoc用の特定のGitHubリポジトリをクローンし、`variables.tf`ファイル内のリソース名を変更して、`secret.tfvars`で機密データを管理します。最後に、Terraformを初期化し、デプロイメントのための実行プランを作成します。

このデプロイメントにおけるAzure Container Registryの役割は何ですか?

Azure Container RegistryはDockerイメージを保存するために使用されます。必要なDockerイメージをアクセスおよびデプロイするために、レジストリの認証情報を`main.tf`ファイルに追加し、`variables.tf`および`secret.tfvars`でレジストリ情報を指定する必要があります。

AzureでのTerraformデプロイが成功したかどうかを確認する方法は?

Terraform実行プランを適用した後、terraform outputを実行してパブリックIPアドレスまたはFQDNを取得します。Postmanやcurlのようなツールを使用してサービスにpingリクエストを送信します。成功したデプロイメントは「pong」を返します。

AzureデプロイメントのためにTerraformを初期化するコマンドは何ですか?

AzureデプロイメントのためにTerraformを初期化するには、terraform init -upgradeコマンドを使用します。これはAzureリソースを管理するために必要なプロバイダープラグインをダウンロードします。

Terraform構成で機密データをどのように扱いますか?

レジストリ認証情報やライセンスキーなどの機密データは、`secret.tfvars`ファイルに保存する必要があります。このファイルは、Terraformプランおよび適用プロセス中に参照され、機密情報を安全に管理します。

Terraformを使用してAzureでデプロイされたリソースを破棄するプロセスは何ですか?

Terraformを使用してAzureでデプロイされたリソースを破棄するには、terraform plan -destroy -var-file='secret.tfvars' -out main.tfplanで破棄実行プランを作成し、terraform apply main.tfplanを使用して適用します。

Curtis Chau
テクニカルライター

Curtis Chauは、カールトン大学でコンピュータサイエンスの学士号を取得し、Node.js、TypeScript、JavaScript、およびReactに精通したフロントエンド開発を専門としています。直感的で美しいユーザーインターフェースを作成することに情熱を持ち、Curtisは現代のフレームワークを用いた開発や、構造の良い視覚的に魅力的なマニュアルの作成を楽しんでいます。

開発以外にも、CurtisはIoT(Internet of Things)への強い関心を持ち、ハードウェアとソフトウェアの統合方法を模索しています。余暇には、ゲームをしたりDiscordボットを作成したりして、技術に対する愛情と創造性を組み合わせています。

準備はいいですか?
バージョン: 2024.10 ただ今リリースされました