diff --git a/changelog/pending/20221209--sdk-go--add-jsonmarshal-to-go-sdk.yaml b/changelog/pending/20221209--sdk-go--add-jsonmarshal-to-go-sdk.yaml new file mode 100644 index 000000000000..cccb0544fcdb --- /dev/null +++ b/changelog/pending/20221209--sdk-go--add-jsonmarshal-to-go-sdk.yaml @@ -0,0 +1,4 @@ +changes: +- type: feat + scope: sdk/go + description: Add JSONMarshal to go sdk. diff --git a/sdk/go/pulumi/generate/templates/types_builtins.go.template b/sdk/go/pulumi/generate/templates/types_builtins.go.template index 5ac68f4f2a83..925b96e08f2c 100644 --- a/sdk/go/pulumi/generate/templates/types_builtins.go.template +++ b/sdk/go/pulumi/generate/templates/types_builtins.go.template @@ -19,6 +19,7 @@ package pulumi import ( "context" + "fmt" "reflect" ) @@ -55,6 +56,7 @@ func {{.Name}}FromPtr(v *{{.ElemElementType}}) {{.Name}}Input { } {{end}} {{if .DefineInputMethods}} + // ElementType returns the element type of this Input ({{.ElementType}}). func ({{.InputType}}) ElementType() reflect.Type { return {{.Name | Unexported}}Type @@ -92,6 +94,10 @@ func (in {{.InputType}}) To{{.Name}}PtrOutputWithContext(ctx context.Context) {{ // {{.Name}}Output is an Output that returns {{.ElementType}} values. type {{.Name}}Output struct { *OutputState } +func ({{.Name}}Output) MarshalJSON() ([]byte, error) { + return nil, fmt.Errorf("Outputs can not be marshaled to JSON") +} + // ElementType returns the element type of this Output ({{.ElementType}}). func ({{.Name}}Output) ElementType() reflect.Type { return {{.Name | Unexported}}Type diff --git a/sdk/go/pulumi/types.go b/sdk/go/pulumi/types.go index 2b8ce0a10234..305c76e8b2f5 100644 --- a/sdk/go/pulumi/types.go +++ b/sdk/go/pulumi/types.go @@ -17,6 +17,7 @@ package pulumi import ( "context" + "encoding/json" "errors" "fmt" "reflect" @@ -602,6 +603,23 @@ func AllWithContext(ctx context.Context, inputs ...interface{}) ArrayOutput { return ToOutputWithContext(ctx, inputs).(ArrayOutput) } +// JSONMarshal uses "encoding/json".Marshal to serialize the given Output value into a JSON string. +func JSONMarshal(v interface{}) StringOutput { + return JSONMarshalWithContext(context.Background(), v) +} + +// JSONMarshalWithContext uses "encoding/json".Marshal to serialize the given Output value into a JSON string. +func JSONMarshalWithContext(ctx context.Context, v interface{}) StringOutput { + o := ToOutputWithContext(ctx, v) + return o.ApplyTWithContext(ctx, func(_ context.Context, v interface{}) (string, error) { + json, err := json.Marshal(v) + if err != nil { + return "", err + } + return string(json), nil + }).(StringOutput) +} + func gatherJoins(v interface{}) workGroups { if v == nil { return nil @@ -1065,6 +1083,10 @@ func anyWithContext(ctx context.Context, join *workGroup, v interface{}) AnyOutp type AnyOutput struct{ *OutputState } +func (AnyOutput) MarshalJSON() ([]byte, error) { + return nil, fmt.Errorf("Outputs can not be marshaled to JSON") +} + func (AnyOutput) ElementType() reflect.Type { return anyType } @@ -1129,6 +1151,10 @@ func convert(v interface{}, to reflect.Type) interface{} { // TODO: ResourceOutput and the init() should probably be code generated. type ResourceOutput struct{ *OutputState } +func (ResourceOutput) MarshalJSON() ([]byte, error) { + return nil, fmt.Errorf("Outputs can not be marshaled to JSON") +} + // ElementType returns the element type of this Output (Resource). func (ResourceOutput) ElementType() reflect.Type { return reflect.TypeOf((*Resource)(nil)).Elem() @@ -1192,6 +1218,10 @@ func (in ResourceArray) ToResourceArrayOutputWithContext(ctx context.Context) Re // ResourceArrayOutput is an Output that returns []Resource values. type ResourceArrayOutput struct{ *OutputState } +func (ResourceArrayOutput) MarshalJSON() ([]byte, error) { + return nil, fmt.Errorf("Outputs can not be marshaled to JSON") +} + // ElementType returns the element type of this Output ([]Resource). func (ResourceArrayOutput) ElementType() reflect.Type { return resourceArrayType diff --git a/sdk/go/pulumi/types_builtins.go b/sdk/go/pulumi/types_builtins.go index 868c49c4ecbd..86b4a46648d1 100644 --- a/sdk/go/pulumi/types_builtins.go +++ b/sdk/go/pulumi/types_builtins.go @@ -19,6 +19,7 @@ package pulumi import ( "context" + "fmt" "reflect" ) @@ -56,6 +57,10 @@ func (in *archive) ToAssetOrArchiveOutputWithContext(ctx context.Context) AssetO // ArchiveOutput is an Output that returns Archive values. type ArchiveOutput struct{ *OutputState } +func (ArchiveOutput) MarshalJSON() ([]byte, error) { + return nil, fmt.Errorf("Outputs can not be marshaled to JSON") +} + // ElementType returns the element type of this Output (Archive). func (ArchiveOutput) ElementType() reflect.Type { return archiveType @@ -108,6 +113,10 @@ func (in ArchiveArray) ToArchiveArrayOutputWithContext(ctx context.Context) Arch // ArchiveArrayOutput is an Output that returns []Archive values. type ArchiveArrayOutput struct{ *OutputState } +func (ArchiveArrayOutput) MarshalJSON() ([]byte, error) { + return nil, fmt.Errorf("Outputs can not be marshaled to JSON") +} + // ElementType returns the element type of this Output ([]Archive). func (ArchiveArrayOutput) ElementType() reflect.Type { return archiveArrayType @@ -180,6 +189,10 @@ func (in ArchiveMap) ToArchiveMapOutputWithContext(ctx context.Context) ArchiveM // ArchiveMapOutput is an Output that returns map[string]Archive values. type ArchiveMapOutput struct{ *OutputState } +func (ArchiveMapOutput) MarshalJSON() ([]byte, error) { + return nil, fmt.Errorf("Outputs can not be marshaled to JSON") +} + // ElementType returns the element type of this Output (map[string]Archive). func (ArchiveMapOutput) ElementType() reflect.Type { return archiveMapType @@ -245,6 +258,10 @@ func (in ArchiveArrayMap) ToArchiveArrayMapOutputWithContext(ctx context.Context // ArchiveArrayMapOutput is an Output that returns map[string][]Archive values. type ArchiveArrayMapOutput struct{ *OutputState } +func (ArchiveArrayMapOutput) MarshalJSON() ([]byte, error) { + return nil, fmt.Errorf("Outputs can not be marshaled to JSON") +} + // ElementType returns the element type of this Output (map[string][]Archive). func (ArchiveArrayMapOutput) ElementType() reflect.Type { return archiveArrayMapType @@ -310,6 +327,10 @@ func (in ArchiveMapArray) ToArchiveMapArrayOutputWithContext(ctx context.Context // ArchiveMapArrayOutput is an Output that returns []map[string]Archive values. type ArchiveMapArrayOutput struct{ *OutputState } +func (ArchiveMapArrayOutput) MarshalJSON() ([]byte, error) { + return nil, fmt.Errorf("Outputs can not be marshaled to JSON") +} + // ElementType returns the element type of this Output ([]map[string]Archive). func (ArchiveMapArrayOutput) ElementType() reflect.Type { return archiveMapArrayType @@ -382,6 +403,10 @@ func (in ArchiveMapMap) ToArchiveMapMapOutputWithContext(ctx context.Context) Ar // ArchiveMapMapOutput is an Output that returns map[string]map[string]Archive values. type ArchiveMapMapOutput struct{ *OutputState } +func (ArchiveMapMapOutput) MarshalJSON() ([]byte, error) { + return nil, fmt.Errorf("Outputs can not be marshaled to JSON") +} + // ElementType returns the element type of this Output (map[string]map[string]Archive). func (ArchiveMapMapOutput) ElementType() reflect.Type { return archiveMapMapType @@ -447,6 +472,10 @@ func (in ArchiveArrayArray) ToArchiveArrayArrayOutputWithContext(ctx context.Con // ArchiveArrayArrayOutput is an Output that returns [][]Archive values. type ArchiveArrayArrayOutput struct{ *OutputState } +func (ArchiveArrayArrayOutput) MarshalJSON() ([]byte, error) { + return nil, fmt.Errorf("Outputs can not be marshaled to JSON") +} + // ElementType returns the element type of this Output ([][]Archive). func (ArchiveArrayArrayOutput) ElementType() reflect.Type { return archiveArrayArrayType @@ -524,6 +553,10 @@ func (in *asset) ToAssetOrArchiveOutputWithContext(ctx context.Context) AssetOrA // AssetOutput is an Output that returns Asset values. type AssetOutput struct{ *OutputState } +func (AssetOutput) MarshalJSON() ([]byte, error) { + return nil, fmt.Errorf("Outputs can not be marshaled to JSON") +} + // ElementType returns the element type of this Output (Asset). func (AssetOutput) ElementType() reflect.Type { return assetType @@ -576,6 +609,10 @@ func (in AssetArray) ToAssetArrayOutputWithContext(ctx context.Context) AssetArr // AssetArrayOutput is an Output that returns []Asset values. type AssetArrayOutput struct{ *OutputState } +func (AssetArrayOutput) MarshalJSON() ([]byte, error) { + return nil, fmt.Errorf("Outputs can not be marshaled to JSON") +} + // ElementType returns the element type of this Output ([]Asset). func (AssetArrayOutput) ElementType() reflect.Type { return assetArrayType @@ -648,6 +685,10 @@ func (in AssetMap) ToAssetMapOutputWithContext(ctx context.Context) AssetMapOutp // AssetMapOutput is an Output that returns map[string]Asset values. type AssetMapOutput struct{ *OutputState } +func (AssetMapOutput) MarshalJSON() ([]byte, error) { + return nil, fmt.Errorf("Outputs can not be marshaled to JSON") +} + // ElementType returns the element type of this Output (map[string]Asset). func (AssetMapOutput) ElementType() reflect.Type { return assetMapType @@ -713,6 +754,10 @@ func (in AssetArrayMap) ToAssetArrayMapOutputWithContext(ctx context.Context) As // AssetArrayMapOutput is an Output that returns map[string][]Asset values. type AssetArrayMapOutput struct{ *OutputState } +func (AssetArrayMapOutput) MarshalJSON() ([]byte, error) { + return nil, fmt.Errorf("Outputs can not be marshaled to JSON") +} + // ElementType returns the element type of this Output (map[string][]Asset). func (AssetArrayMapOutput) ElementType() reflect.Type { return assetArrayMapType @@ -778,6 +823,10 @@ func (in AssetMapArray) ToAssetMapArrayOutputWithContext(ctx context.Context) As // AssetMapArrayOutput is an Output that returns []map[string]Asset values. type AssetMapArrayOutput struct{ *OutputState } +func (AssetMapArrayOutput) MarshalJSON() ([]byte, error) { + return nil, fmt.Errorf("Outputs can not be marshaled to JSON") +} + // ElementType returns the element type of this Output ([]map[string]Asset). func (AssetMapArrayOutput) ElementType() reflect.Type { return assetMapArrayType @@ -850,6 +899,10 @@ func (in AssetMapMap) ToAssetMapMapOutputWithContext(ctx context.Context) AssetM // AssetMapMapOutput is an Output that returns map[string]map[string]Asset values. type AssetMapMapOutput struct{ *OutputState } +func (AssetMapMapOutput) MarshalJSON() ([]byte, error) { + return nil, fmt.Errorf("Outputs can not be marshaled to JSON") +} + // ElementType returns the element type of this Output (map[string]map[string]Asset). func (AssetMapMapOutput) ElementType() reflect.Type { return assetMapMapType @@ -915,6 +968,10 @@ func (in AssetArrayArray) ToAssetArrayArrayOutputWithContext(ctx context.Context // AssetArrayArrayOutput is an Output that returns [][]Asset values. type AssetArrayArrayOutput struct{ *OutputState } +func (AssetArrayArrayOutput) MarshalJSON() ([]byte, error) { + return nil, fmt.Errorf("Outputs can not be marshaled to JSON") +} + // ElementType returns the element type of this Output ([][]Asset). func (AssetArrayArrayOutput) ElementType() reflect.Type { return assetArrayArrayType @@ -971,6 +1028,10 @@ type AssetOrArchiveInput interface { // AssetOrArchiveOutput is an Output that returns AssetOrArchive values. type AssetOrArchiveOutput struct{ *OutputState } +func (AssetOrArchiveOutput) MarshalJSON() ([]byte, error) { + return nil, fmt.Errorf("Outputs can not be marshaled to JSON") +} + // ElementType returns the element type of this Output (AssetOrArchive). func (AssetOrArchiveOutput) ElementType() reflect.Type { return assetOrArchiveType @@ -1013,6 +1074,10 @@ func (in AssetOrArchiveArray) ToAssetOrArchiveArrayOutputWithContext(ctx context // AssetOrArchiveArrayOutput is an Output that returns []AssetOrArchive values. type AssetOrArchiveArrayOutput struct{ *OutputState } +func (AssetOrArchiveArrayOutput) MarshalJSON() ([]byte, error) { + return nil, fmt.Errorf("Outputs can not be marshaled to JSON") +} + // ElementType returns the element type of this Output ([]AssetOrArchive). func (AssetOrArchiveArrayOutput) ElementType() reflect.Type { return assetOrArchiveArrayType @@ -1069,6 +1134,10 @@ func (in AssetOrArchiveMap) ToAssetOrArchiveMapOutputWithContext(ctx context.Con // AssetOrArchiveMapOutput is an Output that returns map[string]AssetOrArchive values. type AssetOrArchiveMapOutput struct{ *OutputState } +func (AssetOrArchiveMapOutput) MarshalJSON() ([]byte, error) { + return nil, fmt.Errorf("Outputs can not be marshaled to JSON") +} + // ElementType returns the element type of this Output (map[string]AssetOrArchive). func (AssetOrArchiveMapOutput) ElementType() reflect.Type { return assetOrArchiveMapType @@ -1118,6 +1187,10 @@ func (in AssetOrArchiveArrayMap) ToAssetOrArchiveArrayMapOutputWithContext(ctx c // AssetOrArchiveArrayMapOutput is an Output that returns map[string][]AssetOrArchive values. type AssetOrArchiveArrayMapOutput struct{ *OutputState } +func (AssetOrArchiveArrayMapOutput) MarshalJSON() ([]byte, error) { + return nil, fmt.Errorf("Outputs can not be marshaled to JSON") +} + // ElementType returns the element type of this Output (map[string][]AssetOrArchive). func (AssetOrArchiveArrayMapOutput) ElementType() reflect.Type { return assetOrArchiveArrayMapType @@ -1167,6 +1240,10 @@ func (in AssetOrArchiveMapArray) ToAssetOrArchiveMapArrayOutputWithContext(ctx c // AssetOrArchiveMapArrayOutput is an Output that returns []map[string]AssetOrArchive values. type AssetOrArchiveMapArrayOutput struct{ *OutputState } +func (AssetOrArchiveMapArrayOutput) MarshalJSON() ([]byte, error) { + return nil, fmt.Errorf("Outputs can not be marshaled to JSON") +} + // ElementType returns the element type of this Output ([]map[string]AssetOrArchive). func (AssetOrArchiveMapArrayOutput) ElementType() reflect.Type { return assetOrArchiveMapArrayType @@ -1223,6 +1300,10 @@ func (in AssetOrArchiveMapMap) ToAssetOrArchiveMapMapOutputWithContext(ctx conte // AssetOrArchiveMapMapOutput is an Output that returns map[string]map[string]AssetOrArchive values. type AssetOrArchiveMapMapOutput struct{ *OutputState } +func (AssetOrArchiveMapMapOutput) MarshalJSON() ([]byte, error) { + return nil, fmt.Errorf("Outputs can not be marshaled to JSON") +} + // ElementType returns the element type of this Output (map[string]map[string]AssetOrArchive). func (AssetOrArchiveMapMapOutput) ElementType() reflect.Type { return assetOrArchiveMapMapType @@ -1272,6 +1353,10 @@ func (in AssetOrArchiveArrayArray) ToAssetOrArchiveArrayArrayOutputWithContext(c // AssetOrArchiveArrayArrayOutput is an Output that returns [][]AssetOrArchive values. type AssetOrArchiveArrayArrayOutput struct{ *OutputState } +func (AssetOrArchiveArrayArrayOutput) MarshalJSON() ([]byte, error) { + return nil, fmt.Errorf("Outputs can not be marshaled to JSON") +} + // ElementType returns the element type of this Output ([][]AssetOrArchive). func (AssetOrArchiveArrayArrayOutput) ElementType() reflect.Type { return assetOrArchiveArrayArrayType @@ -1339,6 +1424,10 @@ func (in Bool) ToBoolPtrOutputWithContext(ctx context.Context) BoolPtrOutput { // BoolOutput is an Output that returns bool values. type BoolOutput struct{ *OutputState } +func (BoolOutput) MarshalJSON() ([]byte, error) { + return nil, fmt.Errorf("Outputs can not be marshaled to JSON") +} + // ElementType returns the element type of this Output (bool). func (BoolOutput) ElementType() reflect.Type { return boolType @@ -1401,6 +1490,10 @@ func (in *boolPtr) ToBoolPtrOutputWithContext(ctx context.Context) BoolPtrOutput // BoolPtrOutput is an Output that returns *bool values. type BoolPtrOutput struct{ *OutputState } +func (BoolPtrOutput) MarshalJSON() ([]byte, error) { + return nil, fmt.Errorf("Outputs can not be marshaled to JSON") +} + // ElementType returns the element type of this Output (*bool). func (BoolPtrOutput) ElementType() reflect.Type { return boolPtrType @@ -1454,6 +1547,10 @@ func (in BoolArray) ToBoolArrayOutputWithContext(ctx context.Context) BoolArrayO // BoolArrayOutput is an Output that returns []bool values. type BoolArrayOutput struct{ *OutputState } +func (BoolArrayOutput) MarshalJSON() ([]byte, error) { + return nil, fmt.Errorf("Outputs can not be marshaled to JSON") +} + // ElementType returns the element type of this Output ([]bool). func (BoolArrayOutput) ElementType() reflect.Type { return boolArrayType @@ -1526,6 +1623,10 @@ func (in BoolMap) ToBoolMapOutputWithContext(ctx context.Context) BoolMapOutput // BoolMapOutput is an Output that returns map[string]bool values. type BoolMapOutput struct{ *OutputState } +func (BoolMapOutput) MarshalJSON() ([]byte, error) { + return nil, fmt.Errorf("Outputs can not be marshaled to JSON") +} + // ElementType returns the element type of this Output (map[string]bool). func (BoolMapOutput) ElementType() reflect.Type { return boolMapType @@ -1591,6 +1692,10 @@ func (in BoolArrayMap) ToBoolArrayMapOutputWithContext(ctx context.Context) Bool // BoolArrayMapOutput is an Output that returns map[string][]bool values. type BoolArrayMapOutput struct{ *OutputState } +func (BoolArrayMapOutput) MarshalJSON() ([]byte, error) { + return nil, fmt.Errorf("Outputs can not be marshaled to JSON") +} + // ElementType returns the element type of this Output (map[string][]bool). func (BoolArrayMapOutput) ElementType() reflect.Type { return boolArrayMapType @@ -1656,6 +1761,10 @@ func (in BoolMapArray) ToBoolMapArrayOutputWithContext(ctx context.Context) Bool // BoolMapArrayOutput is an Output that returns []map[string]bool values. type BoolMapArrayOutput struct{ *OutputState } +func (BoolMapArrayOutput) MarshalJSON() ([]byte, error) { + return nil, fmt.Errorf("Outputs can not be marshaled to JSON") +} + // ElementType returns the element type of this Output ([]map[string]bool). func (BoolMapArrayOutput) ElementType() reflect.Type { return boolMapArrayType @@ -1728,6 +1837,10 @@ func (in BoolMapMap) ToBoolMapMapOutputWithContext(ctx context.Context) BoolMapM // BoolMapMapOutput is an Output that returns map[string]map[string]bool values. type BoolMapMapOutput struct{ *OutputState } +func (BoolMapMapOutput) MarshalJSON() ([]byte, error) { + return nil, fmt.Errorf("Outputs can not be marshaled to JSON") +} + // ElementType returns the element type of this Output (map[string]map[string]bool). func (BoolMapMapOutput) ElementType() reflect.Type { return boolMapMapType @@ -1793,6 +1906,10 @@ func (in BoolArrayArray) ToBoolArrayArrayOutputWithContext(ctx context.Context) // BoolArrayArrayOutput is an Output that returns [][]bool values. type BoolArrayArrayOutput struct{ *OutputState } +func (BoolArrayArrayOutput) MarshalJSON() ([]byte, error) { + return nil, fmt.Errorf("Outputs can not be marshaled to JSON") +} + // ElementType returns the element type of this Output ([][]bool). func (BoolArrayArrayOutput) ElementType() reflect.Type { return boolArrayArrayType @@ -1876,6 +1993,10 @@ func (in Float64) ToFloat64PtrOutputWithContext(ctx context.Context) Float64PtrO // Float64Output is an Output that returns float64 values. type Float64Output struct{ *OutputState } +func (Float64Output) MarshalJSON() ([]byte, error) { + return nil, fmt.Errorf("Outputs can not be marshaled to JSON") +} + // ElementType returns the element type of this Output (float64). func (Float64Output) ElementType() reflect.Type { return float64Type @@ -1938,6 +2059,10 @@ func (in *float64Ptr) ToFloat64PtrOutputWithContext(ctx context.Context) Float64 // Float64PtrOutput is an Output that returns *float64 values. type Float64PtrOutput struct{ *OutputState } +func (Float64PtrOutput) MarshalJSON() ([]byte, error) { + return nil, fmt.Errorf("Outputs can not be marshaled to JSON") +} + // ElementType returns the element type of this Output (*float64). func (Float64PtrOutput) ElementType() reflect.Type { return float64PtrType @@ -1991,6 +2116,10 @@ func (in Float64Array) ToFloat64ArrayOutputWithContext(ctx context.Context) Floa // Float64ArrayOutput is an Output that returns []float64 values. type Float64ArrayOutput struct{ *OutputState } +func (Float64ArrayOutput) MarshalJSON() ([]byte, error) { + return nil, fmt.Errorf("Outputs can not be marshaled to JSON") +} + // ElementType returns the element type of this Output ([]float64). func (Float64ArrayOutput) ElementType() reflect.Type { return float64ArrayType @@ -2063,6 +2192,10 @@ func (in Float64Map) ToFloat64MapOutputWithContext(ctx context.Context) Float64M // Float64MapOutput is an Output that returns map[string]float64 values. type Float64MapOutput struct{ *OutputState } +func (Float64MapOutput) MarshalJSON() ([]byte, error) { + return nil, fmt.Errorf("Outputs can not be marshaled to JSON") +} + // ElementType returns the element type of this Output (map[string]float64). func (Float64MapOutput) ElementType() reflect.Type { return float64MapType @@ -2128,6 +2261,10 @@ func (in Float64ArrayMap) ToFloat64ArrayMapOutputWithContext(ctx context.Context // Float64ArrayMapOutput is an Output that returns map[string][]float64 values. type Float64ArrayMapOutput struct{ *OutputState } +func (Float64ArrayMapOutput) MarshalJSON() ([]byte, error) { + return nil, fmt.Errorf("Outputs can not be marshaled to JSON") +} + // ElementType returns the element type of this Output (map[string][]float64). func (Float64ArrayMapOutput) ElementType() reflect.Type { return float64ArrayMapType @@ -2193,6 +2330,10 @@ func (in Float64MapArray) ToFloat64MapArrayOutputWithContext(ctx context.Context // Float64MapArrayOutput is an Output that returns []map[string]float64 values. type Float64MapArrayOutput struct{ *OutputState } +func (Float64MapArrayOutput) MarshalJSON() ([]byte, error) { + return nil, fmt.Errorf("Outputs can not be marshaled to JSON") +} + // ElementType returns the element type of this Output ([]map[string]float64). func (Float64MapArrayOutput) ElementType() reflect.Type { return float64MapArrayType @@ -2265,6 +2406,10 @@ func (in Float64MapMap) ToFloat64MapMapOutputWithContext(ctx context.Context) Fl // Float64MapMapOutput is an Output that returns map[string]map[string]float64 values. type Float64MapMapOutput struct{ *OutputState } +func (Float64MapMapOutput) MarshalJSON() ([]byte, error) { + return nil, fmt.Errorf("Outputs can not be marshaled to JSON") +} + // ElementType returns the element type of this Output (map[string]map[string]float64). func (Float64MapMapOutput) ElementType() reflect.Type { return float64MapMapType @@ -2330,6 +2475,10 @@ func (in Float64ArrayArray) ToFloat64ArrayArrayOutputWithContext(ctx context.Con // Float64ArrayArrayOutput is an Output that returns [][]float64 values. type Float64ArrayArrayOutput struct{ *OutputState } +func (Float64ArrayArrayOutput) MarshalJSON() ([]byte, error) { + return nil, fmt.Errorf("Outputs can not be marshaled to JSON") +} + // ElementType returns the element type of this Output ([][]float64). func (Float64ArrayArrayOutput) ElementType() reflect.Type { return float64ArrayArrayType @@ -2418,6 +2567,10 @@ func (in ID) ToIDPtrOutputWithContext(ctx context.Context) IDPtrOutput { // IDOutput is an Output that returns ID values. type IDOutput struct{ *OutputState } +func (IDOutput) MarshalJSON() ([]byte, error) { + return nil, fmt.Errorf("Outputs can not be marshaled to JSON") +} + // ElementType returns the element type of this Output (ID). func (IDOutput) ElementType() reflect.Type { return idType @@ -2490,6 +2643,10 @@ func (in *idPtr) ToIDPtrOutputWithContext(ctx context.Context) IDPtrOutput { // IDPtrOutput is an Output that returns *ID values. type IDPtrOutput struct{ *OutputState } +func (IDPtrOutput) MarshalJSON() ([]byte, error) { + return nil, fmt.Errorf("Outputs can not be marshaled to JSON") +} + // ElementType returns the element type of this Output (*ID). func (IDPtrOutput) ElementType() reflect.Type { return iDPtrType @@ -2543,6 +2700,10 @@ func (in IDArray) ToIDArrayOutputWithContext(ctx context.Context) IDArrayOutput // IDArrayOutput is an Output that returns []ID values. type IDArrayOutput struct{ *OutputState } +func (IDArrayOutput) MarshalJSON() ([]byte, error) { + return nil, fmt.Errorf("Outputs can not be marshaled to JSON") +} + // ElementType returns the element type of this Output ([]ID). func (IDArrayOutput) ElementType() reflect.Type { return iDArrayType @@ -2615,6 +2776,10 @@ func (in IDMap) ToIDMapOutputWithContext(ctx context.Context) IDMapOutput { // IDMapOutput is an Output that returns map[string]ID values. type IDMapOutput struct{ *OutputState } +func (IDMapOutput) MarshalJSON() ([]byte, error) { + return nil, fmt.Errorf("Outputs can not be marshaled to JSON") +} + // ElementType returns the element type of this Output (map[string]ID). func (IDMapOutput) ElementType() reflect.Type { return iDMapType @@ -2680,6 +2845,10 @@ func (in IDArrayMap) ToIDArrayMapOutputWithContext(ctx context.Context) IDArrayM // IDArrayMapOutput is an Output that returns map[string][]ID values. type IDArrayMapOutput struct{ *OutputState } +func (IDArrayMapOutput) MarshalJSON() ([]byte, error) { + return nil, fmt.Errorf("Outputs can not be marshaled to JSON") +} + // ElementType returns the element type of this Output (map[string][]ID). func (IDArrayMapOutput) ElementType() reflect.Type { return iDArrayMapType @@ -2745,6 +2914,10 @@ func (in IDMapArray) ToIDMapArrayOutputWithContext(ctx context.Context) IDMapArr // IDMapArrayOutput is an Output that returns []map[string]ID values. type IDMapArrayOutput struct{ *OutputState } +func (IDMapArrayOutput) MarshalJSON() ([]byte, error) { + return nil, fmt.Errorf("Outputs can not be marshaled to JSON") +} + // ElementType returns the element type of this Output ([]map[string]ID). func (IDMapArrayOutput) ElementType() reflect.Type { return iDMapArrayType @@ -2817,6 +2990,10 @@ func (in IDMapMap) ToIDMapMapOutputWithContext(ctx context.Context) IDMapMapOutp // IDMapMapOutput is an Output that returns map[string]map[string]ID values. type IDMapMapOutput struct{ *OutputState } +func (IDMapMapOutput) MarshalJSON() ([]byte, error) { + return nil, fmt.Errorf("Outputs can not be marshaled to JSON") +} + // ElementType returns the element type of this Output (map[string]map[string]ID). func (IDMapMapOutput) ElementType() reflect.Type { return iDMapMapType @@ -2882,6 +3059,10 @@ func (in IDArrayArray) ToIDArrayArrayOutputWithContext(ctx context.Context) IDAr // IDArrayArrayOutput is an Output that returns [][]ID values. type IDArrayArrayOutput struct{ *OutputState } +func (IDArrayArrayOutput) MarshalJSON() ([]byte, error) { + return nil, fmt.Errorf("Outputs can not be marshaled to JSON") +} + // ElementType returns the element type of this Output ([][]ID). func (IDArrayArrayOutput) ElementType() reflect.Type { return iDArrayArrayType @@ -2954,6 +3135,10 @@ func (in Array) ToArrayOutputWithContext(ctx context.Context) ArrayOutput { // ArrayOutput is an Output that returns []interface{} values. type ArrayOutput struct{ *OutputState } +func (ArrayOutput) MarshalJSON() ([]byte, error) { + return nil, fmt.Errorf("Outputs can not be marshaled to JSON") +} + // ElementType returns the element type of this Output ([]interface{}). func (ArrayOutput) ElementType() reflect.Type { return arrayType @@ -3026,6 +3211,10 @@ func (in Map) ToMapOutputWithContext(ctx context.Context) MapOutput { // MapOutput is an Output that returns map[string]interface{} values. type MapOutput struct{ *OutputState } +func (MapOutput) MarshalJSON() ([]byte, error) { + return nil, fmt.Errorf("Outputs can not be marshaled to JSON") +} + // ElementType returns the element type of this Output (map[string]interface{}). func (MapOutput) ElementType() reflect.Type { return mapType @@ -3091,6 +3280,10 @@ func (in ArrayMap) ToArrayMapOutputWithContext(ctx context.Context) ArrayMapOutp // ArrayMapOutput is an Output that returns map[string][]interface{} values. type ArrayMapOutput struct{ *OutputState } +func (ArrayMapOutput) MarshalJSON() ([]byte, error) { + return nil, fmt.Errorf("Outputs can not be marshaled to JSON") +} + // ElementType returns the element type of this Output (map[string][]interface{}). func (ArrayMapOutput) ElementType() reflect.Type { return arrayMapType @@ -3156,6 +3349,10 @@ func (in MapArray) ToMapArrayOutputWithContext(ctx context.Context) MapArrayOutp // MapArrayOutput is an Output that returns []map[string]interface{} values. type MapArrayOutput struct{ *OutputState } +func (MapArrayOutput) MarshalJSON() ([]byte, error) { + return nil, fmt.Errorf("Outputs can not be marshaled to JSON") +} + // ElementType returns the element type of this Output ([]map[string]interface{}). func (MapArrayOutput) ElementType() reflect.Type { return mapArrayType @@ -3228,6 +3425,10 @@ func (in MapMap) ToMapMapOutputWithContext(ctx context.Context) MapMapOutput { // MapMapOutput is an Output that returns map[string]map[string]interface{} values. type MapMapOutput struct{ *OutputState } +func (MapMapOutput) MarshalJSON() ([]byte, error) { + return nil, fmt.Errorf("Outputs can not be marshaled to JSON") +} + // ElementType returns the element type of this Output (map[string]map[string]interface{}). func (MapMapOutput) ElementType() reflect.Type { return mapMapType @@ -3293,6 +3494,10 @@ func (in ArrayArray) ToArrayArrayOutputWithContext(ctx context.Context) ArrayArr // ArrayArrayOutput is an Output that returns [][]interface{} values. type ArrayArrayOutput struct{ *OutputState } +func (ArrayArrayOutput) MarshalJSON() ([]byte, error) { + return nil, fmt.Errorf("Outputs can not be marshaled to JSON") +} + // ElementType returns the element type of this Output ([][]interface{}). func (ArrayArrayOutput) ElementType() reflect.Type { return arrayArrayType @@ -3365,6 +3570,10 @@ func (in ArrayArrayMap) ToArrayArrayMapOutputWithContext(ctx context.Context) Ar // ArrayArrayMapOutput is an Output that returns map[string][][]interface{} values. type ArrayArrayMapOutput struct{ *OutputState } +func (ArrayArrayMapOutput) MarshalJSON() ([]byte, error) { + return nil, fmt.Errorf("Outputs can not be marshaled to JSON") +} + // ElementType returns the element type of this Output (map[string][][]interface{}). func (ArrayArrayMapOutput) ElementType() reflect.Type { return arrayArrayMapType @@ -3441,6 +3650,10 @@ func (in Int) ToIntPtrOutputWithContext(ctx context.Context) IntPtrOutput { // IntOutput is an Output that returns int values. type IntOutput struct{ *OutputState } +func (IntOutput) MarshalJSON() ([]byte, error) { + return nil, fmt.Errorf("Outputs can not be marshaled to JSON") +} + // ElementType returns the element type of this Output (int). func (IntOutput) ElementType() reflect.Type { return intType @@ -3503,6 +3716,10 @@ func (in *intPtr) ToIntPtrOutputWithContext(ctx context.Context) IntPtrOutput { // IntPtrOutput is an Output that returns *int values. type IntPtrOutput struct{ *OutputState } +func (IntPtrOutput) MarshalJSON() ([]byte, error) { + return nil, fmt.Errorf("Outputs can not be marshaled to JSON") +} + // ElementType returns the element type of this Output (*int). func (IntPtrOutput) ElementType() reflect.Type { return intPtrType @@ -3556,6 +3773,10 @@ func (in IntArray) ToIntArrayOutputWithContext(ctx context.Context) IntArrayOutp // IntArrayOutput is an Output that returns []int values. type IntArrayOutput struct{ *OutputState } +func (IntArrayOutput) MarshalJSON() ([]byte, error) { + return nil, fmt.Errorf("Outputs can not be marshaled to JSON") +} + // ElementType returns the element type of this Output ([]int). func (IntArrayOutput) ElementType() reflect.Type { return intArrayType @@ -3628,6 +3849,10 @@ func (in IntMap) ToIntMapOutputWithContext(ctx context.Context) IntMapOutput { // IntMapOutput is an Output that returns map[string]int values. type IntMapOutput struct{ *OutputState } +func (IntMapOutput) MarshalJSON() ([]byte, error) { + return nil, fmt.Errorf("Outputs can not be marshaled to JSON") +} + // ElementType returns the element type of this Output (map[string]int). func (IntMapOutput) ElementType() reflect.Type { return intMapType @@ -3693,6 +3918,10 @@ func (in IntArrayMap) ToIntArrayMapOutputWithContext(ctx context.Context) IntArr // IntArrayMapOutput is an Output that returns map[string][]int values. type IntArrayMapOutput struct{ *OutputState } +func (IntArrayMapOutput) MarshalJSON() ([]byte, error) { + return nil, fmt.Errorf("Outputs can not be marshaled to JSON") +} + // ElementType returns the element type of this Output (map[string][]int). func (IntArrayMapOutput) ElementType() reflect.Type { return intArrayMapType @@ -3758,6 +3987,10 @@ func (in IntMapArray) ToIntMapArrayOutputWithContext(ctx context.Context) IntMap // IntMapArrayOutput is an Output that returns []map[string]int values. type IntMapArrayOutput struct{ *OutputState } +func (IntMapArrayOutput) MarshalJSON() ([]byte, error) { + return nil, fmt.Errorf("Outputs can not be marshaled to JSON") +} + // ElementType returns the element type of this Output ([]map[string]int). func (IntMapArrayOutput) ElementType() reflect.Type { return intMapArrayType @@ -3830,6 +4063,10 @@ func (in IntMapMap) ToIntMapMapOutputWithContext(ctx context.Context) IntMapMapO // IntMapMapOutput is an Output that returns map[string]map[string]int values. type IntMapMapOutput struct{ *OutputState } +func (IntMapMapOutput) MarshalJSON() ([]byte, error) { + return nil, fmt.Errorf("Outputs can not be marshaled to JSON") +} + // ElementType returns the element type of this Output (map[string]map[string]int). func (IntMapMapOutput) ElementType() reflect.Type { return intMapMapType @@ -3895,6 +4132,10 @@ func (in IntArrayArray) ToIntArrayArrayOutputWithContext(ctx context.Context) In // IntArrayArrayOutput is an Output that returns [][]int values. type IntArrayArrayOutput struct{ *OutputState } +func (IntArrayArrayOutput) MarshalJSON() ([]byte, error) { + return nil, fmt.Errorf("Outputs can not be marshaled to JSON") +} + // ElementType returns the element type of this Output ([][]int). func (IntArrayArrayOutput) ElementType() reflect.Type { return intArrayArrayType @@ -3978,6 +4219,10 @@ func (in String) ToStringPtrOutputWithContext(ctx context.Context) StringPtrOutp // StringOutput is an Output that returns string values. type StringOutput struct{ *OutputState } +func (StringOutput) MarshalJSON() ([]byte, error) { + return nil, fmt.Errorf("Outputs can not be marshaled to JSON") +} + // ElementType returns the element type of this Output (string). func (StringOutput) ElementType() reflect.Type { return stringType @@ -4040,6 +4285,10 @@ func (in *stringPtr) ToStringPtrOutputWithContext(ctx context.Context) StringPtr // StringPtrOutput is an Output that returns *string values. type StringPtrOutput struct{ *OutputState } +func (StringPtrOutput) MarshalJSON() ([]byte, error) { + return nil, fmt.Errorf("Outputs can not be marshaled to JSON") +} + // ElementType returns the element type of this Output (*string). func (StringPtrOutput) ElementType() reflect.Type { return stringPtrType @@ -4093,6 +4342,10 @@ func (in StringArray) ToStringArrayOutputWithContext(ctx context.Context) String // StringArrayOutput is an Output that returns []string values. type StringArrayOutput struct{ *OutputState } +func (StringArrayOutput) MarshalJSON() ([]byte, error) { + return nil, fmt.Errorf("Outputs can not be marshaled to JSON") +} + // ElementType returns the element type of this Output ([]string). func (StringArrayOutput) ElementType() reflect.Type { return stringArrayType @@ -4165,6 +4418,10 @@ func (in StringMap) ToStringMapOutputWithContext(ctx context.Context) StringMapO // StringMapOutput is an Output that returns map[string]string values. type StringMapOutput struct{ *OutputState } +func (StringMapOutput) MarshalJSON() ([]byte, error) { + return nil, fmt.Errorf("Outputs can not be marshaled to JSON") +} + // ElementType returns the element type of this Output (map[string]string). func (StringMapOutput) ElementType() reflect.Type { return stringMapType @@ -4230,6 +4487,10 @@ func (in StringArrayMap) ToStringArrayMapOutputWithContext(ctx context.Context) // StringArrayMapOutput is an Output that returns map[string][]string values. type StringArrayMapOutput struct{ *OutputState } +func (StringArrayMapOutput) MarshalJSON() ([]byte, error) { + return nil, fmt.Errorf("Outputs can not be marshaled to JSON") +} + // ElementType returns the element type of this Output (map[string][]string). func (StringArrayMapOutput) ElementType() reflect.Type { return stringArrayMapType @@ -4295,6 +4556,10 @@ func (in StringMapArray) ToStringMapArrayOutputWithContext(ctx context.Context) // StringMapArrayOutput is an Output that returns []map[string]string values. type StringMapArrayOutput struct{ *OutputState } +func (StringMapArrayOutput) MarshalJSON() ([]byte, error) { + return nil, fmt.Errorf("Outputs can not be marshaled to JSON") +} + // ElementType returns the element type of this Output ([]map[string]string). func (StringMapArrayOutput) ElementType() reflect.Type { return stringMapArrayType @@ -4367,6 +4632,10 @@ func (in StringMapMap) ToStringMapMapOutputWithContext(ctx context.Context) Stri // StringMapMapOutput is an Output that returns map[string]map[string]string values. type StringMapMapOutput struct{ *OutputState } +func (StringMapMapOutput) MarshalJSON() ([]byte, error) { + return nil, fmt.Errorf("Outputs can not be marshaled to JSON") +} + // ElementType returns the element type of this Output (map[string]map[string]string). func (StringMapMapOutput) ElementType() reflect.Type { return stringMapMapType @@ -4432,6 +4701,10 @@ func (in StringArrayArray) ToStringArrayArrayOutputWithContext(ctx context.Conte // StringArrayArrayOutput is an Output that returns [][]string values. type StringArrayArrayOutput struct{ *OutputState } +func (StringArrayArrayOutput) MarshalJSON() ([]byte, error) { + return nil, fmt.Errorf("Outputs can not be marshaled to JSON") +} + // ElementType returns the element type of this Output ([][]string). func (StringArrayArrayOutput) ElementType() reflect.Type { return stringArrayArrayType @@ -4520,6 +4793,10 @@ func (in URN) ToURNPtrOutputWithContext(ctx context.Context) URNPtrOutput { // URNOutput is an Output that returns URN values. type URNOutput struct{ *OutputState } +func (URNOutput) MarshalJSON() ([]byte, error) { + return nil, fmt.Errorf("Outputs can not be marshaled to JSON") +} + // ElementType returns the element type of this Output (URN). func (URNOutput) ElementType() reflect.Type { return urnType @@ -4592,6 +4869,10 @@ func (in *urnPtr) ToURNPtrOutputWithContext(ctx context.Context) URNPtrOutput { // URNPtrOutput is an Output that returns *URN values. type URNPtrOutput struct{ *OutputState } +func (URNPtrOutput) MarshalJSON() ([]byte, error) { + return nil, fmt.Errorf("Outputs can not be marshaled to JSON") +} + // ElementType returns the element type of this Output (*URN). func (URNPtrOutput) ElementType() reflect.Type { return uRNPtrType @@ -4645,6 +4926,10 @@ func (in URNArray) ToURNArrayOutputWithContext(ctx context.Context) URNArrayOutp // URNArrayOutput is an Output that returns []URN values. type URNArrayOutput struct{ *OutputState } +func (URNArrayOutput) MarshalJSON() ([]byte, error) { + return nil, fmt.Errorf("Outputs can not be marshaled to JSON") +} + // ElementType returns the element type of this Output ([]URN). func (URNArrayOutput) ElementType() reflect.Type { return uRNArrayType @@ -4717,6 +5002,10 @@ func (in URNMap) ToURNMapOutputWithContext(ctx context.Context) URNMapOutput { // URNMapOutput is an Output that returns map[string]URN values. type URNMapOutput struct{ *OutputState } +func (URNMapOutput) MarshalJSON() ([]byte, error) { + return nil, fmt.Errorf("Outputs can not be marshaled to JSON") +} + // ElementType returns the element type of this Output (map[string]URN). func (URNMapOutput) ElementType() reflect.Type { return uRNMapType @@ -4782,6 +5071,10 @@ func (in URNArrayMap) ToURNArrayMapOutputWithContext(ctx context.Context) URNArr // URNArrayMapOutput is an Output that returns map[string][]URN values. type URNArrayMapOutput struct{ *OutputState } +func (URNArrayMapOutput) MarshalJSON() ([]byte, error) { + return nil, fmt.Errorf("Outputs can not be marshaled to JSON") +} + // ElementType returns the element type of this Output (map[string][]URN). func (URNArrayMapOutput) ElementType() reflect.Type { return uRNArrayMapType @@ -4847,6 +5140,10 @@ func (in URNMapArray) ToURNMapArrayOutputWithContext(ctx context.Context) URNMap // URNMapArrayOutput is an Output that returns []map[string]URN values. type URNMapArrayOutput struct{ *OutputState } +func (URNMapArrayOutput) MarshalJSON() ([]byte, error) { + return nil, fmt.Errorf("Outputs can not be marshaled to JSON") +} + // ElementType returns the element type of this Output ([]map[string]URN). func (URNMapArrayOutput) ElementType() reflect.Type { return uRNMapArrayType @@ -4919,6 +5216,10 @@ func (in URNMapMap) ToURNMapMapOutputWithContext(ctx context.Context) URNMapMapO // URNMapMapOutput is an Output that returns map[string]map[string]URN values. type URNMapMapOutput struct{ *OutputState } +func (URNMapMapOutput) MarshalJSON() ([]byte, error) { + return nil, fmt.Errorf("Outputs can not be marshaled to JSON") +} + // ElementType returns the element type of this Output (map[string]map[string]URN). func (URNMapMapOutput) ElementType() reflect.Type { return uRNMapMapType @@ -4984,6 +5285,10 @@ func (in URNArrayArray) ToURNArrayArrayOutputWithContext(ctx context.Context) UR // URNArrayArrayOutput is an Output that returns [][]URN values. type URNArrayArrayOutput struct{ *OutputState } +func (URNArrayArrayOutput) MarshalJSON() ([]byte, error) { + return nil, fmt.Errorf("Outputs can not be marshaled to JSON") +} + // ElementType returns the element type of this Output ([][]URN). func (URNArrayArrayOutput) ElementType() reflect.Type { return uRNArrayArrayType diff --git a/sdk/go/pulumi/types_test.go b/sdk/go/pulumi/types_test.go index 43c65771f18d..e7250f13695a 100644 --- a/sdk/go/pulumi/types_test.go +++ b/sdk/go/pulumi/types_test.go @@ -1087,3 +1087,44 @@ func TestTypeCoersion(t *testing.T) { }) } } + +func TestJSONMarshalBasic(t *testing.T) { + t.Parallel() + + out, resolve, _ := NewOutput() + go func() { + resolve([]int{0, 1}) + }() + json := JSONMarshal(out) + v, known, secret, deps, err := await(json) + assert.Nil(t, err) + assert.True(t, known) + assert.False(t, secret) + assert.Nil(t, deps) + assert.NotNil(t, v) + assert.Equal(t, "[0,1]", v.(string)) +} + +func TestJSONMarshalNested(t *testing.T) { + t.Parallel() + + a, resolvea, _ := NewOutput() + go func() { + resolvea(0) + }() + b, resolveb, _ := NewOutput() + go func() { + resolveb(1) + }() + out, resolve, _ := NewOutput() + go func() { + resolve([]Output{a, b}) + }() + json := JSONMarshal(out) + v, known, secret, deps, err := await(json) + assert.Equal(t, "json: error calling MarshalJSON for type pulumi.AnyOutput: Outputs can not be marshaled to JSON", err.Error()) + assert.True(t, known) + assert.False(t, secret) + assert.Nil(t, deps) + assert.Nil(t, v) +}