Skip to content

The literal string "string" is incorrectly quoted #251

@mcasperson

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.

Metadata

Metadata

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions