aztfexport
aztfexport copied to clipboard
Updating backend state file
I've an issue when attempting to update my backend state file in Azure. When I run this command. Any advise on this? Much appreciated.
aztfexport resource-group --backend-type=azurerm --backend-config=resource_group_name=RG-terrformname --backend-config=storage_account_name=somestorageaccountname --backend-config=container_name=tfstate --backend-config=key=mystorekey.terraform.tfstate RG-somename
I receive this error " 1 error occurred: * task handler error: failed to merge state file: 1 error occurred: * showing state file C:\Users\jtaberne\AppData\Local\Temp\1\1218278346\terraform.tfstate: exit status 1 Failed to marshal state to json: schema version 0 for azurerm_managed_disk.manageddisk1tst in state does not match version 1 from the provider"
Hey @Wickerman14 is the version of the AzureRM provider you're using in your preexisting environment the same as the version you're export code shows? The tool will default to the latest version, so you'll need to at least specify ~>3.0
on your provider.
Thanks for getting back to me! I realised I was not in the correct folder when running the command. I've specified in my _provider.tf azurerm = {
source = "hashicorp/azurerm"
version = "3.20.0"
Now when I run the command I'm getting a different message.
"Error: --backend-config
should not be specified when appending to a workspace that has terraform block already defined."
@Wickerman14 The error is from a call to terraform show
in the exporting process on both your backend state file and the newly exported resources, to avoid resource address conflict. The terraform show
failed to parse the azurerm_managed_disk
since the schema version of that resource in the latest provider is different than your existing one.
Pinning the provider version is the right solution here, while to avoid the error, you can just put your backend config defined in the CLI to the terraform
block in the terraform.tf file. Alternatively, you can use the option --provider-version
in CLI.
:wave:
Since we've not heard back here I'm going to close this issue for the moment. Feel free to reopen if still have questions.