From 9d0614278785cf746ec2b3826c90ea0e92fca77d Mon Sep 17 00:00:00 2001 From: Noah Stride Date: Tue, 30 Apr 2024 14:09:40 +0100 Subject: [PATCH] Better document fixed boolopt helpers --- terraform/tfschema/token/custom_types.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/terraform/tfschema/token/custom_types.go b/terraform/tfschema/token/custom_types.go index 26f77dafa..2f2dcae94 100644 --- a/terraform/tfschema/token/custom_types.go +++ b/terraform/tfschema/token/custom_types.go @@ -18,7 +18,9 @@ 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, @@ -26,6 +28,8 @@ func GenSchemaBoolOptionFixed(_ context.Context) tfsdk.Attribute { } } +// 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 { @@ -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 { @@ -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