gpt4 book ai didi

postgresql - 尝试在 Azure 云提供商上创建专用链接时出现问题

转载 作者:行者123 更新时间:2023-12-02 22:53:23 39 4
gpt4 key购买 nike

我正在尝试开发 terraform 脚本,该脚本在 Azure 上创建虚拟机并使用专用链接将其连接到 Azure Postgresql 实例。我总是收到此错误:

Error: creating Private Endpoint "n4gx6y-endpoint" (Resource Group "PGSQLResourceGroup"): 
network.PrivateEndpointsClient#CreateOrUpdate:
Failure sending request: StatusCode=400 -- Original Error:
Code="IncorrectPrivateLinkServiceConnectionGroupId"
Message="Call to Microsoft.DBforPostgreSQL/servers failed.
Error message: Private Link Service Connection Group Id is
incorrect for Azure Database for PostgreSQL" Details=[]

on main.tf line 68, in resource "azurerm_private_endpoint" "example":
68: resource "azurerm_private_endpoint" "example" {

这是脚本:

# -*- mode: hcl; coding: utf-8; -*-
# vim: set syntax=hcl fileencoding=utf-8

terraform {
required_version = ">= 0.12, < 0.13"
}

provider "azurerm" {
version = ">=2.20"
subscription_id = var.subscription_id
client_id = var.client_id
client_certificate_path = var.client_certificate_path
tenant_id = var.tenant_id
features {}
}

provider "random" {
version = "~> 2.3"
}

resource "random_string" "random" {
length = 6
special = false
upper = false
}

resource "azurerm_resource_group" "grp" {
name = "PGSQLResourceGroup"
location = var.location

tags = {
environment = "Terraform Demo"
}
}

resource "azurerm_virtual_network" "example" {
name = "${random_string.random.result}-network"
address_space = ["10.0.0.0/16"]
location = azurerm_resource_group.grp.location
resource_group_name = azurerm_resource_group.grp.name
}

resource "azurerm_subnet" "example" {
name = "${random_string.random.result}-subnet"
resource_group_name = azurerm_resource_group.grp.name
virtual_network_name = azurerm_virtual_network.example.name
address_prefixes = ["10.0.1.0/24"]
enforce_private_link_endpoint_network_policies = true
}

resource "azurerm_postgresql_server" "example" {
name = "${random_string.random.result}-pg"
location = azurerm_resource_group.grp.location
resource_group_name = azurerm_resource_group.grp.name

sku_name = "GP_Gen5_2"

backup_retention_days = 7
geo_redundant_backup_enabled = false
storage_mb = 51200
auto_grow_enabled = true
administrator_login = "mysqladmin"
administrator_login_password = "H@Sh1CoR3!"
version = "11"
ssl_enforcement_enabled = true
}

resource "azurerm_private_endpoint" "example" {
name = "${random_string.random.result}-endpoint"
location = azurerm_resource_group.grp.location
resource_group_name = azurerm_resource_group.grp.name
subnet_id = azurerm_subnet.example.id

private_service_connection {
name = "${random_string.random.result}-privateserviceconnection"
private_connection_resource_id = azurerm_postgresql_server.example.id
subresource_names = ["postgresServer"]
is_manual_connection = false
}
}

这是 github 存储库,其中一个用于 Postgres,一个用于 Mariadb。该错误仅在 Postgres 中出现。

https://github.com/kiklop74/terraform-private-link-issue

最佳答案

问题实际上与这部分脚本有关:

  private_service_connection {
name = "${random_string.random.result}-privateserviceconnection"
private_connection_resource_id = azurerm_postgresql_server.example.id
subresource_names = ["postgresServer"] # <-- HERE!
is_manual_connection = false
}

事实证明,专用链接的每个受支持的 Azure 托管服务都有硬编码的子资源名称。对于 MariaDB 实例,它是 mariadbServer;对于 Postgres,它是 postgresqlServer。我错误地将 postgresServer 放置在那里,认为它只是任意值。

关于postgresql - 尝试在 Azure 云提供商上创建专用链接时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63419749/

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