Move functions to conversion pkg (#123)

This commit is contained in:
Vicente Pinto 2023-11-03 08:49:05 +00:00 committed by GitHub
parent 71bf63cbc9
commit 03d0e28016
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
22 changed files with 237 additions and 221 deletions

View file

@ -57,3 +57,33 @@ func ToTerraformStringMap(ctx context.Context, m map[string]string) (basetypes.M
return res, nil
}
// StringValueToPointer converts basetypes.StringValue to a pointer to string.
// It returns nil if the value is null or unknown.
func StringValueToPointer(s basetypes.StringValue) *string {
if s.IsNull() || s.IsUnknown() {
return nil
}
value := s.ValueString()
return &value
}
// Int64ValueToPointer converts basetypes.Int64Value to a pointer to int64.
// It returns nil if the value is null or unknown.
func Int64ValueToPointer(s basetypes.Int64Value) *int64 {
if s.IsNull() || s.IsUnknown() {
return nil
}
value := s.ValueInt64()
return &value
}
// BoolValueToPointer converts basetypes.BoolValue to a pointer to bool.
// It returns nil if the value is null or unknown.
func BoolValueToPointer(s basetypes.BoolValue) *bool {
if s.IsNull() || s.IsUnknown() {
return nil
}
value := s.ValueBool()
return &value
}