gpt4 book ai didi

azure - 获取 azurerm_linux_virtual_machine_scale_set 的 IP 地址作为输出

转载 作者:行者123 更新时间:2023-12-03 04:40:24 25 4
gpt4 key购买 nike

我能否以某种方式获取 azurerm_linux_virtual_machine_scale_set 所创建虚拟机的内部 IP 地址使用固定数量的实例作为输出变量?

我浏览了文档,但没有找到任何与创建的虚拟机相关的导出。

最佳答案

我尝试在我的环境中创建已创建虚拟机的内部 IP 地址,并得到以下结果

The below script I have taken from this terraform URL and modified as per the requirement

locals {
first_public_key = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC+wWK73dCr+jgQOAxNsHAnNNNMEMWOHYEccp6wJm2gotpr9katuF/ZAdou5AaW1C61slRkHRkpRRX9FA9CYBiitZgvCCz+3nWNN7l/Up54Zps/pHWGZLHNJZRYyAB6j5yVLMVHIHriY49d/GZTZVNB8GoJv9Gakwc/fuEZYYl4YDFiGMBP///TzlI4jhiJzjKnEvqPFki5p2ZRJqcbCiF4pJrxUQR/RXqVFQdbRLZgYfJ8xGB878RENq3yQ39d8dVOkq4edbkzwcUmwwwkYVPIoDGsYLaRHnG+To7FvMeyO7xDVQkMKzopTQV8AuKpyvpqu0a9pWOMaiCyDytO7GGN <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="add4c2d8edc0c883cec2c0" rel="noreferrer noopener nofollow">[email protected]</a>"
}

provider "azurerm" {
features {}
}

resource "azurerm_resource_group" "example" {
name = "example-resourcesabc"
location = "West Europe"
}

resource "azurerm_virtual_network" "example" {
name = "example-networkabc"
resource_group_name = azurerm_resource_group.example.name
location = azurerm_resource_group.example.location
address_space = ["10.0.0.0/16"]
}

resource "azurerm_subnet" "internal" {
name = "internal"
resource_group_name = azurerm_resource_group.example.name
virtual_network_name = azurerm_virtual_network.example.name
address_prefixes = ["10.0.2.0/24"]
}

resource "azurerm_linux_virtual_machine_scale_set" "example" {
name = "vmssabc"
resource_group_name = azurerm_resource_group.example.name
location = azurerm_resource_group.example.location
sku = "Standard_F2"
instances = 3
admin_username = "adminuser"

admin_ssh_key {
username = "adminuser"
public_key = local.first_public_key
}

source_image_reference {
publisher = "Canonical"
offer = "UbuntuServer"
sku = "16.04-LTS"
version = "latest"
}

os_disk {
storage_account_type = "Standard_LRS"
caching = "ReadWrite"
}

network_interface {
name = "example"
primary = true

ip_configuration {
name = "internal"
primary = true
subnet_id = azurerm_subnet.internal.id
}
}
}

Run the following script

terraform init

enter image description here

terraform plan

enter image description here

terraform apply

enter image description here

当我打开并检查虚拟机规模集时,我能够看到创建的 3 个实例

enter image description here

我打开了 Vm 实例,我能够看到 terraform 创建的私有(private) IP 地址

enter image description here

关于azure - 获取 azurerm_linux_virtual_machine_scale_set 的 IP 地址作为输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/74558264/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com