我试图在运行terraform apply
时将多个文件名传递到我的地形脚本中,但我一直面临同样的错误。请继续阅读以更好地理解它。我只添加了相关的代码:
在我的Terraform项目中有一个名为keys
的文件夹。在文件夹中我有以下文件:
samantha.cer
john.cer
Inkeys.tfvars
:
path_to_keys = "./keys/*.cer"
Invariables.tf
:
variable "path_to_keys" {
type = string
}
variable "key_names" {
type = string
default = "./keys/"
}
Inmain.tf
resource "azurerm_virtual_network_gateway" "gw" {
name = "team-${terraform.workspace}"
location = azurerm_resource_group.rg.location
resource_group_name = azurerm_resource_group.rg.name
type = "Vpn"
vpn_type = "RouteBased"
active_active = false
enable_bgp = false
sku = "VpnGw1"
ip_configuration {
name = "config"
public_ip_address_id = azurerm_public_ip.ip.id
private_ip_address_allocation = "Dynamic"
subnet_id = azurerm_subnet.subnet.id
}
vpn_client_configuration {
vpn_client_protocols = ["IkeV2","SSTP"]
address_space = [var.vpn_client_address_space]
root_certificate {
name = "${var.key_names}Root-Cert"
public_cert_data = var.path_to_keys
}
}
我在这里要做的是在Root-Cert
之前放置每个密钥文件名,以便更容易发现谁有访问权限,因为我将在未来添加更多的密钥文件。
但是当我做terraform apply
时,我收到的错误是:
Error: Creating/Updating Virtual Network Gateway: (Name "team-gwt" / Resource Group "team-gwt-infra-rg"): network.VirtualNetworkGatewaysClient#CreateOrUpdate: Failure sending request: StatusCode=400 -- Original Error: Code="VpnClientRootCertificateDataInvalid" Message="Data for certificate /subscriptions/subscription-details-retracted-for-security/resourceGroups/team-gwt-infra-rg/providers/Microsoft.Network/virtualNetworkGateways/team-gwt/vpnClientRootCertificates/Root-Cert is invalid." Details=[]
解决这个问题的未来解决方案是什么?
您的"./keys/"
默认值不正确。这是你想用的错误的名字。名称只能是:
Resource name ./keys/Root-Cert is invalid.
The name can be up to 80 characters long.
It must begin with a word character,
and it must end with
a word character or with '_'. The name may
contain word characters or '.', '-', '_'."
因此,您可以尝试使用:
variable "key_names" {
type = string
default = "keys"
}