Error: A resource with the ID "/subscriptions/0386xx61-41b1-xxx-9658-8cxxxx6c0829/resourceGroups/rg-identity-prd-cus-001/providers/Microsoft.Compute/diskEncryptionSets/des-prd-cus-001" already exists - to be managed via Terraform this resource needs to be imported into the State. Please see the resource documentation for "azurerm_disk_encryption_set" for more information.
│
│ with module.identity_subscription[0].azurerm_disk_encryption_set.de_identity["key1"],
│ on subscriptions/identity/identity.tf line 578, in resource "azurerm_disk_encryption_set" "de_identity":
│ 578: resource "azurerm_disk_encryption_set" "de_identity" {
我已经在Identity.tf文件中创建了一个Azure磁盘加密集资源,其中以下代码:
resource "azurerm_disk_encryption_set" "de_identity" {
for_each = local.kv_keys
name = format("des-%s-%s-%s", var.environment,var.location_short_name,var.instance_number)
resource_group_name = module.resource_group.rg_name_subs
location = var.location
key_vault_key_id = azurerm_key_vault_key.kv_key[each.key].id
identity {
type = "SystemAssigned"
}
}
现在我在下面运行此命令,它正在投掷错误:
terraform import --var-file=centralus.tfvars module.identity_subscription[0].azurerm_disk_encryption_set.de_identity "/subscriptions/xxxx61-41xx-451x-xxxx-8c25546c0829/resourceGroups/rg-identity-prd-cus-001/providers/Microsoft.Compute/diskEncryptionSets/des-prd-cus-001"
Error: Configuration for import target does not exist
│
│ The configuration for the given import module.identity_subscription[0].azurerm_disk_encryption_set.de_identity does not exist. All target instances
│ must have an associated configuration to be imported.
我的文件夹的结构显示在屏幕截图中
试图执行Azure磁盘加密设置的TerraForm导入terraform时的错误
每当您使用插件内的for_each配置时,我们应该始终需要提供文字报价llets以这种格式说
terraform import --var-file=centralus.tfvars 'module.identity_subscription[0].azurerm_disk_encryption_set.de_identity["key2"]' /subscriptions/038xxxx-4xx1-4xx-9658-8c25546c0829/resourceGroups/rg-identity-prd-cus-001/providers/Microsoft.Compute/diskEncryptionSets/des-prd-cus-001
使用逃脱的引号[“ key2”]是正确的,在这里需要。
二件事根据错误串扰在C:/Users/
...之前的侵入。这指出外壳将第二个参数误解为
subscriptions/..
而不是
path
以确保您以这种方式的键报价“ key2”或'key2'
确保您在TFVAR中具有有效的密钥输入。
参考:
https://developer.hashicorp.com/terraform/language/import#import-multiple-instances-with-for_each https://github.com/hashicorp/terraform/issues/33114