Skip to content

Commit e36f96d

Browse files
authored
generate: Add hyperlinks to user documentation and version callouts for write-only attribute documentation (#451)
* Add link to write-only user documentation in markdown * Add write-only version callout to all relevant sections
1 parent 80d1c8e commit e36f96d

10 files changed

+92
-15
lines changed

cmd/tfplugindocs/testdata/scripts/schema-json/generate/framework_provider_success_all_framework_types.txtar

+16-1
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,16 @@ example resource
6767
<!-- schema generated by tfplugindocs -->
6868
## Schema
6969

70+
### Required
71+
72+
> **NOTE**: [Write-only arguments](https://developer.hashicorp.com/terraform/language/resources/ephemeral#write-only-arguments) are supported in Terraform 1.11 and later.
73+
74+
- `required_write_only_string_attribute` (String, [Write-only](https://developer.hashicorp.com/terraform/language/resources/ephemeral#write-only-arguments)) example required write-only string attribute
75+
7076
### Optional
7177

78+
> **NOTE**: [Write-only arguments](https://developer.hashicorp.com/terraform/language/resources/ephemeral#write-only-arguments) are supported in Terraform 1.11 and later.
79+
7280
- `bool_attribute` (Boolean) example bool attribute
7381
- `float64_attribute` (Number) example float64 attribute
7482
- `int64_attribute` (Number) example int64 attribute
@@ -93,7 +101,7 @@ example resource
93101
- `single_nested_block` (Block, Optional) example single nested block (see [below for nested schema](#nestedblock--single_nested_block))
94102
- `single_nested_block_sensitive_nested_attribute` (Block, Optional) example sensitive single nested block (see [below for nested schema](#nestedblock--single_nested_block_sensitive_nested_attribute))
95103
- `string_attribute` (String) example string attribute
96-
- `write_only_string_attribute` (String, Write-only) example write-only string attribute
104+
- `write_only_string_attribute` (String, [Write-only](https://developer.hashicorp.com/terraform/language/resources/ephemeral#write-only-arguments)) example write-only string attribute
97105

98106
### Read-Only
99107

@@ -426,6 +434,13 @@ scaffolding(stringInput string, boolInput bool, float64Input number, int64Input
426434
"description_kind": "markdown",
427435
"optional": true,
428436
"write_only": true
437+
},
438+
"required_write_only_string_attribute": {
439+
"type": "string",
440+
"description": "example required write-only string attribute",
441+
"description_kind": "markdown",
442+
"required": true,
443+
"write_only": true
429444
}
430445
},
431446
"block_types": {

internal/schemamd/behaviors.go

+21
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ func childAttributeIsRequired(att *tfjson.SchemaAttribute) bool {
1111
return att.Required
1212
}
1313

14+
func childAttributeIsWriteOnly(att *tfjson.SchemaAttribute) bool {
15+
return att.WriteOnly
16+
}
17+
1418
func childBlockIsRequired(block *tfjson.SchemaBlockType) bool {
1519
return block.MinItems > 0
1620
}
@@ -77,3 +81,20 @@ func childBlockIsReadOnly(block *tfjson.SchemaBlockType) bool {
7781

7882
return true
7983
}
84+
85+
// childBlockContainsWriteOnly returns true for blocks that contain any write-only attributes.
86+
func childBlockContainsWriteOnly(block *tfjson.SchemaBlockType) bool {
87+
for _, childBlock := range block.Block.NestedBlocks {
88+
if childBlockContainsWriteOnly(childBlock) {
89+
return true
90+
}
91+
}
92+
93+
for _, childAtt := range block.Block.Attributes {
94+
if childAttributeIsWriteOnly(childAtt) {
95+
return true
96+
}
97+
}
98+
99+
return false
100+
}

internal/schemamd/render.go

+22
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,28 @@ nameLoop:
304304
return err
305305
}
306306

307+
for _, name := range sortedNames {
308+
if childBlock, ok := block.NestedBlocks[name]; ok {
309+
if childBlockContainsWriteOnly(childBlock) {
310+
_, err := io.WriteString(w,
311+
"> **NOTE**: [Write-only arguments](https://developer.hashicorp.com/terraform/language/resources/ephemeral#write-only-arguments) are supported in Terraform 1.11 and later.\n\n")
312+
if err != nil {
313+
return err
314+
}
315+
break
316+
}
317+
} else if childAtt, ok := block.Attributes[name]; ok {
318+
if childAttributeIsWriteOnly(childAtt) {
319+
_, err := io.WriteString(w,
320+
"> **NOTE**: [Write-only arguments](https://developer.hashicorp.com/terraform/language/resources/ephemeral#write-only-arguments) are supported in Terraform 1.11 and later.\n\n")
321+
if err != nil {
322+
return err
323+
}
324+
break
325+
}
326+
}
327+
}
328+
307329
for _, name := range sortedNames {
308330
path := make([]string, len(parents), len(parents)+1)
309331
copy(path, parents)

internal/schemamd/testdata/deep_nested_write_only_attributes.md

+7-7
Original file line numberDiff line numberDiff line change
@@ -13,34 +13,34 @@
1313

1414
Optional:
1515

16-
- `level_two` (Attributes, Write-only) (see [below for nested schema](#nestedatt--level_one--level_two))
16+
- `level_two` (Attributes, [Write-only](https://developer.hashicorp.com/terraform/language/resources/ephemeral#write-only-arguments)) (see [below for nested schema](#nestedatt--level_one--level_two))
1717

1818
<a id="nestedatt--level_one--level_two"></a>
1919
### Nested Schema for `level_one.level_two`
2020

2121
Optional:
2222

23-
- `level_three` (Attributes, Write-only) (see [below for nested schema](#nestedatt--level_one--level_two--level_three))
23+
- `level_three` (Attributes, [Write-only](https://developer.hashicorp.com/terraform/language/resources/ephemeral#write-only-arguments)) (see [below for nested schema](#nestedatt--level_one--level_two--level_three))
2424

2525
<a id="nestedatt--level_one--level_two--level_three"></a>
2626
### Nested Schema for `level_one.level_two.level_three`
2727

2828
Optional:
2929

30-
- `level_four_primary` (Attributes, Write-only) (see [below for nested schema](#nestedatt--level_one--level_two--level_three--level_four_primary))
31-
- `level_four_secondary` (String, Write-only)
30+
- `level_four_primary` (Attributes, [Write-only](https://developer.hashicorp.com/terraform/language/resources/ephemeral#write-only-arguments)) (see [below for nested schema](#nestedatt--level_one--level_two--level_three--level_four_primary))
31+
- `level_four_secondary` (String, [Write-only](https://developer.hashicorp.com/terraform/language/resources/ephemeral#write-only-arguments))
3232

3333
<a id="nestedatt--level_one--level_two--level_three--level_four_primary"></a>
3434
### Nested Schema for `level_one.level_two.level_three.level_four_primary`
3535

3636
Optional:
3737

38-
- `level_five` (Attributes, Write-only) 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_primary--level_five))
39-
- `level_four_primary_string` (String, Write-only) Parent should be level_one.level_two.level_three.level_four_primary.
38+
- `level_five` (Attributes, [Write-only](https://developer.hashicorp.com/terraform/language/resources/ephemeral#write-only-arguments)) 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_primary--level_five))
39+
- `level_four_primary_string` (String, [Write-only](https://developer.hashicorp.com/terraform/language/resources/ephemeral#write-only-arguments)) Parent should be level_one.level_two.level_three.level_four_primary.
4040

4141
<a id="nestedatt--level_one--level_two--level_three--level_four_primary--level_five"></a>
4242
### Nested Schema for `level_one.level_two.level_three.level_four_primary.level_five`
4343

4444
Optional:
4545

46-
- `level_five_string` (String, Write-only) Parent should be level_one.level_two.level_three.level_four_primary.level_five.
46+
- `level_five_string` (String, [Write-only](https://developer.hashicorp.com/terraform/language/resources/ephemeral#write-only-arguments)) Parent should be level_one.level_two.level_three.level_four_primary.level_five.

internal/schemamd/testdata/framework_types.md

+15-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
11
## Schema
22

3+
### Required
4+
5+
> **NOTE**: [Write-only arguments](https://developer.hashicorp.com/terraform/language/resources/ephemeral#write-only-arguments) are supported in Terraform 1.11 and later.
6+
7+
- `required_write_only_string_attribute` (String, [Write-only](https://developer.hashicorp.com/terraform/language/resources/ephemeral#write-only-arguments)) example required write-only string attribute
8+
39
### Optional
410

11+
> **NOTE**: [Write-only arguments](https://developer.hashicorp.com/terraform/language/resources/ephemeral#write-only-arguments) are supported in Terraform 1.11 and later.
12+
513
- `bool_attribute` (Boolean) example bool attribute
614
- `float64_attribute` (Number) example float64 attribute
715
- `int64_attribute` (Number) example int64 attribute
@@ -26,7 +34,7 @@
2634
- `single_nested_block` (Block, Optional) example single nested block (see [below for nested schema](#nestedblock--single_nested_block))
2735
- `single_nested_block_sensitive_nested_attribute` (Block, Optional) example sensitive single nested block (see [below for nested schema](#nestedblock--single_nested_block_sensitive_nested_attribute))
2836
- `string_attribute` (String) example string attribute
29-
- `write_only_string_attribute` (String, Write-only) example write only string attribute
37+
- `write_only_string_attribute` (String, [Write-only](https://developer.hashicorp.com/terraform/language/resources/ephemeral#write-only-arguments)) example write only string attribute
3038

3139
### Read-Only
3240

@@ -38,9 +46,11 @@
3846

3947
Optional:
4048

49+
> **NOTE**: [Write-only arguments](https://developer.hashicorp.com/terraform/language/resources/ephemeral#write-only-arguments) are supported in Terraform 1.11 and later.
50+
4151
- `list_nested_block_attribute` (String) example list nested block attribute
4252
- `list_nested_block_attribute_with_default` (String) example list nested block attribute with default
43-
- `list_nested_block_write_only_attribute` (String, Write-only) example list nested block write-only attribute
53+
- `list_nested_block_write_only_attribute` (String, [Write-only](https://developer.hashicorp.com/terraform/language/resources/ephemeral#write-only-arguments)) example list nested block write-only attribute
4454
- `nested_list_block` (Block List) (see [below for nested schema](#nestedblock--list_nested_block--nested_list_block))
4555

4656
<a id="nestedblock--list_nested_block--nested_list_block"></a>
@@ -99,8 +109,10 @@ Optional:
99109

100110
Optional:
101111

112+
> **NOTE**: [Write-only arguments](https://developer.hashicorp.com/terraform/language/resources/ephemeral#write-only-arguments) are supported in Terraform 1.11 and later.
113+
102114
- `set_nested_block_attribute` (String) example set nested block attribute
103-
- `set_nested_block_write_only_attribute` (String, Write-only) example set nested block write-only attribute
115+
- `set_nested_block_write_only_attribute` (String, [Write-only](https://developer.hashicorp.com/terraform/language/resources/ephemeral#write-only-arguments)) example set nested block write-only attribute
104116

105117

106118
<a id="nestedblock--single_nested_block"></a>

internal/schemamd/testdata/framework_types.schema.json

+7
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,13 @@
175175
"description_kind": "markdown",
176176
"optional": true,
177177
"write_only": true
178+
},
179+
"required_write_only_string_attribute": {
180+
"type": "string",
181+
"description": "example required write-only string attribute",
182+
"description_kind": "markdown",
183+
"required": true,
184+
"write_only": true
178185
}
179186
},
180187
"block_types": {

internal/schemamd/write_attribute_description.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ func WriteAttributeDescription(w io.Writer, att *tfjson.SchemaAttribute, include
5959
}
6060

6161
if att.WriteOnly {
62-
_, err := io.WriteString(w, ", Write-only")
62+
_, err := io.WriteString(w, ", [Write-only](https://developer.hashicorp.com/terraform/language/resources/ephemeral#write-only-arguments)")
6363
if err != nil {
6464
return err
6565
}

internal/schemamd/write_attribute_description_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ func TestWriteAttributeDescription(t *testing.T) {
3131
},
3232
},
3333
{
34-
"(String, Required, Write-only) This is an attribute.",
34+
"(String, Required, [Write-only](https://developer.hashicorp.com/terraform/language/resources/ephemeral#write-only-arguments)) This is an attribute.",
3535
&tfjson.SchemaAttribute{
3636
AttributeType: cty.String,
3737
Required: true,

internal/schemamd/write_nested_attribute_type_description.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ func WriteNestedAttributeTypeDescription(w io.Writer, att *tfjson.SchemaAttribut
9898
}
9999

100100
if att.WriteOnly {
101-
_, err := io.WriteString(w, ", Write-only")
101+
_, err := io.WriteString(w, ", [Write-only](https://developer.hashicorp.com/terraform/language/resources/ephemeral#write-only-arguments)")
102102
if err != nil {
103103
return err
104104
}

internal/schemamd/write_nested_attribute_type_description_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ func TestWriteNestedAttributeTypeDescription(t *testing.T) {
3939
},
4040
},
4141
{
42-
"(Attributes, Optional, Write-only) This is an attribute.",
42+
"(Attributes, Optional, [Write-only](https://developer.hashicorp.com/terraform/language/resources/ephemeral#write-only-arguments)) This is an attribute.",
4343
&tfjson.SchemaAttribute{
4444
Description: "This is an attribute.",
4545
AttributeNestedType: &tfjson.SchemaNestedAttributeType{

0 commit comments

Comments
 (0)