Introduction
Problem
You have Terraform Enterprise version v202307-1/v202308-1 and working with the new feature to import resources with code block as described here
During the execution Terraform Enterprise shows the following error in the run output
│ Error: Compatibility error
│
│ Error reading TFC agent version. To proceed, please remove any import
│ blocks from your config. Please report the following error to the Terraform
│ team: TFC_AGENT_VERSION not present.
This is not expected as the hashicorp/tfe-agent:latest image with the Terraform Enterprise release v202307-1/v202308-1 is version 1.10.0 or higher that support the import block
Cause
When installing the Terraform Enterprise version v202307-1/v202308-1 on a new environment the hashicorp/tfe-agent:latest image will point to an agent of version 1.10.0.
If you upgrade from earlier versions on the same machine the hashicorp/tfe-agent:latest doesn't get updated to point to the new agent release with the Terraform Enterprise version.
Verify the hashicorp/tfe-agent:latest on the agent version
docker inspect hashicorp/tfe-agent:latest
The output will show something like the following which shows the version is 1.7.1 instead of the expected version 1.10.0
...
...
"Labels": {
"com.hashicorp..version": "1.7.1",
"com.hashicorp.container-type": "tfe-agent",
...
...
Overview of possible solutions
Solution 1
Upgrade Terraform Enterprise to version v202309-1 when available(on September 2023) or higher
Solution 2
Remove the current tfe-agent:latest image from the system. After TFE starts it will notice the missing tfe-agent:latest image and create it again properly pointing to the latest image it has with the release installed on the system. .
- SSH to the Terraform Enterprise instance
- Stop the Terraform Enterprise application
replicatedctl app stop
- Confirm app is fully stopped before proceeding to the next step
replicatedctl app status
- Delete the agent image
docker rmi -f hashicorp/tfe-agent:latest
- Start the Terraform Enterprise application
replicatedctl app start
- Confirm the image has been re-created.
docker images | grep hashicorp/tfe-agent
hashicorp/tfe-agent latest f78028f6be16 7 minutes ago 387MB
Outcome
You should be using a higher version of the agent that supports the import block