question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

vsCode not formatting Terraform files

See original GitHub issue

Issue Description

Format Document no longer working for TF files.

  • Open a Terraform (*.tf) file/format
  • Right click > Format Document
  • Progress bar as the top of the document animates for a few moments; no formatting occurs.

Environment Information

Terraform Information

Version: 1.0.8 Platform: linux_amd64 Outdated: false

Visual Studio Code

Name Version
Operating System Linux x64 3.10.0-1160.71.1.el7.x86_64
VSCode 1.70.1

Visual Studio Code Extensions

Visual Studio Code Extensions(Click to Expand)
Extension Author Version
azure-account ms-vscode 0.11.1
jupyter ms-toolsai 2022.7.1102252217
jupyter-renderers ms-toolsai 1.0.9
powershell ms-vscode 2022.7.2
python ms-python 2022.12.0
terraform hashicorp 2.23.0
vscode-pylance ms-python 2022.8.20
vscode-yaml redhat 1.9.1
vscodeintellicode VisualStudioExptTeam 1.2.22

Extension Logs

Find this from the first few lines of the relevant Output pane: View -> Output -> ‘HashiCorp Terraform’

Launching language server: /home/IAMERS/nasnyder/.vscode-server/extensions/hashicorp.terraform-2.23.0-linux-x64/bin/terraform-ls serve
2022/08/17 20:12:31 serve_command.go:162: Starting terraform-ls 0.28.1
2022/08/17 20:12:31 service.go:95: Preparing new session ...
2022/08/17 20:12:31 langserver.go:94: Starting server (pid 41076; concurrency: 24) ...
2022/08/17 20:12:31 opts.go:218: Received request batch of size 1 (qlen=0)
2022/08/17 20:12:31 opts.go:218: Dequeued request batch of length 1 (qlen=0)
2022/08/17 20:12:31 rpc_logger.go:29: Incoming request for "initialize" (ID 0): {"processId":40976,"clientInfo":{"name":"Visual Studio Code","version":"1.70.1"},"locale":"en","rootPath":"/home/IAMERS/nasnyder/dev/terraform/oci-arch-logging-splunk/GIO-langley-soe","rootUri":"file:///home/IAMERS/nasnyder/dev/terraform/oci-arch-logging-splunk/GIO-langley-soe","capabilities":{"workspace":{"applyEdit":true,"workspaceEdit":{"documentChanges":true,"resourceOperations":["create","rename","delete"],"failureHandling":"textOnlyTransactional","normalizesLineEndings":true,"changeAnnotationSupport":{"groupsOnLabel":true}},"didChangeConfiguration":{"dynamicRegistration":true},"didChangeWatchedFiles":{"dynamicRegistration":true},"symbol":{"dynamicRegistration":true,"symbolKind":{"valueSet":[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26]},"tagSupport":{"valueSet":[1]}},"codeLens":{"refreshSupport":true},"executeCommand":{"dynamicRegistration":true},"configuration":true,"workspaceFolders":true,"semanticTokens":{"refreshSupport":true},"fileOperations":{"dynamicRegistration":true,"didCreate":true,"didRename":true,"didDelete":true,"willCreate":true,"willRename":true,"willDelete":true}},"textDocument":{"publishDiagnostics":{"relatedInformation":true,"versionSupport":false,"tagSupport":{"valueSet":[1,2]},"codeDescriptionSupport":true,"dataSupport":true},"synchronization":{"dynamicRegistration":true,"willSave":true,"willSaveWaitUntil":true,"didSave":true},"completion":{"dynamicRegistration":true,"contextSupport":true,"completionItem":{"snippetSupport":true,"commitCharactersSupport":true,"documentationFormat":["markdown","plaintext"],"deprecatedSupport":true,"preselectSupport":true,"tagSupport":{"valueSet":[1]},"insertReplaceSupport":true,"resolveSupport":{"properties":["documentation","detail","additionalTextEdits"]},"insertTextModeSupport":{"valueSet":[1,2]}},"completionItemKind":{"valueSet":[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25]}},"hover":{"dynamicRegistration":true,"contentFormat":["markdown","plaintext"]},"signatureHelp":{"dynamicRegistration":true,"signatureInformation":{"documentationFormat":["markdown","plaintext"],"parameterInformation":{"labelOffsetSupport":true},"activeParameterSupport":true},"contextSupport":true},"definition":{"dynamicRegistration":true,"linkSupport":true},"references":{"dynamicRegistration":true},"documentHighlight":{"dynamicRegistration":true},"documentSymbol":{"dynamicRegistration":true,"symbolKind":{"valueSet":[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26]},"hierarchicalDocumentSymbolSupport":true,"tagSupport":{"valueSet":[1]},"labelSupport":true},"codeAction":{"dynamicRegistration":true,"isPreferredSupport":true,"disabledSupport":true,"dataSupport":true,"resolveSupport":{"properties":["edit"]},"codeActionLiteralSupport":{"codeActionKind":{"valueSet":["","quickfix","refactor","refactor.extract","refactor.inline","refactor.rewrite","source","source.organizeImports"]}},"honorsChangeAnnotations":false},"codeLens":{"dynamicRegistration":true},"formatting":{"dynamicRegistration":true},"rangeFormatting":{"dynamicRegistration":true},"onTypeFormatting":{"dynamicRegistration":true},"rename":{"dynamicRegistration":true,"prepareSupport":true,"prepareSupportDefaultBehavior":1,"honorsChangeAnnotations":true},"documentLink":{"dynamicRegistration":true,"tooltipSupport":true},"typeDefinition":{"dynamicRegistration":true,"linkSupport":true},"implementation":{"dynamicRegistration":true,"linkSupport":true},"colorProvider":{"dynamicRegistration":true},"foldingRange":{"dynamicRegistration":true,"rangeLimit":5000,"lineFoldingOnly":true},"declaration":{"dynamicRegistration":true,"linkSupport":true},"selectionRange":{"dynamicRegistration":true},"callHierarchy":{"dynamicRegistration":true},"semanticTokens":{"dynamicRegistration":true,"tokenTypes":["namespace","type","class","enum","interface","struct","typeParameter","parameter","variable","property","enumMember","event","function","method","macro","keyword","modifier","comment","string","number","regexp","operator","hcl-attrName","hcl-blockType","hcl-blockLabel","hcl-bool","hcl-string","hcl-number","hcl-objectKey","hcl-mapKey","hcl-keyword","hcl-traversalStep","hcl-typeCapsule","hcl-typePrimitive"],"tokenModifiers":["declaration","definition","readonly","static","deprecated","abstract","async","modification","documentation","defaultLibrary","hcl-dependent","terraform-data","terraform-locals","terraform-module","terraform-output","terraform-provider","terraform-resource","terraform-provisioner","terraform-connection","terraform-variable","terraform-terraform","terraform-backend","terraform-name","terraform-type","terraform-requiredProviders"],"formats":["relative"],"requests":{"range":true,"full":{"delta":true}},"multilineTokenSupport":false,"overlappingTokenSupport":false},"linkedEditingRange":{"dynamicRegistration":true}},"window":{"showMessage":{"messageActionItem":{"additionalPropertiesSupport":true}},"showDocument":{"support":true},"workDoneProgress":true},"general":{"regularExpressions":{"engine":"ECMAScript","version":"ES2020"},"markdown":{"parser":"marked","version":"1.1.0"}},"experimental":{"refreshModuleProvidersCommandId":"client.refreshModuleProviders","refreshModuleCallsCommandId":"client.refreshModuleCalls","telemetryVersion":1}},"initializationOptions":{"experimentalFeatures":{},"ignoreSingleFileWarning":false},"trace":"off","workspaceFolders":[{"uri":"file:///home/IAMERS/nasnyder/dev/terraform/oci-arch-logging-splunk/GIO-langley-soe","name":"GIO-langley-soe"}]}
2022/08/17 20:12:31 initialize.go:158: enabling telemetry (version: 1)
2022/08/17 20:12:31 initialize.go:163: telemetry enabled (version: 1)
2022/08/17 20:12:31 opts.go:218: Posting server notification "telemetry/event" {"v":1,"name":"initialize","properties":{"experimentalCapabilities.referenceCountCodeLens":false,"lsVersion":"0.28.1","options.commandPrefix":false,"options.excludeModulePaths":false,"options.experimentalFeatures.prefillRequiredFields":false,"options.experimentalFeatures.validateOnSave":false,"options.ignoreDirectoryNames":false,"options.ignoreSingleFileWarning":false,"options.rootModulePaths":false,"options.terraformExecPath":false,"options.terraformExecTimeout":"","options.terraformLogFilePath":false,"root_uri":"dir"}}
2022/08/17 20:12:31 scheduler.go:45: launching eval loop 0
2022/08/17 20:12:31 service.go:443: running closed dir scheduler
2022/08/17 20:12:31 scheduler.go:45: launching eval loop 0
2022/08/17 20:12:31 service.go:448: running open dir scheduler
2022/08/17 20:12:35 watcher.go:498: watching for changes ...
2022/08/17 20:12:35 walker_paths.go:240: walking next dir: {"file:///home/IAMERS/nasnyder/dev/terraform/oci-arch-logging-splunk/GIO-langley-soe"}
2022/08/17 20:12:35 rpc_logger.go:50: Response to "initialize" (ID 0): {"capabilities":{"textDocumentSync":{"openClose":true,"change":2,"save":{}},"completionProvider":{"triggerCharacters":[".","["],"completionItem":{}},"hoverProvider":true,"signatureHelpProvider":{},"declarationProvider":{},"definitionProvider":true,"referencesProvider":true,"documentSymbolProvider":true,"codeActionProvider":{"codeActionKinds":["source.formatAll.terraform"]},"codeLensProvider":{},"documentLinkProvider":{},"workspaceSymbolProvider":true,"documentFormattingProvider":true,"documentOnTypeFormattingProvider":{"firstTriggerCharacter":""},"executeCommandProvider":{"commands":["terraform-ls.module.callers","terraform-ls.module.calls","terraform-ls.module.providers","terraform-ls.rootmodules","terraform-ls.terraform.init","terraform-ls.terraform.validate"],"workDoneProgress":true},"semanticTokensProvider":{"legend":{"tokenTypes":["enumMember","function","keyword","number","parameter","property","string","type","variable","hcl-attrName","hcl-blockType","hcl-blockLabel","hcl-bool","hcl-string","hcl-number","hcl-objectKey","hcl-mapKey","hcl-keyword","hcl-traversalStep","hcl-typeCapsule","hcl-typePrimitive"],"tokenModifiers":["defaultLibrary","hcl-dependent","terraform-backend","terraform-connection","terraform-data","terraform-locals","terraform-module","terraform-name","terraform-output","terraform-provider","terraform-provisioner","terraform-requiredProviders","terraform-resource","terraform-terraform","terraform-type","terraform-variable"]},"full":true},"workspace":{"workspaceFolders":{"supported":true,"changeNotifications":"workspace/didChangeWorkspaceFolders"}},"experimental":{"referenceCountCodeLens":false,"refreshModuleProviders":true,"refreshModuleCalls":true}},"serverInfo":{"name":"terraform-ls","version":"0.28.1"}}
2022/08/17 20:12:35 opts.go:218: Completed 1 requests [4.203191012s elapsed]
2022/08/17 20:12:35 walker.go:188: skipping /home/IAMERS/nasnyder/dev/terraform/oci-arch-logging-splunk/GIO-langley-soe/.git
2022/08/17 20:12:35 walker.go:197: found module /home/IAMERS/nasnyder/dev/terraform/oci-arch-logging-splunk/GIO-langley-soe
2022/08/17 20:12:35 jobs.go:92: JOBS: Enqueueing new job "1": "OpTypeParseModuleConfiguration" for {"file:///home/IAMERS/nasnyder/dev/terraform/oci-arch-logging-splunk/GIO-langley-soe"}
2022/08/17 20:12:35 jobs.go:92: JOBS: Enqueueing new job "2": "OpTypeParseVariables" for {"file:///home/IAMERS/nasnyder/dev/terraform/oci-arch-logging-splunk/GIO-langley-soe"}
2022/08/17 20:12:35 jobs.go:92: JOBS: Enqueueing new job "3": "OpTypeGetTerraformVersion" for {"file:///home/IAMERS/nasnyder/dev/terraform/oci-arch-logging-splunk/GIO-langley-soe"}
2022/08/17 20:12:35 walker.go:268: parsed datadir: &datadir.DataDir{ModuleManifestPath:"/home/IAMERS/nasnyder/dev/terraform/oci-arch-logging-splunk/GIO-langley-soe/.terraform/modules/modules.json", PluginLockFilePath:"/home/IAMERS/nasnyder/dev/terraform/oci-arch-logging-splunk/GIO-langley-soe/.terraform.lock.hcl"}
2022/08/17 20:12:35 jobs.go:244: JOBS: Dispatching next job "1": "OpTypeParseModuleConfiguration" for {"file:///home/IAMERS/nasnyder/dev/terraform/oci-arch-logging-splunk/GIO-langley-soe"}
2022/08/17 20:12:35 jobs.go:92: JOBS: Enqueueing new job "4": "OpTypeObtainSchema" for {"file:///home/IAMERS/nasnyder/dev/terraform/oci-arch-logging-splunk/GIO-langley-soe"}
2022/08/17 20:12:35 jobs.go:92: JOBS: Enqueueing new job "5": "OpTypeParseModuleManifest" for {"file:///home/IAMERS/nasnyder/dev/terraform/oci-arch-logging-splunk/GIO-langley-soe"}
2022/08/17 20:12:35 jobs.go:358: JOBS: Finishing job "1": "OpTypeParseModuleConfiguration" for {"file:///home/IAMERS/nasnyder/dev/terraform/oci-arch-logging-splunk/GIO-langley-soe"} (err = %!s(<nil>), deferredJobs: [])
2022/08/17 20:12:35 jobs.go:244: JOBS: Dispatching next job "2": "OpTypeParseVariables" for {"file:///home/IAMERS/nasnyder/dev/terraform/oci-arch-logging-splunk/GIO-langley-soe"}
2022/08/17 20:12:35 jobs.go:92: JOBS: Enqueueing new job "6": "OpTypeDecodeVarsReferences" for {"file:///home/IAMERS/nasnyder/dev/terraform/oci-arch-logging-splunk/GIO-langley-soe"}
2022/08/17 20:12:35 jobs.go:358: JOBS: Finishing job "2": "OpTypeParseVariables" for {"file:///home/IAMERS/nasnyder/dev/terraform/oci-arch-logging-splunk/GIO-langley-soe"} (err = %!s(<nil>), deferredJobs: ["6"])
2022/08/17 20:12:35 jobs.go:244: JOBS: Dispatching next job "3": "OpTypeGetTerraformVersion" for {"file:///home/IAMERS/nasnyder/dev/terraform/oci-arch-logging-splunk/GIO-langley-soe"}
2022/08/17 20:12:35 opts.go:218: Received request batch of size 1 (qlen=0)
2022/08/17 20:12:35 opts.go:218: Dequeued request batch of length 1 (qlen=0)
2022/08/17 20:12:35 rpc_logger.go:29: Incoming notification for "initialized": {}
2022/08/17 20:12:35 opts.go:218: Received request batch of size 1 (qlen=0)
2022/08/17 20:12:35 opts.go:218: Dequeued request batch of length 1 (qlen=0)
2022/08/17 20:12:35 rpc_logger.go:29: Incoming notification for "textDocument/didOpen": {"textDocument":{"uri":"file:///home/IAMERS/nasnyder/dev/terraform/oci-arch-logging-splunk/GIO-langley-soe/modules/terraform-oci-vcn-hub/logging.tf","languageId":"terraform","version":1,"text":"# Enable VCN Flow Logs for Hub VCN\n\n# Rather than attempt to pull some inter-module nonsense...just utilize the data source to get objects by name\ndata \"oci_logging_log_groups\" \"vcn_log_groups\" {\n  compartment_id = var.stream_compartment_ocid\n  display_name   = var.log_group_name\n}\n\ndata \"oci_streaming_streams\" \"splunk_streams\" {\n  compartment_id = var.stream_compartment_ocid\n  name           = var.splunk_stream_name\n  state          = \"Active\"\n}\n\n# Service Logs directed to the 1st matching log_group by name; in the Security Compartment\nresource \"oci_logging_log\" \"vcn_flow_log\" {\n  display_name = oci_core_subnet.svc_subnet.display_name\n  log_group_id = data.oci_logging_log_groups.vcn_log_groups.log_groups[0].id\n  log_type     = \"SERVICE\"\n  configuration {\n    source {\n      category    = \"all\"\n      resource    = oci_core_subnet.svc_subnet.id\n      service     = \"flowlogs\"\n      source_type = \"OCISERVICE\"\n    }\n    compartment_id = var.stream_compartment_ocid\n  }\n  defined_tags       = merge(local.default_tags, var.defined_tags)\n  is_enabled         = true\n  retention_duration     = 30\n  lifecycle {\n    ignore_changes = [\n      defined_tags[\"Oracle_Tags.CreatedOn\"],\n      defined_tags[\"Oracle_Tags.CreatedBy\"]\n    ]\n  }\n}\n"}}
2022/08/17 20:12:35 did_open.go:42: opened module: /home/IAMERS/nasnyder/dev/terraform/oci-arch-logging-splunk/GIO-langley-soe/modules/terraform-oci-vcn-hub
2022/08/17 20:12:35 jobs.go:92: JOBS: Enqueueing new job "7": "OpTypeParseModuleConfiguration" for {"file:///home/IAMERS/nasnyder/dev/terraform/oci-arch-logging-splunk/GIO-langley-soe/modules/terraform-oci-vcn-hub"}
2022/08/17 20:12:35 jobs.go:92: JOBS: Enqueueing new job "8": "OpTypeParseVariables" for {"file:///home/IAMERS/nasnyder/dev/terraform/oci-arch-logging-splunk/GIO-langley-soe/modules/terraform-oci-vcn-hub"}
2022/08/17 20:12:35 jobs.go:92: JOBS: Enqueueing new job "9": "OpTypeGetTerraformVersion" for {"file:///home/IAMERS/nasnyder/dev/terraform/oci-arch-logging-splunk/GIO-langley-soe/modules/terraform-oci-vcn-hub"}
2022/08/17 20:12:35 watcher.go:86: adding module for watching: /home/IAMERS/nasnyder/dev/terraform/oci-arch-logging-splunk/GIO-langley-soe/modules/terraform-oci-vcn-hub
2022/08/17 20:12:35 jobs.go:358: JOBS: Finishing job "3": "OpTypeGetTerraformVersion" for {"file:///home/IAMERS/nasnyder/dev/terraform/oci-arch-logging-splunk/GIO-langley-soe"} (err = %!s(<nil>), deferredJobs: [])
2022/08/17 20:12:35 jobs.go:244: JOBS: Dispatching next job "4": "OpTypeObtainSchema" for {"file:///home/IAMERS/nasnyder/dev/terraform/oci-arch-logging-splunk/GIO-langley-soe"}
2022/08/17 20:12:35 opts.go:218: Received request batch of size 1 (qlen=0)
2022/08/17 20:12:35 opts.go:218: Dequeued request batch of length 1 (qlen=0)
2022/08/17 20:12:35 opts.go:218: Received request batch of size 1 (qlen=0)
2022/08/17 20:12:35 opts.go:218: Received request batch of size 1 (qlen=1)
2022/08/17 20:12:36 opts.go:218: Received request batch of size 1 (qlen=2)
2022/08/17 20:12:36 opts.go:218: Posting server notification "telemetry/event" {"v":1,"name":"moduleData","properties":{"installedProviders":{"registry.terraform.io/hashicorp/dns":"3.2.3","registry.terraform.io/infobloxopen/infoblox":"2.1.0"},"moduleId":"0829ee70-03dd-67c5-ad3e-020063291fa5","tfVersion":"1.0.8"}}
2022/08/17 20:12:36 opts.go:218: Posting server call "client.refreshModuleProviders" 
2022/08/17 20:12:36 opts.go:218: Received response for callback "1"
2022/08/17 20:12:36 opts.go:218: Posting server call "client.refreshModuleCalls" 
2022/08/17 20:12:36 opts.go:218: Received response for callback "2"
2022/08/17 20:12:36 opts.go:218: Received request batch of size 1 (qlen=3)
2022/08/17 20:12:36 opts.go:218: Received request batch of size 1 (qlen=4)
2022/08/17 20:12:36 opts.go:218: Received request batch of size 1 (qlen=5)
2022/08/17 20:12:36 opts.go:218: Received request batch of size 1 (qlen=6)
2022/08/17 20:12:38 opts.go:218: Received request batch of size 1 (qlen=7)
2022/08/17 20:12:38 opts.go:218: Received request batch of size 1 (qlen=8)
2022/08/17 20:12:38 opts.go:218: Received request batch of size 1 (qlen=9)
2022/08/17 20:12:43 opts.go:218: Received request batch of size 1 (qlen=10)
2022/08/17 20:12:43 opts.go:218: Received request batch of size 1 (qlen=11)
2022/08/17 20:12:51 opts.go:218: Received request batch of size 1 (qlen=12)
2022/08/17 20:12:51 opts.go:218: Received request batch of size 1 (qlen=13)
2022/08/17 20:12:51 opts.go:218: Received request batch of size 1 (qlen=14)
2022/08/17 20:12:51 opts.go:218: Received request batch of size 1 (qlen=15)

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
Sneedescommented, Aug 23, 2022

Uninstalling the Preview version and installing 2.24.0 appears to have resolved my issue.

Side note…noting that the Changelog shows 2.24.0 (Unreleased). Was expecting to see todays date.
image

0reactions
github-actions[bot]commented, Sep 23, 2022

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cannot get autoformatting (format on save) working - VS Code
I'm not able to get formatting to occur on a save. Is there something I'm missing? I've also added the terraform format on...
Read more >
How to configure alignment and indentation of terraform code ...
You can use the formatting function of terraform fmt , it just format all tf files in your directory and aligns their format....
Read more >
How to Auto Format HCL Terraform Code in Visual Studio Code
📝In the search bar, type “HashiCorp” and select HashiCorp Terraform once it appears. 📝In the search settings type “format”. Confirm the auto format...
Read more >
HashiCorp Terraform - Visual Studio Marketplace
Code Formatting. This extension utilizes terraform fmt to rewrite an open document to a canonical format and style. This command applies a ...
Read more >
It's Time To Tidy Up Your Code: How To Use VS ... - C# Corner
Open the menu File->Preferences->Settings and under Text Editor look for Formating and enable the option Format On Save choosing which option is ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found