Skip to content

Error "the provider detected that no object exists with the given id" when attempting to import any existing resource #540

@manwithaplandy

Description

@manwithaplandy

I am attempting to use this tool to import existing resources into Terraform from an Azure environment, but no matter what I do I am getting the following error message:

While attempting to import an existing object to
"<resource>", the provider detected that no
object exists with the given id. Only pre-existing objects can be imported;
check that the id is correct and that it is associated with the provider's
configured region or endpoint, or use "terraform apply" to create a new
remote object for this resource.

I have tried the following command:
aztfexport res --use-azure-cli-cred --log-level TRACE --log-path log.txt --env usgovernment -s xxxxxxxxx /subscriptions/xxxxxxxxxxx/resourceGroups/xxxxxxxxx/providers/Microsoft.MachineLearningServices/workspaces/xxxxxxx
but it gives me the above error every time.

I have also tried using the rg import command:
aztfexport rg --log-level TRACE --log-path log.txt --env usgovernment xxxxxxxxxxxxx
and it gives me the above error for every single resource in the resource group, including the resource group itself.

I have used the az cli to list the resources successfully.

All of these resources have public access disabled and are accessible via private endpoint on a vnet. My machine is on a network that can reach resources in the vnet via privatelink.

Below is the (sanitized) log from using the first command:

2024-07-16T16:00:57.628-0700 [INFO] aztfexport: aztfexport starts with config: config.Config{CommonConfig:config.CommonConfig{SubscriptionId:"xxxxxxxxxx", AzureSDKCredential:(*azidentity.AzureCLICredential)(0xc006048080), AzureSDKClientOption:policy.ClientOptions{ClientOptions:policy.ClientOptions{APIVersion:"", Cloud:cloud.Configuration{ActiveDirectoryAuthorityHost:"https://login.microsoftonline.us/", Services:map[cloud.ServiceName]cloud.ServiceConfiguration{"resourceManager":cloud.ServiceConfiguration{Audience:"https://management.core.usgovcloudapi.net", Endpoint:"https://management.usgovcloudapi.net"}}}, Logging:policy.LogOptions{IncludeBody:true, AllowedHeaders:[]string(nil), AllowedQueryParams:[]string(nil)}, Retry:policy.RetryOptions{MaxRetries:0, TryTimeout:0, RetryDelay:0, MaxRetryDelay:0, StatusCodes:[]int(nil), ShouldRetry:(func(*http.Response, error) bool)(nil)}, Telemetry:policy.TelemetryOptions{ApplicationID:"aztfexport(azurerm)", Disabled:false}, TracingProvider:tracing.Provider{newTracerFn:(func(string, string) tracing.Tracer)(nil)}, Transport:exported.Transporter(nil), PerCallPolicies:[]exported.Policy(nil), PerRetryPolicies:[]exported.Policy(nil)}, AuxiliaryTenants:[]string(nil), DisableRPRegistration:false}, OutputDir:"/home/xxxxxxxxxx/Scripts/Synapse_tf_export", OutputFileNames:config.OutputFileNames{TerraformFileName:"", ProviderFileName:"", MainFileName:"", ImportBlockFileName:""}, ProviderVersion:"", DevProvider:false, ProviderName:"azurerm", ContinueOnError:false, BackendType:"local", BackendConfig:[]string(nil), ProviderConfig:map[string]cty.Value(nil), FullConfig:false, Parallelism:10, ModulePath:"", HCLOnly:false, TFClient:tfclient.Client(nil), TelemetryClient:telemetry.AppInsightClient{TelemetryClient:(*appinsights.telemetryClient)(0xc006043a40), subscriptionId:"xxxxxxxxxx", installId:"xxxxxxxxxx", sessionId:"xxxxxxxxxx"}, GenerateImportBlock:false}, ResourceId:"/subscriptions/xxxxxxxxxx/resourceGroups/xxxxxxxxxx/providers/Microsoft.MachineLearningServices/workspaces/xxxxxxxxxx", ResourceGroupName:"", ARGPredicate:"", MappingFile:"", ResourceNamePattern:"", RecursiveQuery:false, TFResourceName:"res-0", TFResourceType:"", IncludeRoleAssignment:false, IncludeResourceGroup:false}

2024-07-16T16:00:57.629-0700 [INFO] aztfexport: New resource meta
2024-07-16T16:00:57.631-0700 [DEBUG] aztfexport: UI update. STATUS: initializing | MSG: tea.WindowSizeMsg{Width:207, Height:39}
2024-07-16T16:00:57.631-0700 [DEBUG] aztfexport: UI update. STATUS: initializing | MSG: &meta.MetaResource{baseMeta:meta.baseMeta{subscriptionId:"xxxxxxxxxx", azureSDKCred:(*azidentity.AzureCLICredential)(0xc006048080), azureSDKClientOpt:policy.ClientOptions{ClientOptions:policy.ClientOptions{APIVersion:"", Cloud:cloud.Configuration{ActiveDirectoryAuthorityHost:"https://login.microsoftonline.us/", Services:map[cloud.ServiceName]cloud.ServiceConfiguration{"resourceManager":cloud.ServiceConfiguration{Audience:"https://management.core.usgovcloudapi.net", Endpoint:"https://management.usgovcloudapi.net"}}}, Logging:policy.LogOptions{IncludeBody:true, AllowedHeaders:[]string(nil), AllowedQueryParams:[]string(nil)}, Retry:policy.RetryOptions{MaxRetries:0, TryTimeout:0, RetryDelay:0, MaxRetryDelay:0, StatusCodes:[]int(nil), ShouldRetry:(func(*http.Response, error) bool)(nil)}, Telemetry:policy.TelemetryOptions{ApplicationID:"aztfexport(azurerm)", Disabled:false}, TracingProvider:tracing.Provider{newTracerFn:(func(string, string) tracing.Tracer)(nil)}, Transport:exported.Transporter(nil), PerCallPolicies:[]exported.Policy(nil), PerRetryPolicies:[]exported.Policy(nil)}, AuxiliaryTenants:[]string(nil), DisableRPRegistration:false}, outdir:"/home/xxxxxxxxxx/Scripts/Synapse_tf_export", outputFileNames:config.OutputFileNames{TerraformFileName:"terraform.tf", ProviderFileName:"provider.tf", MainFileName:"main.tf", ImportBlockFileName:"import.tf"}, tf:(*tfexec.Terraform)(nil), resourceClient:(*armresources.Client)(0xc00047e078), providerVersion:"3.99.0", devProvider:false, providerName:"azurerm", backendType:"local", backendConfig:[]string(nil), providerConfig:map[string]cty.Value(nil), fullConfig:false, parallelism:10, generateImportFile:false, hclOnly:false, tfclient:tfclient.Client(nil), moduleAddr:"", moduleDir:"/home/xxxxxxxxxx/Scripts/Synapse_tf_export", importBaseDirs:[]string(nil), importModuleDirs:[]string(nil), importTFs:[]*tfexec.Terraform(nil), originBaseState:[]uint8(nil), baseState:[]uint8(nil), tc:telemetry.AppInsightClient{TelemetryClient:(*appinsights.telemetryClient)(0xc006043a40), subscriptionId:"xxxxxxxxxx", installId:"xxxxxxxxxx", sessionId:"xxxxxxxxxx"}}, AzureId:(*armid.ScopedResourceId)(0xc001d00190), ResourceName:"res-0", ResourceType:""}
2024-07-16T16:00:57.635-0700 [INFO] aztfexport: Init Terraform
2024-07-16T16:00:57.812-0700 [INFO] aztfexport: Find terraform binary at /usr/bin/terraform
2024-07-16T16:00:57.812-0700 [INFO] aztfexport: Init provider
2024-07-16T16:00:57.812-0700 [INFO] aztfexport: Output directory doesn't contain provider setting, create one then
2024-07-16T16:00:57.813-0700 [INFO] aztfexport: Output directory doesn't contain terraform block, create one then
2024-07-16T16:00:57.813-0700 [DEBUG] aztfexport: Run "terraform init" for the output directory /home/xxxxxxxxxx/Scripts/Synapse_tf_export
2024-07-16T16:01:02.269-0700 [DEBUG] aztfexport: Run "terraform init" for the import directory /tmp/aztfexport-1144619604
2024-07-16T16:01:02.269-0700 [DEBUG] aztfexport: Run "terraform init" for the import directory /tmp/aztfexport-1811785705
2024-07-16T16:01:02.269-0700 [DEBUG] aztfexport: Run "terraform init" for the import directory /tmp/aztfexport-1404755313
2024-07-16T16:01:02.269-0700 [DEBUG] aztfexport: Run "terraform init" for the import directory /tmp/aztfexport-1906308737
2024-07-16T16:01:02.269-0700 [DEBUG] aztfexport: Run "terraform init" for the import directory /tmp/aztfexport-350614429
2024-07-16T16:01:02.269-0700 [DEBUG] aztfexport: Run "terraform init" for the import directory /tmp/aztfexport-1944491435
2024-07-16T16:01:02.269-0700 [DEBUG] aztfexport: Run "terraform init" for the import directory /tmp/aztfexport-3955052224
2024-07-16T16:01:02.270-0700 [DEBUG] aztfexport: Run "terraform init" for the import directory /tmp/aztfexport-9591396
2024-07-16T16:01:02.270-0700 [DEBUG] aztfexport: Run "terraform init" for the import directory /tmp/aztfexport-1121354430
2024-07-16T16:01:02.270-0700 [DEBUG] aztfexport: Run "terraform init" for the import directory /tmp/aztfexport-2830121908
2024-07-16T16:01:19.136-0700 [DEBUG] aztfexport: UI update. STATUS: initializing | MSG: aztfexportclient.InitProviderDoneMsg{}
2024-07-16T16:01:19.136-0700 [DEBUG] aztfexport: Azure Resource set map to TF resource set
2024-07-16T16:01:19.153-0700 [DEBUG] aztfexport: UI update. STATUS: listing Azure resources | MSG: aztfexportclient.ListResourceDoneMsg{List:meta.ImportList{meta.ImportItem{AzureResourceID:(*armid.ScopedResourceId)(0xc001d83db0), TFResourceId:"/subscriptions/xxxxxxxxxx/resourceGroups/xxxxxxxxxx/providers/Microsoft.MachineLearningServices/workspaces/xxxxxxxxxx", ImportError:error(nil), Imported:false, ValidateError:error(nil), TFAddr:tfaddr.TFAddr{Type:"azurerm_machine_learning_workspace", Name:"res-0"}, TFAddrCache:tfaddr.TFAddr{Type:"azurerm_machine_learning_workspace", Name:"res-0"}, IsRecommended:false, Recommendations:[]string(nil), State:cty.NilVal}}}
2024-07-16T16:01:19.155-0700 [DEBUG] aztfexport: UI update. STATUS: building import list | MSG: tea.WindowSizeMsg{Width:207, Height:39}
2024-07-16T16:01:57.491-0700 [DEBUG] aztfexport: UI update. STATUS: building import list | MSG: tea.KeyMsg{Type:-1, Runes:[]int32{119}, Alt:false}
2024-07-16T16:01:57.493-0700 [DEBUG] aztfexport: UI update. STATUS: building import list | MSG: aztfexportclient.StartImportMsg{List:meta.ImportList{meta.ImportItem{AzureResourceID:(*armid.ScopedResourceId)(0xc001d83db0), TFResourceId:"/subscriptions/xxxxxxxxxx/resourceGroups/xxxxxxxxxx/providers/Microsoft.MachineLearningServices/workspaces/xxxxxxxxxx", ImportError:error(nil), Imported:false, ValidateError:error(nil), TFAddr:tfaddr.TFAddr{Type:"azurerm_machine_learning_workspace", Name:"res-0"}, TFAddrCache:tfaddr.TFAddr{Type:"azurerm_machine_learning_workspace", Name:"res-0"}, IsRecommended:false, Recommendations:[]string(nil), State:cty.NilVal}}}
2024-07-16T16:01:57.493-0700 [DEBUG] aztfexport: UI update. STATUS: importing | MSG: tea.WindowSizeMsg{Width:207, Height:39}
2024-07-16T16:01:57.493-0700 [INFO] aztfexport: Importing /subscriptions/xxxxxxxxxx/resourceGroups/xxxxxxxxxx/providers/Microsoft.MachineLearningServices/workspaces/xxxxxxxxxx as azurerm_machine_learning_workspace.res-0
2024-07-16T16:02:01.566-0700 [ERROR] aztfexport: Importing azurerm_machine_learning_workspace.res-0: exit status 1

Error: Cannot import non-existent remote object

While attempting to import an existing object to
"azurerm_machine_learning_workspace.res-0", the provider detected that no
object exists with the given id. Only pre-existing objects can be imported;
check that the id is correct and that it is associated with the provider's
configured region or endpoint, or use "terraform apply" to create a new
remote object for this resource.
2024-07-16T16:02:01.567-0700 [DEBUG] aztfexport: UI update. STATUS: importing | MSG: aztfexportclient.ImportItemsDoneMsg{Items:[]meta.ImportItem{meta.ImportItem{AzureResourceID:(*armid.ScopedResourceId)(0xc001d83db0), TFResourceId:"/subscriptions/xxxxxxxxxx/resourceGroups/xxxxxxxxxx/providers/Microsoft.MachineLearningServices/workspaces/xxxxxxxxxx", ImportError:(*fmt.wrapError)(0xc001d04400), Imported:false, ValidateError:error(nil), TFAddr:tfaddr.TFAddr{Type:"azurerm_machine_learning_workspace", Name:"res-0"}, TFAddrCache:tfaddr.TFAddr{Type:"azurerm_machine_learning_workspace", Name:"res-0"}, IsRecommended:false, Recommendations:[]string(nil), State:cty.NilVal}}}
2024-07-16T16:02:01.567-0700 [DEBUG] aztfexport: UI update. STATUS: importing | MSG: aztfexportclient.ImportDoneMsg{List:meta.ImportList{meta.ImportItem{AzureResourceID:(*armid.ScopedResourceId)(0xc001d83db0), TFResourceId:"/subscriptions/xxxxxxxxxx/resourceGroups/xxxxxxxxxx/providers/Microsoft.MachineLearningServices/workspaces/xxxxxxxxxx", ImportError:(*fmt.wrapError)(0xc001d04400), Imported:false, ValidateError:error(nil), TFAddr:tfaddr.TFAddr{Type:"azurerm_machine_learning_workspace", Name:"res-0"}, TFAddrCache:tfaddr.TFAddr{Type:"azurerm_machine_learning_workspace", Name:"res-0"}, IsRecommended:false, Recommendations:[]string(nil), State:cty.NilVal}}}
2024-07-16T16:02:01.568-0700 [DEBUG] aztfexport: UI update. STATUS: building import list | MSG: tea.WindowSizeMsg{Width:207, Height:39}
2024-07-16T16:02:01.584-0700 [DEBUG] aztfexport: UI update. STATUS: building import list | MSG: progress.FrameMsg{id:1, tag:1}
2024-07-16T16:02:03.731-0700 [DEBUG] aztfexport: UI update. STATUS: building import list | MSG: tea.KeyMsg{Type:-1, Runes:[]int32{101}, Alt:false}
2024-07-16T16:02:03.732-0700 [DEBUG] aztfexport: UI update. STATUS: building import list | MSG: aztfexportclient.ShowImportErrorMsg{Item:meta.ImportItem{AzureResourceID:(*armid.ScopedResourceId)(0xc001d83db0), TFResourceId:"/subscriptions/xxxxxxxxxx/resourceGroups/xxxxxxxxxx/providers/Microsoft.MachineLearningServices/workspaces/xxxxxxxxxx", ImportError:(*fmt.wrapError)(0xc001d04400), Imported:false, ValidateError:error(nil), TFAddr:tfaddr.TFAddr{Type:"azurerm_machine_learning_workspace", Name:"res-0"}, TFAddrCache:tfaddr.TFAddr{Type:"azurerm_machine_learning_workspace", Name:"res-0"}, IsRecommended:false, Recommendations:[]string(nil), State:cty.NilVal}, Index:0, List:meta.ImportList{meta.ImportItem{AzureResourceID:(*armid.ScopedResourceId)(0xc001d83db0), TFResourceId:"/subscriptions/xxxxxxxxxx/resourceGroups/xxxxxxxxxx/providers/Microsoft.MachineLearningServices/workspaces/xxxxxxxxxx", ImportError:(*fmt.wrapError)(0xc001d04400), Imported:false, ValidateError:error(nil), TFAddr:tfaddr.TFAddr{Type:"azurerm_machine_learning_workspace", Name:"res-0"}, TFAddrCache:tfaddr.TFAddr{Type:"azurerm_machine_learning_workspace", Name:"res-0"}, IsRecommended:false, Recommendations:[]string(nil), State:cty.NilVal}}}
2024-07-16T16:02:04.419-0700 [DEBUG] aztfexport: UI update. STATUS: import error message | MSG: tea.KeyMsg{Type:-1, Runes:[]int32{113}, Alt:false}
2024-07-16T16:02:04.420-0700 [DEBUG] aztfexport: UI update. STATUS: building import list | MSG: tea.WindowSizeMsg{Width:207, Height:39}
2024-07-16T16:02:06.661-0700 [DEBUG] aztfexport: UI update. STATUS: building import list | MSG: tea.KeyMsg{Type:-1, Runes:[]int32{101}, Alt:false}
2024-07-16T16:02:06.662-0700 [DEBUG] aztfexport: UI update. STATUS: building import list | MSG: aztfexportclient.ShowImportErrorMsg{Item:meta.ImportItem{AzureResourceID:(*armid.ScopedResourceId)(0xc001d83db0), TFResourceId:"/subscriptions/xxxxxxxxxx/resourceGroups/xxxxxxxxxx/providers/Microsoft.MachineLearningServices/workspaces/xxxxxxxxxx", ImportError:(*fmt.wrapError)(0xc001d04400), Imported:false, ValidateError:error(nil), TFAddr:tfaddr.TFAddr{Type:"azurerm_machine_learning_workspace", Name:"res-0"}, TFAddrCache:tfaddr.TFAddr{Type:"azurerm_machine_learning_workspace", Name:"res-0"}, IsRecommended:false, Recommendations:[]string(nil), State:cty.NilVal}, Index:0, List:meta.ImportList{meta.ImportItem{AzureResourceID:(*armid.ScopedResourceId)(0xc001d83db0), TFResourceId:"/subscriptions/xxxxxxxxxx/resourceGroups/xxxxxxxxxx/providers/Microsoft.MachineLearningServices/workspaces/xxxxxxxxxx", ImportError:(*fmt.wrapError)(0xc001d04400), Imported:false, ValidateError:error(nil), TFAddr:tfaddr.TFAddr{Type:"azurerm_machine_learning_workspace", Name:"res-0"}, TFAddrCache:tfaddr.TFAddr{Type:"azurerm_machine_learning_workspace", Name:"res-0"}, IsRecommended:false, Recommendations:[]string(nil), State:cty.NilVal}}}
2024-07-16T16:02:06.883-0700 [DEBUG] aztfexport: UI update. STATUS: import error message | MSG: tea.KeyMsg{Type:-1, Runes:[]int32{113}, Alt:false}
2024-07-16T16:02:06.884-0700 [DEBUG] aztfexport: UI update. STATUS: building import list | MSG: tea.WindowSizeMsg{Width:207, Height:39}
2024-07-16T16:02:08.310-0700 [DEBUG] aztfexport: UI update. STATUS: building import list | MSG: tea.KeyMsg{Type:-1, Runes:[]int32{113}, Alt:false}
2024-07-16T16:02:08.333-0700 [DEBUG] aztfexport: UI update. STATUS: building import list | MSG: aztfexportclient.QuitMsg{}
2024-07-16T16:02:08.334-0700 [INFO] aztfexport: aztfexport ends

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions