ईवेंट्स
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.
Azure virtual machine scale sets allow you to configure identical VMs. The number of VM instances can adjust based on demand or a schedule. For more information, see Automatically scale a virtual machine scale set in the Azure portal.
In this article, you learn how to:
Configure Terraform: If you haven't already done so, configure Terraform using one of the following options:
Create a directory in which to test the sample Terraform code and make it the current directory.
Create a file named main.tf
and insert the following code:
terraform {
required_version = ">=0.12"
required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = "~>3.0"
}
}
}
provider "azurerm" {
features {
resource_group {
prevent_deletion_if_contains_resources = false
}
}
}
resource "random_password" "password" {
count = var.admin_password == null ? 1 : 0
length = 20
}
locals {
admin_password = try(random_password.password[0].result, var.admin_password)
}
resource "azurerm_resource_group" "vmss" {
name = var.resource_group_name
location = var.location
tags = var.tags
}
resource "random_string" "fqdn" {
length = 6
special = false
upper = false
numeric = false
}
resource "azurerm_virtual_network" "vmss" {
name = "vmss-vnet"
address_space = ["10.0.0.0/16"]
location = var.location
resource_group_name = azurerm_resource_group.vmss.name
tags = var.tags
}
resource "azurerm_subnet" "vmss" {
name = "vmss-subnet"
resource_group_name = azurerm_resource_group.vmss.name
virtual_network_name = azurerm_virtual_network.vmss.name
address_prefixes = ["10.0.2.0/24"]
}
resource "azurerm_public_ip" "vmss" {
name = "vmss-public-ip"
location = var.location
resource_group_name = azurerm_resource_group.vmss.name
allocation_method = "Static"
domain_name_label = random_string.fqdn.result
tags = var.tags
}
resource "azurerm_lb" "vmss" {
name = "vmss-lb"
location = var.location
resource_group_name = azurerm_resource_group.vmss.name
frontend_ip_configuration {
name = "PublicIPAddress"
public_ip_address_id = azurerm_public_ip.vmss.id
}
tags = var.tags
}
resource "azurerm_lb_backend_address_pool" "bpepool" {
loadbalancer_id = azurerm_lb.vmss.id
name = "BackEndAddressPool"
}
resource "azurerm_lb_probe" "vmss" {
loadbalancer_id = azurerm_lb.vmss.id
name = "ssh-running-probe"
port = var.application_port
}
resource "azurerm_lb_rule" "lbnatrule" {
loadbalancer_id = azurerm_lb.vmss.id
name = "http"
protocol = "Tcp"
frontend_port = var.application_port
backend_port = var.application_port
backend_address_pool_ids = [azurerm_lb_backend_address_pool.bpepool.id]
frontend_ip_configuration_name = "PublicIPAddress"
probe_id = azurerm_lb_probe.vmss.id
}
resource "azurerm_virtual_machine_scale_set" "vmss" {
name = "vmscaleset"
location = var.location
resource_group_name = azurerm_resource_group.vmss.name
upgrade_policy_mode = "Manual"
sku {
name = "Standard_DS1_v2"
tier = "Standard"
capacity = 2
}
storage_profile_image_reference {
publisher = "Canonical"
offer = "UbuntuServer"
sku = "16.04-LTS"
version = "latest"
}
storage_profile_os_disk {
name = ""
caching = "ReadWrite"
create_option = "FromImage"
managed_disk_type = "Standard_LRS"
}
storage_profile_data_disk {
lun = 0
caching = "ReadWrite"
create_option = "Empty"
disk_size_gb = 10
}
os_profile {
computer_name_prefix = "vmlab"
admin_username = var.admin_user
admin_password = local.admin_password
custom_data = file("web.conf")
}
os_profile_linux_config {
disable_password_authentication = false
}
network_profile {
name = "terraformnetworkprofile"
primary = true
ip_configuration {
name = "IPConfiguration"
subnet_id = azurerm_subnet.vmss.id
load_balancer_backend_address_pool_ids = [azurerm_lb_backend_address_pool.bpepool.id]
primary = true
}
}
tags = var.tags
}
resource "azurerm_public_ip" "jumpbox" {
name = "jumpbox-public-ip"
location = var.location
resource_group_name = azurerm_resource_group.vmss.name
allocation_method = "Static"
domain_name_label = "${random_string.fqdn.result}-ssh"
tags = var.tags
}
resource "azurerm_network_interface" "jumpbox" {
name = "jumpbox-nic"
location = var.location
resource_group_name = azurerm_resource_group.vmss.name
ip_configuration {
name = "IPConfiguration"
subnet_id = azurerm_subnet.vmss.id
private_ip_address_allocation = "Dynamic"
public_ip_address_id = azurerm_public_ip.jumpbox.id
}
tags = var.tags
}
resource "azurerm_virtual_machine" "jumpbox" {
name = "jumpbox"
location = var.location
resource_group_name = azurerm_resource_group.vmss.name
network_interface_ids = [azurerm_network_interface.jumpbox.id]
vm_size = "Standard_DS1_v2"
storage_image_reference {
publisher = "Canonical"
offer = "UbuntuServer"
sku = "16.04-LTS"
version = "latest"
}
storage_os_disk {
name = "jumpbox-osdisk"
caching = "ReadWrite"
create_option = "FromImage"
managed_disk_type = "Standard_LRS"
}
os_profile {
computer_name = "jumpbox"
admin_username = var.admin_user
admin_password = local.admin_password
}
os_profile_linux_config {
disable_password_authentication = false
}
tags = var.tags
}
Create a file named variables.tf
to contain the project variables and insert the following code:
variable "resource_group_name" {
description = "Name of the resource group in which the resources will be created"
default = "myResourceGroup"
}
variable "location" {
default = "eastus"
description = "Location where resources will be created"
}
variable "tags" {
description = "Map of the tags to use for the resources that are deployed"
type = map(string)
default = {
environment = "codelab"
}
}
variable "application_port" {
description = "Port that you want to expose to the external load balancer"
default = 80
}
variable "admin_user" {
description = "User name to use as the admin account on the VMs that will be part of the VM scale set"
default = "azureuser"
}
variable "admin_password" {
description = "Default password for admin account"
default = null
sensitive = true
}
Create a file named output.tf
to specify what values Terraform displays and insert the following code:
output "vmss_public_ip_fqdn" {
value = azurerm_public_ip.vmss.fqdn
}
output "jumpbox_public_ip_fqdn" {
value = azurerm_public_ip.jumpbox.fqdn
}
output "jumpbox_public_ip" {
value = azurerm_public_ip.jumpbox.ip_address
}
Create a file named web.conf
and insert the following code:
#cloud-config
packages:
- nginx
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.From the output of the terraform apply
command, you see values for the following:
Browse to the virtual machine URL to confirm a default page with the text Welcome to nginx!.
Use SSH to connect to the jumpbox VM using the user name defined in the variables file and the password you specified when you ran terraform apply
. For example: ssh azureuser@<ip_address>
.
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 व्यवस्थापक सहयोगी - Certifications
Microsoft Azure में मुख्य व्यावसायिक फ़ंक्शंस कॉन्फ़िगर, प्रबंधित, सुरक्षित और व्यवस्थापित करने के लिए मुख्य कौशल प्रदर्शित करें.
दस्तावेज़ीकरण
Quickstart: Use Terraform to create a Windows VM - Azure Virtual Machines
In this quickstart, you learn how to use Terraform to create a Windows virtual machine
Quickstart: Use Terraform to create a Linux VM - Azure Virtual Machines
In this quickstart, you learn how to use Terraform to create a Linux virtual machine
Create an Azure virtual machine scale set from a Packer custom image by using Terraform
Learn how to use Terraform to configure and version an Azure virtual machine scale set from a custom image generated by Packer