Skip to content

The literal string "string" is incorrectly quoted #251

Closed

Description

@mcasperson

When deserializing a property that assigns the literal value string to a property, it is incorrectly quoted.

A clear and concise description of what the bug is.

Software:

  • OS: Linux
  • Python version 3.11
  • python-hcl2 version 7.3.1

Snippet of HCL2 code causing the unexpected behaviour:

variable "octopus_space_id" {
  type        = string
  nullable    = false
  sensitive   = false
  description = "The ID of the Octopus space to populate."
}

Expected behavior

The following script should produce output with an unquoted string value:

import hcl2

hcl = """variable "octopus_space_id" {
  type        = string
  nullable    = false
  sensitive   = false
  description = "The ID of the Octopus space to populate."
}
"""

parsed_config = hcl2.loads(hcl, with_meta=True)
example_ast = hcl2.reverse_transform(parsed_config)
converted_hcl = hcl2.writes(example_ast)

print(converted_hcl)

The result of this script is this:

variable "octopus_space_id" {
  type = "string"
  nullable = false
  sensitive = false
  description = "The ID of the Octopus space to populate."
}

Terraform does not accept this output as the type must be an unquoted value.

Activity

  1. added
    bug
    on Nov 27, 2025
  2. added
    unreleased
    and removed
    unreleased
    on Dec 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions