ईवेंट्स
17 मार्च, 9 pm - 21 मार्च, 10 am
साथी डेवलपर्स और विशेषज्ञों के साथ वास्तविक दुनिया के उपयोग के मामलों के आधार पर स्केलेबल एआई समाधान बनाने के लिए मीटअप श्रृंखला में शामिल हों।
अभी पंजीकरण करेंयह ब्राउज़र अब समर्थित नहीं है.
नवीनतम सुविधाओं, सुरक्षा अपडेट और तकनीकी सहायता का लाभ लेने के लिए Microsoft Edge में अपग्रेड करें.
Terraform enables the definition, preview, and deployment of cloud infrastructure. Using Terraform, you create configuration files using HCL syntax. The HCL syntax allows you to specify the cloud provider - such as Azure - and the elements that make up your cloud infrastructure. After you create your configuration files, you create an execution plan that allows you to preview your infrastructure changes before they're deployed. Once you verify the changes, you apply the execution plan to deploy the infrastructure.
In this article, you learn how to use the AzAPI Terraform provider to manage an Azure service that the AzureRM provider currently doesn't support. In the example code, the azapi_resource
is used to manage an Azure Container Registry resource.
- Define and configure the AzureRM and AzAPI providers
- Use the AzureRM provider to create an Azure resource group with a unique name
- Use the AzureRM provider to register the "Microsoft.ContainerRegistry" provider in your subscription
- Use the AzAPI provider to create the Azure Container Registry resource
Configure Terraform: If you haven't already done so, configure Terraform using one of the following options:
नोट
The sample code for this article is located in the Azure Terraform GitHub repo. You can view the log file containing the test results from current and previous versions of Terraform.
See more articles and sample code showing how to use Terraform to manage Azure resources
Create a directory in which to test the sample Terraform code and make it the current directory.
Create a file named providers.tf
and insert the following code:
terraform {
required_providers {
azapi = {
source = "Azure/azapi"
version = "~>2.0"
}
azurerm = {
source = "hashicorp/azurerm"
version = "~>4.0"
}
random = {
source = "hashicorp/random"
version = "~>3.0"
}
}
}
provider "azurerm" {
features {}
}
Create a file named variables.tf
and insert the following code:
variable "resource_group_location" {
type = string
default = "eastus"
description = "Location of the resource group."
}
variable "resource_group_name_prefix" {
type = string
default = "rg"
description = "Prefix of the resource group name that's combined with a random ID so name is unique in your Azure subscription."
}
variable "container_registry_name" {
type = string
default = ""
description = "Name of the container registry."
}
Create a file named main.tf
and insert the following code:
# Create a resource group with a random name.
resource "random_pet" "rg_name" {
prefix = var.resource_group_name_prefix
}
resource "azurerm_resource_group" "rg" {
location = var.resource_group_location
name = random_pet.rg_name.id
}
# Create a user assigned identity resource.
resource "azurerm_user_assigned_identity" "example" {
name = "example"
resource_group_name = azurerm_resource_group.rg.name
location = azurerm_resource_group.rg.location
}
# Create a random name for the container registry.
resource "random_string" "acr_name" {
length = 10
special = false
upper = false
numeric = false
}
# Manage a container registry resource.
resource "azapi_resource" "example" {
type = "Microsoft.ContainerRegistry/registries@2020-11-01-preview"
name = coalesce(var.container_registry_name, random_string.acr_name.result)
parent_id = azurerm_resource_group.rg.id
location = azurerm_resource_group.rg.location
identity {
type = "SystemAssigned, UserAssigned"
identity_ids = [azurerm_user_assigned_identity.example.id]
}
body = {
sku = {
name = "Standard"
}
properties = {
adminUserEnabled = true
}
}
tags = {
"Key" = "Value"
}
response_export_values = ["properties.loginServer", "properties.policies.quarantinePolicy.status"]
}
Create a file named outputs.tf
and insert the following code:
output "resource_group_name" {
value = azurerm_resource_group.rg.name
}
output "azure_container_registry_name" {
value = azapi_resource.example.name
}
Run terraform init to initialize the Terraform deployment. This command downloads the Azure provider required to manage your Azure resources.
terraform init -upgrade
Key points:
-upgrade
parameter upgrades the necessary provider plugins to the newest version that complies with the configuration's version constraints.Run terraform plan to create an execution plan.
terraform plan -out main.tfplan
Key points:
terraform plan
command creates an execution plan, but doesn't execute it. Instead, it determines what actions are necessary to create the configuration specified in your configuration files. This pattern allows you to verify whether the execution plan matches your expectations before making any changes to actual resources.-out
parameter allows you to specify an output file for the plan. Using the -out
parameter ensures that the plan you reviewed is exactly what is applied.Run terraform apply to apply the execution plan to your cloud infrastructure.
terraform apply main.tfplan
Key points:
terraform apply
command assumes you previously ran terraform plan -out main.tfplan
.-out
parameter, use that same filename in the call to terraform apply
.-out
parameter, call terraform apply
without any parameters.Get the resource group name.
resource_group_name=$(terraform output -raw resource_group_name)
Get the container registry name.
azure_container_registry_name=$(terraform output -raw azure_container_registry_name)
Run az acr show to view the container registry.
az acr show --name $azure_container_registry_name --resource-group $resource_group_name
When you no longer need the resources created via Terraform, do the following steps:
Run terraform plan and specify the destroy
flag.
terraform plan -destroy -out main.destroy.tfplan
Key points:
terraform plan
command creates an execution plan, but doesn't execute it. Instead, it determines what actions are necessary to create the configuration specified in your configuration files. This pattern allows you to verify whether the execution plan matches your expectations before making any changes to actual resources.-out
parameter allows you to specify an output file for the plan. Using the -out
parameter ensures that the plan you reviewed is exactly what is applied.Run terraform apply to apply the execution plan.
terraform apply main.destroy.tfplan
ईवेंट्स
17 मार्च, 9 pm - 21 मार्च, 10 am
साथी डेवलपर्स और विशेषज्ञों के साथ वास्तविक दुनिया के उपयोग के मामलों के आधार पर स्केलेबल एआई समाधान बनाने के लिए मीटअप श्रृंखला में शामिल हों।
अभी पंजीकरण करेंप्रशिक्षण
प्रशिक्षण पथ
Azure पर Terraform के मूल सिद्धांत - Training
टेराफ़ॉर्म आपको Azure पर बुनियादी ढाँचे के परिनियोजन का प्रबंधन करने में कैसे सक्षम बनाता है, इसके मूल सिद्धांतों के बारे में जानें।
Certification
Microsoft प्रमाणित: Azure Fundamentals - Certifications
क्लाउड अवधारणाओं, कोर Azure सेवाओं, साथ ही Azure प्रबंधन और शासन सुविधाओं और उपकरणों के मूलभूत ज्ञान का प्रदर्शन करें।