Terraform OpenAI 和 VNET/子网中的依赖关系

问题描述 投票:0回答:1

我正在尝试使用 terraform 中的 openai 模块创建一个 openai 端点。我创建网络然后单独打开没有问题。但是,当我尝试在一个管道下添加所有内容时,它会查找 vnet 和子网,就好像它们已经创建一样,而不是先创建它们。

(我更改了专有名称以“测试”隐私)

我的目录结构如下:

terraform
  /modules
    /openai/
      main.tf
      variables.tf
      outputs.tf
    network/
      main.tf
      variables.tf
      outputs.tf
  main.tf
  variables.tf

在我的网络文件中,我正在为 vnet 和子网名称创建输出:

output "subnet_name" {
  description = "The name of the subnet."
  value       = azurerm_subnet.test_subnet.name
}

output "vnet_name" {
  description = "The name of the virtual network."
  value       = azurerm_virtual_network.test_vnet.name
}

在根 main.tf 中:

provider "azurerm" {
  features {}
}



# Network Module
module "network" {
  source                = "./modules/network"
  vnet_name             = "test_vnet"
  address_space         = ["10.0.0.0/16"]
  location              = "US East"
  resource_group_name   = "TestRG"
  subnet_name           =  "test_subnet"
  subnet_prefixes       = ["10.0.1.0/24"]
}

module "openai" {
  source                = "./modules/openai"
  resource_group_name   = "TestRG"
  location              = "US East"
  openai_name           = "test_openai"
  vnet_name             = module.network.vnet_name
  subnet_name           = module.network.subnet_name
} 

openai 模块 main.tf:

provider "azurerm" {
  features {}
}

module "openai" {
  source              = "Azure/openai/azurerm"
  resource_group_name = var.resource_group_name
  location            = var.location
  private_endpoint = {
    "pe_endpoint" = {
      private_dns_entry_enabled       = true
      dns_zone_virtual_network_link   = "dns_zone_link"
      is_manual_connection            = false
      name                            = var.private_endpoint_name
      private_service_connection_name = var.private_service_connection_name 
      subnet_name                     = var.subnet_name
      vnet_name                       = var.vnet_name
      vnet_rg_name                    = var.resource_group_name
    }
  }
  deployment = {
    "text-embedding-ada-002" = {
      name          = "text-embedding-ada-002"
      model_format  = "OpenAI"
      model_name    = "text-embedding-ada-002"
      model_version = "2"
      scale_type    = "Standard"
    }
  }

}

考虑到我正在从网络模块获取变量,它不应该首先创建网络组件吗?我知道我可以在 openai 文件夹中添加一个 vnet 模块,我只是更喜欢将它们分开,并且无法理解为什么上面不起作用。欢迎任何想法!我不是地形专家:)

谢谢你

尝试运行 terraform plan 来解决上述错误,即创建 openai pe_endpoint 时 vnet 和子网不存在。

azure terraform devops infrastructure-as-code azure-openai
1个回答
0
投票

OpenAI 然后网络只能使用 terraform 单独创建。

问题似乎在于您将 Vnet 引入 OpenAI 的方式,因为在并行操作期间,所有资源同时配置。

因此,为了解决这个问题,我们需要进行更改,以便通过使用 dependent_on 将 Vnet 的输出分配给 OpenAI。

配置:

main.tf:

provider "azurerm" {
  features {}
}

module "network" {
  source                = "./modules/network"
  vnet_name             = "test_vnet"
  address_space         = ["10.0.0.0/16"]
  location              = "East US"
  resource_group_name   = "vinay-rg"
  subnet_name           = "test_subnet"
  subnet_prefixes       = ["10.0.1.0/24"]
}

module "openai" {
  source                = "./modules/openai"
  resource_group_name   = "vinay-rg"
  location              = "East US"
  vnet_name             = module.network.vnet_name
  subnet_name           = module.network.subnet_name
  private_endpoint_name = "test_pe_endpoint"
  private_service_connection_name = "test_service_connection"
}

模块/network.tf:

variable "vnet_name" {
  description = "Name of the Virtual Network"
  type        = string
}

variable "address_space" {
  description = "Address space for the Virtual Network"
  type        = list(string)
}

variable "location" {}

variable "resource_group_name" {}

variable "subnet_name" {}

variable "subnet_prefixes" {}

resource "azurerm_virtual_network" "test_vnet" {
  name                = var.vnet_name
  address_space       = var.address_space
  location            = var.location
  resource_group_name = var.resource_group_name
}

resource "azurerm_subnet" "test_subnet" {
  name                 = var.subnet_name
  resource_group_name  = var.resource_group_name
  virtual_network_name = azurerm_virtual_network.test_vnet.name
  address_prefixes     = var.subnet_prefixes
}

output "subnet_name" {
  value = azurerm_subnet.test_subnet.name
}

output "vnet_name" {
  value = azurerm_virtual_network.test_vnet.name
}

模块/openai.tf:

provider "azurerm" {
  features {}
}

module "openai" {
  source              = "Azure/openai/azurerm"
  resource_group_name = var.resource_group_name
  location            = var.location

  private_endpoint = {
    "pe_endpoint" = {
      private_dns_entry_enabled       = true
      dns_zone_virtual_network_link   = "dns_zone_link"
      is_manual_connection            = false
      name                            = var.private_endpoint_name
      private_service_connection_name = var.private_service_connection_name 
      subnet_name                     = var.subnet_name
      vnet_name                       = var.vnet_name
      vnet_rg_name                    = var.resource_group_name
    }
  }

  deployment = {
    "text-embedding-ada-002" = {
      name          = "text-embedding-ada-002"
      model_format  = "OpenAI"
      model_name    = "text-embedding-ada-002"
      model_version = "2"
      scale_type    = "Standard"
    }
  }

  depends_on = [ var.vnet_name, var.subnet_name ]
}

variable "subnet_name" {}
variable "vnet_name" {}
variable "resource_group_name" {}
variable "location" {}
variable "private_endpoint_name" {}
variable "private_service_connection_name" {}

部署:

enter image description here

enter image description here 参考:

https://github.com/Azure/terraform-azurerm-openai/tree/v0.1.3/examples/azureopenai-private-endpoints

https://msandbu.org/deploy-azure-openai-using-terraform-with-private-endpoint/

https://techcommunity.microsoft.com/t5/azure-architecture-blog/azure-openai-private-endpoints-connecting-across-vnet-s/ba-p/3913325

depend_on 元参数 - 配置语言 |地形 | HashiCorp 开发商

© www.soinside.com 2019 - 2024. All rights reserved.