MCPcopy Index your code
hub / github.com/coder/coder / CtyValueString

Function CtyValueString

provisioner/terraform/tfparse/tfparse.go:555–576  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

553// It supports only primitive types - bool, number, and string.
554// As a special case, it also supports map[string]interface{} with key "value".
555func 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
578func interfaceToString(i interface{}) (string, error) {
579 switch v := i.(type) {

Callers 3

evaluateWorkspaceTagsFunction · 0.85

Calls 3

TypeMethod · 0.65
StringMethod · 0.45
ErrorfMethod · 0.45

Tested by

no test coverage detected