[Bug] Invalid Resource ID Error: ‘id should start with /’ in aztfexport
🐛 Bug Description
I encountered an error when trying to export an Azure Database for PostgreSQL flexible server using aztfexport. The tool returns: Error: invalid resource id: id should start with “/”
This happens even though the resource ID is correctly formatted and follows the expected pattern.
🔄 To Reproduce
Steps to reproduce the behavior:
- Run the following command:
aztfexport resource --hcl-only "/subscriptions/<sub_id>/resourceGroups/<rg_name>/providers/Microsoft.DBforPostgreSQL/flexibleServers/<pg_server_name>" - The error appears:
2025/03/20 22:11:40 invalid resource id: id should start with "/"
✅ Expected Behavior
The tool should correctly parse the resource ID and proceed with exporting it to Terraform HCL.
🖥️ Environment • OS: Windows (Git Bash) • aztfexport Version: v0.16.0(ec548e4) • Terraform Version: v1.11.2 • Shell: Git Bash
📌 Additional Context • I verified that the resource ID follows the correct Azure format. • aztft might be involved in validating the resource type, but it’s unclear if it’s treating PostgreSQL flexible servers differently. • Similar issues were reported before regarding PostgreSQL flexible servers (#353).
@IstvanCsVarga I've tried to create a PostgreSQL flexible server and use the tool to export it, which is successful:
/tmp/aztfy1
💤 aztfexport resource -n --hcl-only --plain-ui /subscriptions/xxxx/resourceGroups/acctestRG-postgresql-322/providers/Microsoft.DBforPostgreSQL/flexibleServers/acctest-fs-322
[aztfexport] 2025/03/21 10:24:39 Initializing...
[aztfexport] 2025/03/21 10:24:40 Listing resources...
[aztfexport] 2025/03/21 10:24:40 Exporting Skipped Resource file...
[aztfexport] 2025/03/21 10:24:40 Exporting Resource Mapping file...
[aztfexport] 2025/03/21 10:24:40 Importing resources...
(1/1) Importing /subscriptions/xxxx/resourceGroups/acctestRG-postgresql-322/providers/Microsoft.DBforPostgreSQL/flexibleServers/acctest-fs-322 as azurerm_postgresql_flexible_server.res-0
[aztfexport] 2025/03/21 10:24:43 Generating Terraform configurations...
[aztfexport] 2025/03/21 10:24:44 Cleaning up...
[aztfexport] 2025/03/21 10:24:44 DeInitializing...
/tmp/aztfy1 via 💠 default took 5s
💤 cat main.tf
resource "azurerm_postgresql_flexible_server" "res-0" {
location = "westus2"
name = "acctest-fs-322"
resource_group_name = "acctestRG-postgresql-322"
zone = "2"
}
Could you please run the tool similar as I did above, with -n --hcl-only --plain-ui options, to see which step it failed?
TLDR: MSYS_NO_PATHCONV.
This is related to Windows - Linux path conversion inside a MSYS-based shells.
- I have same error in Git Bash on Windows.
- If I past exact same command e.g. in PowerShell - works.
- If I disable path conversion - works in Git Bash too. See example:
MSYS_NO_PATHCONV=1 aztfexport resource "/subscriptions/x-y-z/resourceGroups/some-rg/providers/Microsoft.Compute/sshPublicKeys/test-ssh"
Since this is a shell behavior, I'm gonna to close this issue for now. Thanks @needleshaped!