Terraform 1.71 Mock_provider error

All,

I am running terraform test v1.7.1 and mock provider as per given example in Terraform 1.7 adds test mocking and config-driven remove and Write Terraform Tests | Terraform | HashiCorp Developer

always i am getting error

│ Error: Unsupported block type
│ 
│   on tests/website.tftest.hcl line 50:
│   50: override_resource {
│ 
│ Blocks of type "override_resource" are not expected here.
╵
╷
│ Error: Unsupported block type
│ 
│   on tests/website.tftest.hcl line 54:
│   54: override_resource {
│ 
│ Blocks of type "override_resource" are not expected here

anything i am missing ? thanks in advance

Based on the error messages you’re getting, it sounds like there’s a bit of a hiccup with the syntax or configuration in your website.tftest.hcl file. Terraform is pretty picky about where and how certain blocks can be used, and it seems like it’s not recognizing override_resource as a valid block in the context you’re using it.

First thing’s first, let’s make sure you’re placing the override_resource block in the right spot. With Terraform 1.7’s new testing features, override_resource should be used within a mock_resources block, which in turn should be inside a test block. The structure should look something like this:

hclCopy code

test "your_test_name" {
  mock_resources {
    override_resource "your_resource_type.your_resource_name" {
      // Your overrides here
    }
  }
}

Make sure your override_resource blocks are nestled within mock_resources blocks, and that these are properly contained within a test block.

If everything seems to be in the right place and you’re still getting the error, double-check the version of Terraform you’re running. I know you mentioned you’re using Terraform 1.7.1, but it’s always good to verify with a quick terraform version command. Sometimes, the simplest solutions are the ones we overlook!

Another thing to consider is the structure and syntax of the override itself. Ensure that your overrides are correctly formatted and that you’re using the correct identifiers for the resources you intend to mock.

If after all this, you’re still stuck, feel free to share a snippet of your website.tftest.hcl (with any sensitive information redacted, of course). Sometimes, a second pair of eyes can spot something that’s easy to miss when you’ve been staring at the same code for a while.