[codegen/python] Allow setting constant values for props (#4864)
* Allow setting constant values for props * PR feedback
This commit is contained in:
parent
9a62c92efc
commit
1837c0a779
|
@ -465,6 +465,8 @@ func (mod *modContext) genResource(res *schema.Resource) (string, error) {
|
|||
ins := stringSet{}
|
||||
for _, prop := range res.InputProperties {
|
||||
pname := PyName(prop.Name)
|
||||
var arg interface{}
|
||||
var err error
|
||||
|
||||
// Fill in computed defaults for arguments.
|
||||
if prop.DefaultValue != nil {
|
||||
|
@ -491,7 +493,14 @@ func (mod *modContext) genResource(res *schema.Resource) (string, error) {
|
|||
}
|
||||
|
||||
// And add it to the dictionary.
|
||||
arg := pname
|
||||
arg = pname
|
||||
|
||||
if prop.ConstValue != nil {
|
||||
arg, err = getConstValue(prop.ConstValue)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
}
|
||||
|
||||
// If this resource is a provider then, regardless of the schema of the underlying provider
|
||||
// type, we must project all properties as strings. For all properties that are not strings,
|
||||
|
@ -1205,6 +1214,13 @@ func getPrimitiveValue(value interface{}) (string, error) {
|
|||
}
|
||||
}
|
||||
|
||||
func getConstValue(cv interface{}) (string, error) {
|
||||
if cv == nil {
|
||||
return "", nil
|
||||
}
|
||||
return getPrimitiveValue(cv)
|
||||
}
|
||||
|
||||
func getDefaultValue(dv *schema.DefaultValue, t schema.Type) (string, error) {
|
||||
defaultValue := ""
|
||||
if dv.Value != nil {
|
||||
|
|
Loading…
Reference in a new issue