-
Notifications
You must be signed in to change notification settings - Fork 77
Expand file tree
/
Copy pathwrite_attribute_description.go
More file actions
82 lines (70 loc) · 1.48 KB
/
write_attribute_description.go
File metadata and controls
82 lines (70 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
package schemamd
import (
"fmt"
"io"
"strings"
tfjson "github.com/hashicorp/terraform-json"
)
func WriteAttributeDescription(w io.Writer, att *tfjson.SchemaAttribute, includeRW bool) error {
_, err := io.WriteString(w, "(")
if err != nil {
return err
}
err = WriteType(w, att.AttributeType)
if err != nil {
return err
}
if includeRW {
switch {
case childAttributeIsRequired(att):
_, err = io.WriteString(w, ", Required")
if err != nil {
return err
}
case childAttributeIsOptional(att):
_, err = io.WriteString(w, ", Optional")
if err != nil {
return err
}
case childAttributeIsReadOnly(att):
_, err = io.WriteString(w, ", Read-only")
if err != nil {
return err
}
default:
return fmt.Errorf("attribute does not match any filter states")
}
}
if att.Sensitive {
_, err := io.WriteString(w, ", Sensitive")
if err != nil {
return err
}
}
if att.Deprecated {
_, err := io.WriteString(w, ", Deprecated")
if err != nil {
return err
}
}
if att.WriteOnly {
_, err := io.WriteString(w, ", [Write-only](https://developer.hashicorp.com/terraform/language/resources/ephemeral#write-only-arguments)")
if err != nil {
return err
}
}
_, err = io.WriteString(w, ")")
if err != nil {
return err
}
desc := strings.TrimSpace(att.Description)
if desc != "" {
_, err = io.WriteString(w, " "+desc)
if err != nil {
return err
}
}
return nil
}