minamijoyo / tfschema

A schema inspector for Terraform / OpenTofu providers
MIT License
295 stars 15 forks source link

Use typeexpr.TypeString(cty.Type) in HCL2 instead of our custom logic #19

Closed minamijoyo closed 5 years ago

minamijoyo commented 5 years ago

Fixes #18

In #16, I said

it seems that HCL2 has a type annotation parser but no writer

but it is not true. I found typeexpr.TypeString(cty.Type) in HCL2 and we should use it.

TypeString returns a string without space. If a type name contains object type, its length may be long. It’ s hard to read with table mode. So we add a space to the type name so that tablewriter can break it into lines.

[v0.12@use-typeexpr|✔]$ ../../bin/tfschema resource show aws_security_group
+------------------------+--------------------------------+----------+----------+----------+-----------+
| ATTRIBUTE              | TYPE                           | REQUIRED | OPTIONAL | COMPUTED | SENSITIVE |
+------------------------+--------------------------------+----------+----------+----------+-----------+
| arn                    | string                         | false    | false    | true     | false     |
| description            | string                         | false    | true     | false    | false     |
| egress                 | set(object({                   | false    | true     | true     | false     |
|                        | cidr_blocks=list(string),      |          |          |          |           |
|                        | description=string,            |          |          |          |           |
|                        | from_port=number,              |          |          |          |           |
|                        | ipv6_cidr_blocks=list(string), |          |          |          |           |
|                        | prefix_list_ids=list(string),  |          |          |          |           |
|                        | protocol=string,               |          |          |          |           |
|                        | security_groups=set(string),   |          |          |          |           |
|                        | self=bool, to_port=number }))  |          |          |          |           |
| id                     | string                         | false    | true     | true     | false     |
| ingress                | set(object({                   | false    | true     | true     | false     |
|                        | cidr_blocks=list(string),      |          |          |          |           |
|                        | description=string,            |          |          |          |           |
|                        | from_port=number,              |          |          |          |           |
|                        | ipv6_cidr_blocks=list(string), |          |          |          |           |
|                        | prefix_list_ids=list(string),  |          |          |          |           |
|                        | protocol=string,               |          |          |          |           |
|                        | security_groups=set(string),   |          |          |          |           |
|                        | self=bool, to_port=number }))  |          |          |          |           |
| name                   | string                         | false    | true     | true     | false     |
| name_prefix            | string                         | false    | true     | false    | false     |
| owner_id               | string                         | false    | false    | true     | false     |
| revoke_rules_on_delete | bool                           | false    | true     | false    | false     |
| tags                   | map(string)                    | false    | true     | false    | false     |
| vpc_id                 | string                         | false    | true     | true     | false     |
+------------------------+--------------------------------+----------+----------+----------+-----------+

block_type: timeouts, nesting: NestingSingle, min_items: 0, max_items: 0
+-----------+--------+----------+----------+----------+-----------+
| ATTRIBUTE | TYPE   | REQUIRED | OPTIONAL | COMPUTED | SENSITIVE |
+-----------+--------+----------+----------+----------+-----------+
| create    | string | false    | true     | false    | false     |
| delete    | string | false    | true     | false    | false     |
+-----------+--------+----------+----------+----------+-----------+