我收到以下错误:
Error: Unsupported block type
front.tf line 164, in resource "azurerm_virtual_machine" "FrontEndVirtualMachines":
164: admin_ssh_key {
Blocks of type "admin_ssh_key" are not expected here.
我正在关注这个例子:
我在文档中注意到的一件事,“创建虚拟机”部分使用:
output "tls_private_key" {
value = "tls_private_key.Ssh.private_key_pem"
}
而“完整的 Terraform 脚本”部分使用带有花括号的 $:
output "tls_private_key" {
value = "${tls_private_key.Ssh.private_key_pem}"
}
我已经尝试了两种方法并遇到了同样的问题。
这是我的代码:
#Create (and display) an SSH key
resource "tls_private_key" "Ssh" {
algorithm = "RSA"
rsa_bits = 4096
}
output "tls_private_key" { value = "${tls_private_key.Ssh.private_key_pem}" }
#Create 2 front end web servers VMs
resource "azurerm_virtual_machine" "FrontEndVirtualMachines" {
count = 2
name = "vmFront${count.index}"
location = azurerm_resource_group.PWSDevResourceGroup.location
availability_set_id = azurerm_availability_set.AvailibilitySet.id
resource_group_name = azurerm_resource_group.PWSDevResourceGroup.name
network_interface_ids = [element(azurerm_network_interface.FrontNetworkInterface.*.id, count.index)]
vm_size = "A4_V2"
# Uncomment this line to delete the OS disk automatically when deleting the VM
# delete_os_disk_on_termination = true
# Uncomment this line to delete the data disks automatically when deleting the VM
# delete_data_disks_on_termination = true
#Define OS Image
storage_image_reference {
publisher = "MicrosoftWindowsServer"
offer = "WindowsServer"
sku = "2016-Datacenter"
version = "latest"
}
#Define OS Disk
storage_os_disk {
name = "FrontOSDisk"
caching = "ReadWrite"
create_option = "FromImage"
managed_disk_type = "Standard_LRS"
}
#Define Secondary Storage Disk
storage_data_disk {
name = "FrontDataDisk"
create_option = "Empty"
lun = 1
disk_size_gb = "64"
managed_disk_type = "Standard_LRS"
}
#Define Admin Profile
os_profile {
computer_name = "Front"
admin_username = "#######"
admin_password = "#######"
}
admin_ssh_key {
username = "azureuser"
public_key = tls_private_key.Ssh.public_key_openssh
}
boot_diagnostics {
enabled = true
storage_uri = azurerm_storage_account.PWSDevStorageAcct.primary_blob_endpoint
}
tags = {
environment = "Front-End"
}
}