Skip to content
This repository has been archived by the owner on Jun 4, 2024. It is now read-only.

Commit

Permalink
Better document fixed boolopt helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
strideynet committed Apr 30, 2024
1 parent 2226c9d commit 9d06142
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion terraform/tfschema/token/custom_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,18 @@ func GenSchemaLabels(ctx context.Context) tfsdk.Attribute {
return tfschema.GenSchemaLabels(ctx)
}

// GenSchemaBoolOptionsFixed returns Terraform schema for BoolOption type
// GenSchemaBoolOptionFixed returns Terraform schema for BoolOption type.
// This differs from the original GenSchemaBoolOption in that it is fixed
// to handle the case where the value is not set.
func GenSchemaBoolOptionFixed(_ context.Context) tfsdk.Attribute {
return tfsdk.Attribute{
Optional: true,
Type: types.BoolType,
}
}

// CopyFromBoolOptionFixed converts the tfschema Bool value to a Teleport
// BoolOption value.
func CopyFromBoolOptionFixed(diags diag.Diagnostics, tf attr.Value, o **apitypes.BoolOption) {
v, ok := tf.(types.Bool)
if !ok {
Expand All @@ -39,6 +43,8 @@ func CopyFromBoolOptionFixed(diags diag.Diagnostics, tf attr.Value, o **apitypes
}
}

// CopyToBoolOptionFixed converts the Teleport BoolOption value to a tfschema
// Bool value.
func CopyToBoolOptionFixed(diags diag.Diagnostics, o *apitypes.BoolOption, t attr.Type, v attr.Value) attr.Value {
value, ok := v.(types.Bool)
if !ok {
Expand All @@ -50,6 +56,7 @@ func CopyToBoolOptionFixed(diags diag.Diagnostics, o *apitypes.BoolOption, t att
return value
}

value.Null = false
value.Value = o.Value

return value
Expand Down

0 comments on commit 9d06142

Please sign in to comment.