帮我用terraform版本123在azure上面创建一个带vnet的虚拟机vnet地址:19216810024虚拟机ip19216810100nsg名称:vm-nsgos操作系统:centos
7.6。
以下是基本的Terraform代码:
provider "azurerm" {
version = "=1.36.0"
features {}
}
resource "azurerm_resource_group" "example" {
name = "example-resources"
location = "East US"
}
resource "azurerm_virtual_network" "example" {
name = "example-network"
address_space = ["192.168.10.0/24"]
location = azurerm_resource_group.example.location
resource_group_name = azurerm_resource_group.example.name
}
resource "azurerm_subnet" "example" {
name = "example-subnet"
resource_group_name = azurerm_resource_group.example.name
virtual_network_name = azurerm_virtual_network.example.name
address_prefixes = ["192.168.10.0/24"]
}
resource "azurerm_network_security_group" "example" {
name = "vm-nsg"
location = azurerm_resource_group.example.location
resource_group_name = azurerm_resource_group.example.name
}
resource "azurerm_network_interface" "example" {
name = "example-nic"
location = azurerm_resource_group.example.location
resource_group_name = azurerm_resource_group.example.name
ip_configuration {
name = "internal"
subnet_id = azurerm_subnet.example.id
private_ip_address_allocation = "Static"
private_ip_address = "192.168.10.100"
}
}
resource "azurerm_virtual_machine" "example" {
name = "example-vm"
location = azurerm_resource_group.example.location
resource_group_name = azurerm_resource_group.example.name
network_interface_ids = [azurerm_network_interface.example.id]
storage_image_reference {
publisher = "OpenLogic"
offer = "CentOS"
sku = "7.6"
version = "latest"
}
storage_os_disk {
name = "example-os-disk"
caching = "ReadWrite"
create_option = "FromImage"
managed_disk_type = "Premium_LRS"
}
os_profile {
computer_name = "example-vm"
admin_username = "adminuser"
admin_password = "P@ssw0rd1234!"
}
os_profile_linux_config {
disable_password_authentication = false
}
boot_diagnostics {
storage_account_uri = "https://example.blob.core.windows.net/"
}
}
这个代码将创建以下资源:
- 一个Azure资源组
- 一个虚拟网络
- 一个子网
- 一个网络安全组
- 一个网络接口
- 一个虚拟机
注意:
- 代码中的版本号“1.36.0”是Terraform Azure提供程序版本的示例。如果您使用的是不同的版本,请替换代码中的版本号。
- 注意更改虚拟机的管理员用户名和密码。代码中的示例值“adminuser”和“P@ssw0rd1234!”不应用于生产环境。
原文地址: https://www.cveoy.top/t/topic/bh8c 著作权归作者所有。请勿转载和采集!