Using Azure openAI key rotation automation

题意:使用 Azure OpenAI 密钥轮换自动化

问题背景:

We are planning to do the Azure OpenAI key rotation automatically. How can we achieve this? Do we have terraform resource for this.

我们计划自动执行 Azure OpenAI 密钥轮换。我们如何实现这一点?是否有相应的 Terraform 资源可用?

python 复制代码
resource "azurerm_cognitive_account" "example" {
  name                = "xxxxx"
  location            = azurerm_resource_group.example.location
  resource_group_name = azurerm_resource_group.example.name
  kind                = "OpenAI"

  sku_name = "S0"
}

问题解决:

Firstly, there is no direct resource present for the Open AI key rotation in terraform. Following a workaround on the requirement, I found below approach to make it work.

首先,Terraform 中没有直接用于 OpenAI 密钥轮换的资源。针对这一需求,我找到了一种可行的替代方法,具体如下。

As I mentioned in the comments, use azurerm_cognitive_account resource from terraform by providing kind as an "OpenAI" as shown.

正如我在评论中提到的,可以使用 Terraform 中的 azurerm_cognitive_account 资源,并将 kind 设置为 OpenAI,如图所示。

I tried creating a new open AI account with the below code and the deployment was successful.

我尝试使用以下代码创建一个新的 OpenAI 帐户,部署成功。

python 复制代码
provider  "azurerm"{
  features{}
}
data  "azurerm_resource_group"  "example"  {
    name = "DefaultResourceGroup-EUS"
}
resource  "azurerm_cognitive_account"  "example"  {
    name = "examplesample"
    location = data.azurerm_resource_group.example.location
    resource_group_name = data.azurerm_resource_group.example.name
    kind = "OpenAI"
sku_name = "S0"
}
}

Once it is done, you need to retrieve the keys from the external path. To do that, use data "external" block.

完成后,你需要从外部路径检索密钥。为此,可以使用 data "external" 块。

How to use it: Reference

Sample data block shown below:

示例数据块如下所示:

python 复制代码
data "external" "keys" {
  program = ["sh", "/path/retrieve_sshkey.sh"]
}

Now refer this in the main.tf terraform resource with null_resource block by passing the open ai resource id under triggers block and add a provisioner as well.

现在,在 main.tf Terraform 资源中,通过在 null_resource 块的 triggers 块中传递 OpenAI 资源 ID,并添加一个 provisioner

python 复制代码
resource "null_resource" "samplerotation" {
  triggers = {
    open_ai_resource_id = azurerm_cognitive_account.example.id
    }
provisioner "remote-exec" {
 //write a powershell script here and refer the above keys data block here
 }
}

Alternatively, you can also follow an other approach with the help of key vault. Store all the keys in the key vault and apply the key rotation from there itself.

另外,你也可以使用密钥保管库(Key Vault)采取另一种方法。将所有密钥存储在密钥保管库中,并从那里执行密钥轮换。

To do so, refer the terraform code from SO & for CLI approach refer Github doc.

为此,可以参考来自 Stack Overflow 的 Terraform 代码,并且对于 CLI 方法,可以参考 GitHub 文档。

相关推荐
菜菜艾6 小时前
基于llama.cpp部署私有大模型
linux·运维·服务器·人工智能·ai·云计算·ai编程
chushiyunen8 小时前
人工智能会话管理
ai
阿杰学AI10 小时前
AI核心知识115—大语言模型之 自监督学习(简洁且通俗易懂版)
人工智能·学习·ai·语言模型·aigc·监督学习·自监督学习
艾为电子11 小时前
【应用方案】会议&面试记录终结者-艾为AI智能录音卡方案,清晰拾音,解放双手
人工智能·ai
哥布林学者12 小时前
深度学习进阶(七)Data-efficient Image Transformer
机器学习·ai
数据知道13 小时前
《 Claude Code源码分析与实践》专栏目录
python·ai·github·claude code·claw code
程序员鱼皮13 小时前
SBTI 爆火后,我做了个程序员版的 CBTI。。已开源 + 附开发过程
ai·程序员·开源·编程·ai编程
九卷14 小时前
100多行代码实现一个最简单的Agent(用ReAct)
ai·agent·智能体
gao_tjie14 小时前
Veo MCP 集成指南
ai
萧逸才14 小时前
【learn-claude-code-4j】S14FeiShu - 飞书群聊智能体
java·人工智能·ai·飞书