// Record the any config values in ComputedKeys. This field had been unused in
// helper/schema, but in the new protocol we're using this so that the SDK can
// now handle having an unknown collection. The legacy diff code doesn't
// properly handle the unknown, because it can't be expressed in the same way
// between the config and diff.
Record the any config values in ComputedKeys. This field had been unused in
helper/schema, but in the new protocol we're using this so that the SDK can
now handle having an unknown collection. The legacy diff code doesn't
properly handle the unknown, because it can't be expressed in the same way
between the config and diff.
// Record the any config values in ComputedKeys . This field had been unused in // helper / schema but in the new protocol we ' re using this so that the SDK can // now handle having an unknown collection . The legacy diff code doesn ' t // properly handle the unknown because it can ' t be expressed in the same way // between the config and diff .
func newResourceConfigShimmedComputedKeys(val cty.Value, path string) []string {
	var ret []string
	ty := val.Type()
	if val.IsNull() {
		return ret
	}
	if !val.IsKnown() {
		if len(path) > 0 {
			ret = append(ret, path)
		}
		return ret
	}
	if path != "" {
		path += "."
	}
	switch {
	case ty.IsListType(), ty.IsTupleType(), ty.IsSetType():
		i := 0
		for it := val.ElementIterator(); it.Next(); i++ {
			_, subVal := it.Element()
			keys := newResourceConfigShimmedComputedKeys(subVal, fmt.Sprintf("%s%d", path, i))
			ret = append(ret, keys...)
		}
	case ty.IsMapType(), ty.IsObjectType():
		for it := val.ElementIterator(); it.Next(); {
			subK, subVal := it.Element()
			keys := newResourceConfigShimmedComputedKeys(subVal, fmt.Sprintf("%s%s", path, subK.AsString()))
			ret = append(ret, keys...)
		}
	}
	return ret
}
func newResourceConfigShimmedComputedKeys ( val cty . Value , path string ) [ ] string { var ret [ ] string ty := val . Type ( ) if val . IsNull ( ) { return ret } if ! val . IsKnown ( ) { if len ( path ) > 0 { ret = append ( ret , path ) } return ret } if path != " " { path += " " } switch { case ty . IsListType ( ) , ty . IsTupleType ( ) , ty . IsSetType ( ) : i := 0 for it := val . ElementIterator ( ) ; it . Next ( ) ; i ++ { _ , subVal := it . Element ( ) keys := newResourceConfigShimmedComputedKeys ( subVal , fmt . Sprintf ( " " , path , i ) ) ret = append ( ret , keys ... ) } case ty . IsMapType ( ) , ty . IsObjectType ( ) : for it := val . ElementIterator ( ) ; it . Next ( ) ; { subK , subVal := it . Element ( ) keys := newResourceConfigShimmedComputedKeys ( subVal , fmt . Sprintf ( " " , path , subK . AsString ( ) ) ) ret = append ( ret , keys ... ) } } return ret }
Record the any config values in ComputedKeys.
Record the any config values in ComputedKeys .
// we shouldn't have an entirely unknown resource, but prevent empty // strings just in case