Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error parsing import statement in HCL-JSON #1652

Closed
aherbst-broad opened this issue May 16, 2024 · 2 comments · Fixed by #1665
Closed

Error parsing import statement in HCL-JSON #1652

aherbst-broad opened this issue May 16, 2024 · 2 comments · Fixed by #1665
Assignees
Labels
accepted This issue has been accepted for implementation. bug Something isn't working
Milestone

Comments

@aherbst-broad
Copy link

OpenTofu Version

» tofu --version                                       
OpenTofu v1.7.1
on darwin_arm64
+ provider registry.terraform.io/hashicorp/azurerm v3.95.0

OpenTofu Configuration Files

{
  "//": {
    "metadata": {
      "backend": "pg",
      "imports": {
        "azurerm_storage_account": [
          "storageAccount"
        ]
      },
      "stackName": "storageAccount1234",
      "version": "0.20.7"
    },
    "outputs": {
    }
  },
  "import": [
    {
      "id": "/subscriptions/cfb45937-0e77-4aaa-a3ec-d2d83e4df678/resourceGroups/test1234/providers/Microsoft.Storage/storageAccounts/storageAccount1234",
      "to": "azurerm_storage_account.storageAccount"
    }
  ],
  "provider": {
    "azurerm": [
      {
        "features": {
        }
      }
    ]
  },
  "resource": {
    "azurerm_storage_account": {
      "storageAccount": {
        "//": {
          "metadata": {
            "path": "storageAccount1234/storageAccount",
            "uniqueId": "storageAccount"
          }
        },
        "account_replication_type": "LRS",
        "account_tier": "Standard",
        "lifecycle": {
          "ignore_changes": [
            "location"
          ]
        },
        "location": "westus",
        "name": "lzstorageaccount1234",
        "resource_group_name": "storageAccount1234"
      }
    }
  },
  "terraform": {
    "backend": {
      "pg": {
        "conn_str": "postgres://postgres:mysecretpassword@localhost/terraform_backend?sslmode=disable"
      }
    },
    "required_providers": {
      "azurerm": {
        "source": "azurerm",
        "version": "3.95.0"
      }
    }
  }
}

Debug Output

https://gist.github.com/aherbst-broad/4e7730390be12825dfcbac95c70f52c2

Expected Behavior

The plan and subsequent apply should succeed instead of erroring out. Running against Terraform 1.8.3 succeeds.

Actual Behavior

tofu plan errors out like this:

╷
│ Error: Invalid import address expression
│
│   on cdk.tf.json line 19, in import[0]:
│   19:       "to": "azurerm_storage_account.storageAccount"
│
│ Import address must be a reference to a resource's address, and only allows for indexing with dynamic keys. For example: module.my_module[expression1].aws_s3_bucket.my_buckets[expression2] for resources inside of modules, or simply
│ aws_s3_bucket.my_bucket for a resource in the root module

Steps to Reproduce

  1. tofu init
  2. tofu plan

Additional Context

No response

References

May be related to this commit

@aherbst-broad aherbst-broad added bug Something isn't working pending-decision This issue has not been accepted for implementation nor rejected. It's still open to discussion. labels May 16, 2024
@Evi1Pumpkin
Copy link
Collaborator

Evi1Pumpkin commented May 20, 2024

Hi @aherbst-broad, and thank you for reporting this bug.
I managed to reproduce it using JSON files, it looks like we don't parse the to value correctly. The same configuration in TF files is working correctly.
We'll start working on a fix and update you when we are done.
Thank you again for reporting this!

@Evi1Pumpkin Evi1Pumpkin added accepted This issue has been accepted for implementation. and removed pending-decision This issue has not been accepted for implementation nor rejected. It's still open to discussion. labels May 20, 2024
@cube2222 cube2222 added this to the 1.7.2 milestone May 20, 2024
@Evi1Pumpkin
Copy link
Collaborator

Hi @aherbst-broad,

We have fixed this bug in version v1.7.2, which is now available.

Thank you for your patience and for helping to improve OpenTofu. Your assistance is highly appreciated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accepted This issue has been accepted for implementation. bug Something isn't working
Projects
None yet
3 participants