@@ -199,11 +199,13 @@ type Schema struct {
199
199
RequiredWith []string
200
200
201
201
// ConditionsMode specifies the behavior of the SDK when one of the
202
- // above conditions are met. (ConflictsWith, ExactlyOneOf, etc).
203
- // When set to WARNING, a warning message is displayed to the user.
204
- // When set to ERROR (default), a fatal error is returned.
205
- // Optionally, a message can be returned with the warning or error.
206
- ConditionsMode string
202
+ // above conditions are met (ConflictsWith, ExactlyOneOf, etc).
203
+ // The default value is SchemaConditionsModeError, which returns an error.
204
+ // Set ConditionsMode to SchemaConditionsModeWarning to return a warning instead.
205
+ //
206
+ // ConditionsModeMessage can optionally be used to display a message
207
+ // to the user when one of the above conditions are met.
208
+ ConditionsMode SchemaConditionsMode
207
209
ConditionsMessage string
208
210
209
211
// When Deprecated is set, this attribute is deprecated.
@@ -263,6 +265,13 @@ const (
263
265
SchemaConfigModeBlock
264
266
)
265
267
268
+ type SchemaConditionsMode uint8
269
+
270
+ const (
271
+ SchemaConditionsModeError SchemaConditionsMode = 0
272
+ SchemaConditionsModeWarning SchemaConditionsMode = 1
273
+ )
274
+
266
275
// SchemaDiffSuppressFunc is a function which can be used to determine
267
276
// whether a detected diff on a schema element is "valid" or not, and
268
277
// suppress it from the plan if necessary.
@@ -1457,17 +1466,10 @@ func (m schemaMap) validate(
1457
1466
ok = raw != nil
1458
1467
}
1459
1468
1460
- var conditionsMode diag.Severity
1461
- if schema .ConditionsMode == strings .ToLower ("warning" ) {
1462
- conditionsMode = diag .Warning
1463
- } else {
1464
- conditionsMode = diag .Error
1465
- }
1466
-
1467
1469
err := validateExactlyOneAttribute (k , schema , c )
1468
1470
if err != nil {
1469
1471
return append (diags , diag.Diagnostic {
1470
- Severity : conditionsMode ,
1472
+ Severity : diag . Severity ( schema . ConditionsMode ) ,
1471
1473
Summary : "ExactlyOne" ,
1472
1474
Detail : fmt .Sprintf ("%s %s" , schema .ConditionsMessage , err .Error ()),
1473
1475
AttributePath : path ,
@@ -1477,7 +1479,7 @@ func (m schemaMap) validate(
1477
1479
err = validateAtLeastOneAttribute (k , schema , c )
1478
1480
if err != nil {
1479
1481
return append (diags , diag.Diagnostic {
1480
- Severity : conditionsMode ,
1482
+ Severity : diag . Severity ( schema . ConditionsMode ) ,
1481
1483
Summary : "AtLeastOne" ,
1482
1484
Detail : fmt .Sprintf ("%s %s" , schema .ConditionsMessage , err .Error ()),
1483
1485
AttributePath : path ,
@@ -1509,7 +1511,7 @@ func (m schemaMap) validate(
1509
1511
err = validateRequiredWithAttribute (k , schema , c )
1510
1512
if err != nil {
1511
1513
return append (diags , diag.Diagnostic {
1512
- Severity : conditionsMode ,
1514
+ Severity : diag . Severity ( schema . ConditionsMode ) ,
1513
1515
Summary : "RequiredWith" ,
1514
1516
Detail : fmt .Sprintf ("%s %s" , schema .ConditionsMessage , err .Error ()),
1515
1517
AttributePath : path ,
@@ -1536,7 +1538,7 @@ func (m schemaMap) validate(
1536
1538
err = validateConflictingAttributes (k , schema , c )
1537
1539
if err != nil {
1538
1540
return append (diags , diag.Diagnostic {
1539
- Severity : conditionsMode ,
1541
+ Severity : diag . Severity ( schema . ConditionsMode ) ,
1540
1542
Summary : "ConflictsWith" ,
1541
1543
Detail : fmt .Sprintf ("%s %s" , schema .ConditionsMessage , err .Error ()),
1542
1544
AttributePath : path ,
0 commit comments