terraform-provider-aws icon indicating copy to clipboard operation
terraform-provider-aws copied to clipboard

[Bug]: Failed to marshal plan to json, unsupported attribute "override_json"

Open kim0 opened this issue 1 year ago • 10 comments

Terraform Core Version

1.4.6

AWS Provider Version

5.0.1

Affected Resource(s)

Converting a saved plan file into json using terraform show -json results in this error Failed to marshal plan to json: error marshaling prior state: unsupported attribute "override_json"

Downgrading to anything less than 5.0.0, and the same command works

Expected Behavior

Plan is converted to json and displayed on the screen

Actual Behavior

I get the error: Failed to marshal plan to json: error marshaling prior state: unsupported attribute "override_json"

Relevant Error/Panic Output Snippet

No response

Terraform Configuration Files

Since terraform is not showing which TF code lines are causing this panic, it's not possible to show a snippet of the configs

Steps to Reproduce

  • Try to convert a saved plan file into json and it fails

Debug Output

No response

Panic Output

No response

Important Factoids

No response

References

No response

Would you like to implement a fix?

None

kim0 avatar May 30 '23 09:05 kim0

Community Note

Voting for Prioritization

  • Please vote on this issue by adding a 👍 reaction to the original post to help the community and maintainers prioritize this request.
  • Please see our prioritization guide for information on how we prioritize.
  • Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for issue followers and do not help prioritize the request.

Volunteering to Work on This Issue

  • If you are interested in working on this issue, please leave a comment.
  • If this would be your first contribution, please review the contribution guide.

github-actions[bot] avatar May 30 '23 09:05 github-actions[bot]

Maybe related to this change? https://github.com/hashicorp/terraform-provider-aws/issues/22906

jvisker avatar May 30 '23 18:05 jvisker

For some reason, "override_json": null exist in state, when it should be removed from the state

Example:

{
  "version": 4,
  "terraform_version": "1.3.9",
  "serial": 13,
  "lineage": "fe5ffc8a-776c-9548-36c5-0b43c266ccb1",
  "outputs": {},
  "resources": [
    {
      "mode": "data",
      "type": "aws_iam_policy_document",
      "name": "assume_role",
      "provider": "provider[\"registry.terraform.io/hashicorp/aws\"]",
      "instances": [
        {
          "schema_version": 0,
          "attributes": {
            "id": "1642520416",
            "json": "",
            "override_json": null,
            "override_policy_documents": null,
            "policy_id": null,
            "source_json": null,
            "source_policy_documents": null,
            "statement": [],
            "version": "2012-10-17"
          },
          "sensitive_attributes": []
        }
      ]
    },
    {
      "mode": "data",
      "type": "aws_iam_policy_document",
      "name": "iam_access",
      "provider": "provider[\"registry.terraform.io/hashicorp/aws\"]",
      "instances": [
        {
          "schema_version": 0,
          "attributes": {
            "id": "4064693197",
            "json": "",
            "override_json": null,
            "override_policy_documents": null,
            "policy_id": null,
            "source_json": null,
            "source_policy_documents": null,
            "statement": [],
            "version": "2012-10-17"
          },
          "sensitive_attributes": []
        }
      ]
    },
...

MaxymVlasov avatar Jun 06 '23 13:06 MaxymVlasov

The same issue happens with source_json

    {
      "mode": "data",
      "type": "aws_iam_policy_document",
      "name": "assume_role",
      "provider": "provider[\"registry.terraform.io/hashicorp/aws\"]",
      "instances": [
        {
          "schema_version": 0,
          "attributes": {
            "id": "....",
            "json": ....,
            "override_json": null, // Deprecated field!!!!
            "override_policy_documents": null,
            "policy_id": null,
            "source_json": null, // Deprecated field!!!!
            "source_policy_documents": null,

franciscoprin avatar Jun 06 '23 14:06 franciscoprin

Workaround: to fix the state without state manipulations, you need change resources which had the override_json field, and then apply.

For example:

  1. In data.aws_iam_policy_document, change Sid
  2. Run terraform apply

MaxymVlasov avatar Jun 06 '23 15:06 MaxymVlasov

I have the same issue in TF 1.5.0 with AWS Provider 5.4.0

For me the workaround doesn't work because many of the aws_iam_policy_document data are managed by modules meaning a simple change of SID is not always possible

This is a sever issue and has already impacted a production workspace which seems now nigh on unrecoverable baring some drastic state manipulation 🫰

Any speedy progress would be greatly appreciated!

tomer-ds avatar Jun 20 '23 19:06 tomer-ds

I encountered this while trying to delete from state in Terraform Cloud. As a workaround, I had to first checkout the main branch version of my workspace, upgrade to AWS Provider 5, and terraform state refresh to fixup the state. Following that I was able to delete resources from state.

carl-reverb avatar Jun 27 '23 18:06 carl-reverb

Hi Team, We are also facing same issue when running plan for specific resource or module. Failed to marshal plan to json: error marshaling prior state: unsupported attribute "override_json" Is there any fix or workaround anyone has for this issue.

Mukesh-Sharma-external avatar Dec 07 '23 05:12 Mukesh-Sharma-external

In my case I have managed to make it work by:

  • Upgrading providers, previously had AWS version 4.37.0, now on 5.31.0: terraform init -upgrade
  • Performing a plan and apply - even without changes. In my case I had "override_json": null in state. After the upgrade these were gone and I could finish what I was trying to do - a state push.

ferschubert avatar Dec 19 '23 20:12 ferschubert

Seeing this very consistently when doing a -target'ed plan.

major0 avatar Feb 21 '24 18:02 major0

I just got this issue

`Failed generating plan JSON Exit code: 1

Failed to marshal plan to json: error marshaling prior state: unsupported attribute "override_json" Operation failed: failed generating plan JSON: failed running command (exit 1)`

I have external modules, so Im not able to perform simple SID change. Is there any other way to fix this?

muhamedkapoevolt avatar Mar 06 '24 10:03 muhamedkapoevolt

I just got this issue

`Failed generating plan JSON Exit code: 1

Failed to marshal plan to json: error marshaling prior state: unsupported attribute "override_json" Operation failed: failed generating plan JSON: failed running command (exit 1)`

I have external modules, so Im not able to perform simple SID change. Is there any other way to fix this?

Look like i fixed my issue with running plan+apply on 4.x provider with changed SID in all "aws_iam_policy_document" resources that I handle, get it back on 5.x and it worked!

muhamedkapoevolt avatar Mar 08 '24 09:03 muhamedkapoevolt

This functionality has been released in v5.41.0 of the Terraform AWS Provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading.

For further feature requests or bug reports with this functionality, please create a new GitHub issue following the template. Thank you!

github-actions[bot] avatar Mar 14 '24 22:03 github-actions[bot]

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

github-actions[bot] avatar Apr 14 '24 02:04 github-actions[bot]