hashicorp / terraform-config-inspect

A helper library for shallow inspection of Terraform configurations
Mozilla Public License 2.0
376 stars 76 forks source link

Terraform variable with type object - type value not converted into json format #31

Open tcondeixa opened 4 years ago

tcondeixa commented 4 years ago

Use-case: I'm using the CLI from terraform-config-inspect (json output) to generate documentation for modules using json parsing in the output.

Problem: When using object type into variables the default is converted json but the type is not converted to json format.

Terraform Code Example:

variable "cors_rule" {
  description = "default cors rule defined for s3 bucket"
  type = object({
    max_age_seconds = number
    allowed_origins = list(string)
    allowed_methods = list(string)
    allowed_headers = list(string)
  })
  default = {
    max_age_seconds = 3000
    allowed_origins = [
      "*"]
    allowed_methods = [
      "GET",
      "PUT"]
    allowed_headers = [
      "*"]
  }
}

Output:

"cors_rule": {
      "name": "cors_rule",
      "type": "object({\n    max_age_seconds = number\n    allowed_origins = list(string)\n    allowed_methods = list(string)\n    allowed_headers = list(string)\n  })",
      "description": "default cors rule defined for s3 bucket",
      "default": {
        "allowed_headers": [
          "*"
        ],
        "allowed_methods": [
          "GET",
          "PUT"
        ],
        "allowed_origins": [
          "*"
        ],
        "max_age_seconds": 3000
      },
      "pos": {
        "filename": "variables.tf",
        "line": 121
      }
    }