You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Terraform导入Azure Disk Encryption Set时遇配置不存在错误

Terraform导入Azure Disk Encryption Set报“导入目标配置不存在”的解决方法

问题根源

你用for_each遍历local.kv_keys定义Azure Disk Encryption Set资源,Terraform对for_each生成的资源采用键值寻址,而非列表索引([0]这种格式)。你当前导入命令里用的module.identity_subscription[0].azurerm_disk_encryption_set.de_identity是列表索引式地址,和实际基于for_each的配置不匹配,导致报错。

解决步骤

  1. 确认for_each的键值
    查看identity.tf中local.kv_keys的定义,确定对应要导入的Disk Encryption Set的键名(比如如果local.kv_keys是一个map,键可能是资源名称des-prd-cus-001或自定义标识)。

  2. 修正导入命令的资源地址
    将导入命令中的索引[0]替换为for_each的键值,格式为["键名"]。示例命令如下:

    terraform import --var-file=centralus.tfvars module.identity_subscription["des-prd-cus-001"].azurerm_disk_encryption_set.de_identity "/subscriptions/0386xx61-41b1-xxx-9658-8cxxxx6c0829/resourceGroups/rg-identity-prd-cus-001/providers/Microsoft.Compute/diskEncryptionSets/des-prd-cus-001"
    

    注意:把["des-prd-cus-001"]替换为你实际local.kv_keys中的对应键值。

  3. 验证导入结果
    导入完成后执行terraform plan,确认Terraform State与实际资源配置一致,无漂移报错。

额外提示

  • 如果不确定for_each的键值,可以执行terraform plan(即使会报资源已存在的错误,输出中会显示预期的资源地址格式)。
  • 确保local.kv_keys中的键值与要导入的资源属性完全匹配,否则仍会出现地址不匹配的问题。

内容的提问来源于stack exchange,提问作者Pallab

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.14 20:45:58