CtyValueString converts a cty.Value to a string. It supports only primitive types - bool, number, and string. As a special case, it also supports map[string]interface{} with key "value".
(val cty.Value)
| 553 | // It supports only primitive types - bool, number, and string. |
| 554 | // As a special case, it also supports map[string]interface{} with key "value". |
| 555 | func CtyValueString(val cty.Value) (string, error) { |
| 556 | switch val.Type() { |
| 557 | case cty.Bool: |
| 558 | if val.True() { |
| 559 | return "true", nil |
| 560 | } |
| 561 | return "false", nil |
| 562 | case cty.Number: |
| 563 | return val.AsBigFloat().String(), nil |
| 564 | case cty.String: |
| 565 | return val.AsString(), nil |
| 566 | // We may also have a map[string]interface{} with key "value". |
| 567 | case cty.Map(cty.String): |
| 568 | valval, ok := val.AsValueMap()["value"] |
| 569 | if !ok { |
| 570 | return "", xerrors.Errorf("map does not have key 'value'") |
| 571 | } |
| 572 | return CtyValueString(valval) |
| 573 | default: |
| 574 | return "", xerrors.Errorf("only primitive types are supported - bool, number, and string") |
| 575 | } |
| 576 | } |
| 577 | |
| 578 | func interfaceToString(i interface{}) (string, error) { |
| 579 | switch v := i.(type) { |
no test coverage detected