mirror of
https://github.com/letic/terraform-provider-google.git
synced 2024-09-07 09:36:44 +00:00
![Riley Karson](/assets/img/avatar_default.png)
```bash GO111MODULE=on go get github.com/hashicorp/terraform@pluginsdk-v0.12-early7 GO111MODULE=on go mod vendor GO111MODULE=on go mod tidy ```
49 lines
1.1 KiB
Go
49 lines
1.1 KiB
Go
package convert
|
|
|
|
import (
|
|
"github.com/zclconf/go-cty/cty"
|
|
)
|
|
|
|
var stringTrue = cty.StringVal("true")
|
|
var stringFalse = cty.StringVal("false")
|
|
|
|
var primitiveConversionsSafe = map[cty.Type]map[cty.Type]conversion{
|
|
cty.Number: {
|
|
cty.String: func(val cty.Value, path cty.Path) (cty.Value, error) {
|
|
f := val.AsBigFloat()
|
|
return cty.StringVal(f.Text('f', -1)), nil
|
|
},
|
|
},
|
|
cty.Bool: {
|
|
cty.String: func(val cty.Value, path cty.Path) (cty.Value, error) {
|
|
if val.True() {
|
|
return stringTrue, nil
|
|
} else {
|
|
return stringFalse, nil
|
|
}
|
|
},
|
|
},
|
|
}
|
|
|
|
var primitiveConversionsUnsafe = map[cty.Type]map[cty.Type]conversion{
|
|
cty.String: {
|
|
cty.Number: func(val cty.Value, path cty.Path) (cty.Value, error) {
|
|
v, err := cty.ParseNumberVal(val.AsString())
|
|
if err != nil {
|
|
return cty.NilVal, path.NewErrorf("a number is required")
|
|
}
|
|
return v, nil
|
|
},
|
|
cty.Bool: func(val cty.Value, path cty.Path) (cty.Value, error) {
|
|
switch val.AsString() {
|
|
case "true", "1":
|
|
return cty.True, nil
|
|
case "false", "0":
|
|
return cty.False, nil
|
|
default:
|
|
return cty.NilVal, path.NewErrorf("a bool is required")
|
|
}
|
|
},
|
|
},
|
|
}
|