|
| 1 | +package schema |
| 2 | + |
| 3 | +import ( |
| 4 | + "github.com/hashicorp/terraform-plugin-framework/attr" |
| 5 | + "github.com/hashicorp/terraform-plugin-framework/internal/fwschema" |
| 6 | + "github.com/hashicorp/terraform-plugin-framework/internal/fwschema/fwxschema" |
| 7 | + "github.com/hashicorp/terraform-plugin-framework/schema/validator" |
| 8 | + "github.com/hashicorp/terraform-plugin-framework/types" |
| 9 | + "github.com/hashicorp/terraform-plugin-go/tftypes" |
| 10 | +) |
| 11 | + |
| 12 | +// Ensure the implementation satisifies the desired interfaces. |
| 13 | +var ( |
| 14 | + _ Attribute = BoolAttribute{} |
| 15 | + _ fwxschema.AttributeWithBoolValidators = BoolAttribute{} |
| 16 | +) |
| 17 | + |
| 18 | +// BoolAttribute represents a schema attribute that is a boolean. When |
| 19 | +// retrieving the value for this attribute, use types.Bool as the value type |
| 20 | +// unless the CustomType field is set. |
| 21 | +// |
| 22 | +// Terraform configurations configure this attribute using expressions that |
| 23 | +// return a boolean or directly via the true/false keywords. |
| 24 | +// |
| 25 | +// example_attribute = true |
| 26 | +// |
| 27 | +// Terraform configurations reference this attribute using the attribute name. |
| 28 | +// |
| 29 | +// .example_attribute |
| 30 | +type BoolAttribute struct { |
| 31 | + // CustomType enables the use of a custom attribute type in place of the |
| 32 | + // default types.BoolType. When retrieving data, the types.BoolValuable |
| 33 | + // associated with this custom type must be used in place of types.Bool. |
| 34 | + CustomType types.BoolTypable |
| 35 | + |
| 36 | + // Required indicates whether the practitioner must enter a value for |
| 37 | + // this attribute or not. Required and Optional cannot both be true, |
| 38 | + // and Required and Computed cannot both be true. |
| 39 | + Required bool |
| 40 | + |
| 41 | + // Optional indicates whether the practitioner can choose to enter a value |
| 42 | + // for this attribute or not. Optional and Required cannot both be true. |
| 43 | + Optional bool |
| 44 | + |
| 45 | + // Computed indicates whether the provider may return its own value for |
| 46 | + // this Attribute or not. Required and Computed cannot both be true. If |
| 47 | + // Required and Optional are both false, Computed must be true, and the |
| 48 | + // attribute will be considered "read only" for the practitioner, with |
| 49 | + // only the provider able to set its value. |
| 50 | + Computed bool |
| 51 | + |
| 52 | + // Sensitive indicates whether the value of this attribute should be |
| 53 | + // considered sensitive data. Setting it to true will obscure the value |
| 54 | + // in CLI output. Sensitive does not impact how values are stored, and |
| 55 | + // practitioners are encouraged to store their state as if the entire |
| 56 | + // file is sensitive. |
| 57 | + Sensitive bool |
| 58 | + |
| 59 | + // Description is used in various tooling, like the language server, to |
| 60 | + // give practitioners more information about what this attribute is, |
| 61 | + // what it's for, and how it should be used. It should be written as |
| 62 | + // plain text, with no special formatting. |
| 63 | + Description string |
| 64 | + |
| 65 | + // MarkdownDescription is used in various tooling, like the |
| 66 | + // documentation generator, to give practitioners more information |
| 67 | + // about what this attribute is, what it's for, and how it should be |
| 68 | + // used. It should be formatted using Markdown. |
| 69 | + MarkdownDescription string |
| 70 | + |
| 71 | + // DeprecationMessage defines warning diagnostic details to display when |
| 72 | + // practitioner configurations use this Attribute. The warning diagnostic |
| 73 | + // summary is automatically set to "Attribute Deprecated" along with |
| 74 | + // configuration source file and line information. |
| 75 | + // |
| 76 | + // Set this field to a practitioner actionable message such as: |
| 77 | + // |
| 78 | + // - "Configure other_attribute instead. This attribute will be removed |
| 79 | + // in the next major version of the provider." |
| 80 | + // - "Remove this attribute's configuration as it no longer is used and |
| 81 | + // the attribute will be removed in the next major version of the |
| 82 | + // provider." |
| 83 | + // |
| 84 | + // In Terraform 1.2.7 and later, this warning diagnostic is displayed any |
| 85 | + // time a practitioner attempts to configure a value for this attribute and |
| 86 | + // certain scenarios where this attribute is referenced. |
| 87 | + // |
| 88 | + // In Terraform 1.2.6 and earlier, this warning diagnostic is only |
| 89 | + // displayed when the Attribute is Required or Optional, and if the |
| 90 | + // practitioner configuration sets the value to a known or unknown value |
| 91 | + // (which may eventually be null). It has no effect when the Attribute is |
| 92 | + // Computed-only (read-only; not Required or Optional). |
| 93 | + // |
| 94 | + // Across any Terraform version, there are no warnings raised for |
| 95 | + // practitioner configuration values set directly to null, as there is no |
| 96 | + // way for the framework to differentiate between an unset and null |
| 97 | + // configuration due to how Terraform sends configuration information |
| 98 | + // across the protocol. |
| 99 | + // |
| 100 | + // Additional information about deprecation enhancements for read-only |
| 101 | + // attributes can be found in: |
| 102 | + // |
| 103 | + // - https://github.com/hashicorp/terraform/issues/7569 |
| 104 | + // |
| 105 | + DeprecationMessage string |
| 106 | + |
| 107 | + // Validators define value validation functionality for the attribute. All |
| 108 | + // elements of the slice of AttributeValidator are run, regardless of any |
| 109 | + // previous error diagnostics. |
| 110 | + // |
| 111 | + // Many common use case validators can be found in the |
| 112 | + // github.com/hashicorp/terraform-plugin-framework-validators Go module. |
| 113 | + // |
| 114 | + // If the Type field points to a custom type that implements the |
| 115 | + // xattr.TypeWithValidate interface, the validators defined in this field |
| 116 | + // are run in addition to the validation defined by the type. |
| 117 | + Validators []validator.Bool |
| 118 | +} |
| 119 | + |
| 120 | +// ApplyTerraform5AttributePathStep always returns an error as it is not |
| 121 | +// possible to step further into a BoolAttribute. |
| 122 | +func (a BoolAttribute) ApplyTerraform5AttributePathStep(step tftypes.AttributePathStep) (interface{}, error) { |
| 123 | + return a.GetType().ApplyTerraform5AttributePathStep(step) |
| 124 | +} |
| 125 | + |
| 126 | +// BoolValidators returns the Validators field value. |
| 127 | +func (a BoolAttribute) BoolValidators() []validator.Bool { |
| 128 | + return a.Validators |
| 129 | +} |
| 130 | + |
| 131 | +// Equal returns true if the given Attribute is a BoolAttribute |
| 132 | +// and all fields are equal. |
| 133 | +func (a BoolAttribute) Equal(o fwschema.Attribute) bool { |
| 134 | + if _, ok := o.(BoolAttribute); !ok { |
| 135 | + return false |
| 136 | + } |
| 137 | + |
| 138 | + return fwschema.AttributesEqual(a, o) |
| 139 | +} |
| 140 | + |
| 141 | +// GetDeprecationMessage returns the DeprecationMessage field value. |
| 142 | +func (a BoolAttribute) GetDeprecationMessage() string { |
| 143 | + return a.DeprecationMessage |
| 144 | +} |
| 145 | + |
| 146 | +// GetDescription returns the Description field value. |
| 147 | +func (a BoolAttribute) GetDescription() string { |
| 148 | + return a.Description |
| 149 | +} |
| 150 | + |
| 151 | +// GetMarkdownDescription returns the MarkdownDescription field value. |
| 152 | +func (a BoolAttribute) GetMarkdownDescription() string { |
| 153 | + return a.MarkdownDescription |
| 154 | +} |
| 155 | + |
| 156 | +// GetType returns types.StringType or the CustomType field value if defined. |
| 157 | +func (a BoolAttribute) GetType() attr.Type { |
| 158 | + if a.CustomType != nil { |
| 159 | + return a.CustomType |
| 160 | + } |
| 161 | + |
| 162 | + return types.BoolType |
| 163 | +} |
| 164 | + |
| 165 | +// IsComputed returns the Computed field value. |
| 166 | +func (a BoolAttribute) IsComputed() bool { |
| 167 | + return a.Computed |
| 168 | +} |
| 169 | + |
| 170 | +// IsOptional returns the Optional field value. |
| 171 | +func (a BoolAttribute) IsOptional() bool { |
| 172 | + return a.Optional |
| 173 | +} |
| 174 | + |
| 175 | +// IsRequired returns the Required field value. |
| 176 | +func (a BoolAttribute) IsRequired() bool { |
| 177 | + return a.Required |
| 178 | +} |
| 179 | + |
| 180 | +// IsSensitive returns the Sensitive field value. |
| 181 | +func (a BoolAttribute) IsSensitive() bool { |
| 182 | + return a.Sensitive |
| 183 | +} |
0 commit comments