-
Notifications
You must be signed in to change notification settings - Fork 77
Description
Terraform CLI and terraform-plugin-docs Versions
$ terraform version
Terraform v1.8.3
on darwin_amd64
github.com/hashicorp/terraform-plugin-docs v0.19.3
Provider Code
func (r *exampleResource) Schema(ctx context.Context, req resource.SchemaRequest, resp *resource.SchemaResponse) {
resp.Schema = schema.Schema{
Description: "Example resource.",
Attributes: map[string]schema.Attribute{
"level_one": schema.SingleNestedAttribute{
Required: true,
Attributes: map[string]schema.Attribute{
"level_two": schema.SingleNestedAttribute{
Optional: true,
Attributes: map[string]schema.Attribute{
"level_three": schema.SingleNestedAttribute{
Optional: true,
Attributes: map[string]schema.Attribute{
"level_four_primary": schema.SingleNestedAttribute{
Attributes: map[string]schema.Attribute{
"level_four_primary_string": schema.StringAttribute{
Optional: true,
Description: "Parent should be level_one.level_two.level_three.level_four_primary.",
},
"level_five": schema.SingleNestedAttribute{
Attributes: map[string]schema.Attribute{
"level_five_string": schema.StringAttribute{
Optional: true,
Description: "Parent should be level_one.level_two.level_three.level_four_primary.level_five.",
},
},
Optional: true,
Description: "Parent should be level_one.level_two.level_three.level_four_primary.",
},
},
Optional: true,
},
"level_four_secondary": schema.StringAttribute{
Optional: true,
},
},
},
},
},
},
},
},
}
}
Expected Behavior
Labels in generated documentation should be correct, including names of parent attributes up the chain
Actual Behavior
Links in the generated example.md
file go to the right place, but the labels of the sections can be wrong. With this schema, one label treats an adjacent StringAttribute as if it was the parent SingleNestedAttribute.
<!-- schema generated by tfplugindocs -->
## Schema
### Required
- `level_one` (Attributes) (see [below for nested schema](#nestedatt--level_one))
<a id="nestedatt--level_one"></a>
### Nested Schema for `level_one`
Optional:
- `level_two` (Attributes) (see [below for nested schema](#nestedatt--level_one--level_two))
<a id="nestedatt--level_one--level_two"></a>
### Nested Schema for `level_one.level_two`
Optional:
- `level_three` (Attributes) (see [below for nested schema](#nestedatt--level_one--level_two--level_three))
<a id="nestedatt--level_one--level_two--level_three"></a>
### Nested Schema for `level_one.level_two.level_three`
Optional:
- `level_four_primary` (Attributes) (see [below for nested schema](#nestedatt--level_one--level_two--level_three--level_four_primary))
- `level_four_secondary` (String)
<a id="nestedatt--level_one--level_two--level_three--level_four_primary"></a>
### Nested Schema for `level_one.level_two.level_three.level_four_primary`
Optional:
- `level_five` (Attributes) Parent should be level_one.level_two.level_three.level_four_primary. (see [below for nested schema](#nestedatt--level_one--level_two--level_three--level_four_secondary--level_five))
- `level_four_primary_string` (String) Parent should be level_one.level_two.level_three.level_four_primary.
<a id="nestedatt--level_one--level_two--level_three--level_four_secondary--level_five"></a>
### Nested Schema for `level_one.level_two.level_three.level_four_secondary.level_five`
Optional:
- `level_five_string` (String) Parent should be level_one.level_two.level_three.level_four_primary.level_five.
Note the "Nested Schema for level_one.level_two.level_three.level_four_secondary.level_five
": that level_four_secondary
attribute is just a string, it can't have child attributes, yet the generated doc includes it as a parent in the label for the nested schema.
I'm not sure whether or not this is the simplest schema to reproduce this issue. I tried several variations. It seems that this can happen under ListNested attributes as well at minimum. I tried reducing the nesting from the amount in my example here but then the bug stopped occurring, so it may somehow be related to very deep nesting.
Steps to Reproduce
tfplugindocs generate
with a provider with a resource with the given schema
The code I copied here as well as the generated markdown can also be viewed in the DocsBug branch linked here - https://github.com/henryrecker-pingidentity/terraform-provider-example/tree/DocsBug
How much impact is this issue causing?
Medium
Logs
No response
Additional Information
No response
Code of Conduct
- I agree to follow this project's Code of Conduct