'Terraform plan error - Missing Expected {
I am using terraform 0.14.3 with custom provider to manage resources on on-perm infrastructure. Things are running fine as long as I am running Terraform to store state locally. However, when I switch to PG as backend, it gives me an error on plan:
Error: Missing Expected {
Below is how i am using PG configuration:
terraform {
required_providers {
mycloud = {
source = "terraform.provider/proj/cloud"
version = "0.0.x"
}
}
backend "pg" {
conn_str = "postgres://connection.url.for.postgres"
}
}
Again if remove the backend config, it works fine.
Solution 1:[1]
I am having the same problem. My debugging consisted of downloading the unhealthy tfstate and deleting resources until it started working again, which identified the broken resource. Then when I found the errant resource depicted below, I compared it to another healthy workspace :
{
"module": "module.mongodb_project",
"mode": "managed",
"type": "mongodbatlas_cloud_provider_access",
"name": "encryption_access",
"provider": "provider[\"registry.terraform.io/mongodb/mongodbatlas\"]",
"instances": [
{
"schema_version": 0,
"attributes": {
"atlas_assumed_role_external_id": "48491470-626e-4091-8b5e-..........",
"atlas_aws_account_arn": "arn:aws:iam::536727724300:root",
"authorized_date": "2021-04-19T18:40:22Z",
"created_date": "2021-03-12T18:51:17Z",
"feature_usages": [
{
"feature_id": "", <<<< ==== THIS IS THE PROBLEM
"feature_type": "ENCRYPTION_AT_REST"
}
],
"iam_assumed_role_arn": "arn:aws:iam::2411360.....:role/bluescape-kms",
"id": "...",
"project_id": "604bb8221347fxxxxxxxxxx",
"provider_name": "AWS",
"role_id": "604bb82577962xxxxxxxxxx"
},
"sensitive_attributes": [],
"private": "xxxxxxxx",
"dependencies": [
"module.mongodb_project.mongodbatlas_project.project"
]
}
]
},
In my healthy workspace, "feature_id" is {}, whereas in this unhealthy workspace, "feature_id" is "". Apparently, when there is a schema upgrade to a new version of a provider, they sometimes forget to run a conversion on the data and so this error represents a failure to upgrade the data structure from "" to {} (map). It is also happening for another resource of mine in the same workspace but I have to convert {} -> null!
Terraform should do a better job of printing errors when it encounters an error in tfstate. We have never edited the tfstate for this workspace before, the error is a result of schema upgrades that were not properly implemented by the mongo backend-provider developer.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
