我一直在尝试创建 Azure IoT 中心设备配置服务以及使用 X509 证书的注册组。
据我所知,无法使用 azurerm
提供程序来做到这一点。我还尝试探索 azapi
选项,但似乎 type = "Microsoft.Devices/provisioningServices@2022-12-12"
也无法提供自动注册组创建?
我可以使用其他提供商吗?
最佳答案
最终,我最终使用 local_file
创建临时证书文件,然后使用 null_resource
运行 Azure CLI 命令,我的解决方案:
locals {
iot_hub_name = join("-", [var.project_name, "iothub", var.environment_name])
dps_name = join("-", [var.project_name, "dps", var.environment_name])
cert_path = "intermediate"
}
data "azurerm_client_config" "current" {}
resource "azurerm_iothub" "azure_iot_hub" {
...
}
resource "azurerm_iothub_dps" "azure_iot_hub_dps" {
...
}
resource "local_file" "create_cert_file" {
content = var.iot_dps_intermediate_cert
filename = local.cert_path
}
resource "null_resource" "create-dps-certificate-enrollement" {
provisioner "local-exec" {
interpreter = ["/bin/bash", "-c"]
command = <<-EOT
az login --service-principal -u $CLIENT_ID -p $CLIENT_SECRET --tenant $TENANT_ID
az extension add --name azure-iot
az iot dps enrollment-group create --cp $CERT_PATH -g $RESOURCE_GROUP --dps-name $DPS_NAME --enrollment-id $ENROLLMENT_ID
EOT
environment = {
CLIENT_ID = data.azurerm_client_config.current.client_id
TENANT_ID = data.azurerm_client_config.current.tenant_id
CLIENT_SECRET = var.client_secret
RESOURCE_GROUP = var.resource_group_name
DPS_NAME = local.dps_name
ENROLLMENT_ID = "${local.dps_name}-enrollement-group"
CERT_PATH = local.cert_path
}
}
depends_on = [local_file.create_cert_file]
}
其中 var.iot_dps_intermediate_cert
表示用于创建新注册组的 .pem
文件的内容
关于azure - Terraform 创建 Azure IoT 设备配置服务注册组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/75335658/