Skip to content

Commit 3212152

Browse files
authored
do: make default input YAML (#23808)
PCL is not documented, and the PCL runtime has not been released publicly yet. It's better to have a documented format for `--input-file` and `--provider-file` inputs instead. Choose yaml as default, as it's the closest to a config language. PCL can still be used using `--input pcl` if the user wishes to do so.
1 parent 93ab968 commit 3212152

7 files changed

Lines changed: 134 additions & 35 deletions

File tree

‎pkg/cmd/pulumi/do/do.go‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -388,12 +388,11 @@ installed locally.
388388
389389
Provider configuration can be supplied via:
390390
- the provider's standard environment variables (e.g. AWS_REGION)
391-
- an input file passed with --provider-file (PCL by default;
392-
set --input to convert from another format)
391+
- an input file passed with --provider-file (YAML by default;
392+
set --input to use another format)
393393
394-
Function inputs come from --input-file. PCL is the default; pass --input
395-
to convert from another format such as YAML. Non-PCL formats require a
396-
converter plugin for that format to be installed.`,
394+
Function inputs come from --input-file. YAML is the default; pass --input
395+
to use another format.`,
397396
DisableFlagParsing: true,
398397
RunE: func(cmd *cobra.Command, args []string) error {
399398
subcmd, cleanup, err := buildSubcommand(cmd, args)

‎pkg/cmd/pulumi/do/do_function.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ func (pc *packageCommand) newFunctionCommand(fn *schema.Function) *cobra.Command
150150
cmd.Flags().StringVar(&inputFile, "input-file", "", "Path to a file containing function inputs")
151151
cmd.Flags().StringVar(&pc.providerFile, "provider-file", "",
152152
"Path to a file containing provider configuration")
153-
cmd.Flags().StringVar(&pc.format, "input", "pcl",
153+
cmd.Flags().StringVar(&pc.format, "input", "yaml",
154154
"Format of the configuration files")
155155
cmd.Flags().StringVar(&pc.providerURN, "provider", "",
156156
"The URN of a provider resource in the current stack whose inputs to use as the "+

‎pkg/cmd/pulumi/do/do_function_test.go‎

Lines changed: 97 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ Usage:
131131
Flags:
132132
--dry-run Run the operation in preview mode
133133
-h, --help help for do
134-
--input string Format of the configuration files (default "pcl")
134+
--input string Format of the configuration files (default "yaml")
135135
--input-file string Path to a file containing function inputs
136136
--package string The package to load, in the form 'name@version' or a path to a plugin binary or folder. If the package supports parameterization, additional space-separated parameters can be included after the package name, e.g. --package "name@version param1 \"multi word param\""
137137
--param1 string To set param1 things (alias for --input:param1)
@@ -215,7 +215,7 @@ param2 = 42
215215
param3 = true
216216
`)
217217

218-
cmd.SetArgs([]string{"azure:index:myFunction", "--input-file", inputFile})
218+
cmd.SetArgs([]string{"azure:index:myFunction", "--input", "pcl", "--input-file", inputFile})
219219
err := cmd.Execute()
220220
require.NoError(t, err)
221221

@@ -660,7 +660,7 @@ param = "hello"
660660
`)
661661

662662
stdout.Reset()
663-
cmd.SetArgs([]string{"pkg:mod1/mod2:fun", "--input-file", inputFile})
663+
cmd.SetArgs([]string{"pkg:mod1/mod2:fun", "--input", "pcl", "--input-file", inputFile})
664664
err := cmd.Execute()
665665
require.NoError(t, err)
666666

@@ -725,7 +725,7 @@ param2 = 42
725725
param3 = true
726726
`)
727727

728-
cmd.SetArgs([]string{"azure:index:myFunction", "--input-file", inputFile})
728+
cmd.SetArgs([]string{"azure:index:myFunction", "--input", "pcl", "--input-file", inputFile})
729729
err := cmd.Execute()
730730
require.ErrorContains(t, err, `Missing required input "param1"`)
731731
}
@@ -900,7 +900,7 @@ param3 = {
900900
cmd.SetErr(&stdout)
901901

902902
inputFile := writeHCLFile(t, "inputs.pcl", tt.input)
903-
cmd.SetArgs([]string{"azure:index:myFunction", "--input-file", inputFile})
903+
cmd.SetArgs([]string{"azure:index:myFunction", "--input", "pcl", "--input-file", inputFile})
904904
err := cmd.Execute()
905905
require.Error(t, err)
906906
for _, want := range tt.wantErrs {
@@ -949,7 +949,7 @@ func TestDoCmdFunctionInvokeInputFileForInputlessFunction(t *testing.T) {
949949
cmd := NewDoCmd(mlm, mws, loader, testHost, panicLoadConverterPlugin)
950950
cmd.SetOut(&stdout)
951951
cmd.SetErr(&stdout)
952-
cmd.SetArgs([]string{"azure:index:myFunction", "--input-file", inputFile})
952+
cmd.SetArgs([]string{"azure:index:myFunction", "--input", "pcl", "--input-file", inputFile})
953953
err := cmd.Execute()
954954
require.Error(t, err)
955955
assert.ErrorContains(t, err, "unsupported attribute 'bogus'")
@@ -1005,7 +1005,7 @@ stuff {
10051005
cmd := NewDoCmd(mlm, mws, loader, testHost, panicLoadConverterPlugin)
10061006
cmd.SetOut(&stdout)
10071007
cmd.SetErr(&stdout)
1008-
cmd.SetArgs([]string{"azure:index:myFunction", "--input-file", inputFile})
1008+
cmd.SetArgs([]string{"azure:index:myFunction", "--input", "pcl", "--input-file", inputFile})
10091009
err := cmd.Execute()
10101010
require.Error(t, err)
10111011
assert.ErrorContains(t, err, `unexpected block "stuff"`)
@@ -1065,7 +1065,7 @@ param2 = "true"
10651065
param3 = "45"
10661066
`)
10671067

1068-
cmd.SetArgs([]string{"azure:index:myFunction", "--input-file", inputFile})
1068+
cmd.SetArgs([]string{"azure:index:myFunction", "--input", "pcl", "--input-file", inputFile})
10691069
err := cmd.Execute()
10701070
require.NoError(t, err)
10711071

@@ -1148,7 +1148,7 @@ param2 = 42
11481148
param3 = true
11491149
`)
11501150

1151-
cmd.SetArgs([]string{"--dry-run", "azure:index:myFunction", "--input-file", inputFile})
1151+
cmd.SetArgs([]string{"--dry-run", "azure:index:myFunction", "--input", "pcl", "--input-file", inputFile})
11521152
err := cmd.Execute()
11531153
require.NoError(t, err)
11541154

@@ -1221,7 +1221,7 @@ param2 = max(1, length(split(":", "a:b:c")), 6)
12211221
cmd.SetOut(&stdout)
12221222
cmd.SetErr(&stdout)
12231223

1224-
cmd.SetArgs([]string{"azure:index:myFunction", "--input-file", inputFile})
1224+
cmd.SetArgs([]string{"azure:index:myFunction", "--input", "pcl", "--input-file", inputFile})
12251225
err := cmd.Execute()
12261226
require.NoError(t, err)
12271227
}
@@ -1286,7 +1286,7 @@ func TestDoCmdFunctionInvokeWithUnsupportedBuiltinFunction(t *testing.T) {
12861286

12871287
inputFile := writeHCLFile(t, "inputs.pcl", tt.input)
12881288

1289-
cmd.SetArgs([]string{"azure:index:myFunction", "--input-file", inputFile})
1289+
cmd.SetArgs([]string{"azure:index:myFunction", "--input", "pcl", "--input-file", inputFile})
12901290
err := cmd.Execute()
12911291
require.ErrorContains(t, err, tt.expected)
12921292
})
@@ -1365,7 +1365,7 @@ project = project()
13651365
cmd.SetOut(&stdout)
13661366
cmd.SetErr(&stdout)
13671367

1368-
cmd.SetArgs([]string{"azure:index:myFunction", "--input-file", inputFile})
1368+
cmd.SetArgs([]string{"azure:index:myFunction", "--input", "pcl", "--input-file", inputFile})
13691369
err := cmd.Execute()
13701370
require.NoError(t, err)
13711371
}
@@ -1462,6 +1462,7 @@ param3 = true
14621462

14631463
cmd.SetArgs([]string{
14641464
"azure:index:myFunction",
1465+
"--input", "pcl",
14651466
"--provider-file", providerFile,
14661467
"--input-file", inputFile,
14671468
})
@@ -1796,7 +1797,7 @@ func TestDoCmdFunctionInvokeWithParameterizedPackage(t *testing.T) {
17961797
// First positional is the package spec: base provider name plus any Parameterize args, shlex-quoted.
17971798
cmd.SetArgs([]string{
17981799
"--package", "terraform-provider foo/bar 1.2.3",
1799-
"myparam:index:myFunction", "--input-file", inputFile,
1800+
"myparam:index:myFunction", "--input", "pcl", "--input-file", inputFile,
18001801
})
18011802
err := cmd.Execute()
18021803
require.NoError(t, err)
@@ -1938,6 +1939,88 @@ param3: true
19381939
assert.Equal(t, expected, stdout.String())
19391940
}
19401941

1942+
// TestDoCmdFunctionInvokeYAMLInputByDefault verifies that YAML is the default input format: an input file
1943+
// passed without --input is routed through the yaml converter.
1944+
func TestDoCmdFunctionInvokeYAMLInputByDefault(t *testing.T) {
1945+
t.Parallel()
1946+
1947+
mlm := &cmdBackend.MockLoginManager{}
1948+
mws := &pkgWorkspace.MockContext{}
1949+
yamlHost := func(_ context.Context, d, statusD diag.Sink) (plugin.Host, error) {
1950+
// Serve the standard schema loader so the context exposes a non-empty LoaderAddr, which
1951+
// `do` forwards to the converter as its TargetLoader.
1952+
return &plugin.MockHost{
1953+
LoaderF: func(ctx *plugin.Context) (*plugin.GrpcServer, error) {
1954+
return plugin.NewServer(ctx, schema.LoaderRegistration(schema.NewLoaderServerFromContext(ctx)))
1955+
},
1956+
}, nil
1957+
}
1958+
loadConverter := func(
1959+
_ *plugin.Context, name string, _ func(sev diag.Severity, msg string),
1960+
) (plugin.Converter, error) {
1961+
assert.Equal(t, "yaml", name)
1962+
return &plugin.MockConverter{
1963+
ConvertSnippetF: func(ctx context.Context, req *plugin.ConvertSnippetRequest) (
1964+
*plugin.ConvertSnippetResponse, error,
1965+
) {
1966+
assert.Equal(t, "inputs.yaml", filepath.Base(req.Filename))
1967+
assert.Equal(t, "x: hello\n", string(req.Source))
1968+
return &plugin.ConvertSnippetResponse{
1969+
Filename: "inputs.pp",
1970+
Source: []byte(`x = "hello"` + "\n"),
1971+
}, nil
1972+
},
1973+
}, nil
1974+
}
1975+
loader := func(ctx context.Context, pctx *plugin.Context, wd, source string) (plugin.Provider, error) {
1976+
assert.Equal(t, "azure", source)
1977+
spec := schema.PackageSpec{
1978+
Name: "azure",
1979+
Functions: map[string]schema.FunctionSpec{
1980+
"azure:index:myFunction": {
1981+
Inputs: &schema.ObjectTypeSpec{
1982+
Properties: map[string]schema.PropertySpec{
1983+
"x": {TypeSpec: schema.TypeSpec{Type: "string"}},
1984+
},
1985+
},
1986+
Outputs: &schema.ObjectTypeSpec{
1987+
Properties: map[string]schema.PropertySpec{
1988+
"y": {TypeSpec: schema.TypeSpec{Type: "string"}},
1989+
},
1990+
},
1991+
},
1992+
},
1993+
}
1994+
return &testProvider{
1995+
spec: spec,
1996+
MockProvider: plugin.MockProvider{
1997+
InvokeF: func(ctx context.Context, req plugin.InvokeRequest) (plugin.InvokeResponse, error) {
1998+
assert.Equal(t, "hello", req.Args["x"].StringValue())
1999+
return plugin.InvokeResponse{
2000+
Properties: resource.PropertyMap{"y": resource.NewProperty("world")},
2001+
}, nil
2002+
},
2003+
},
2004+
}, nil
2005+
}
2006+
2007+
inputFile := writeHCLFile(t, "inputs.yaml", "x: hello\n")
2008+
2009+
var stdout bytes.Buffer
2010+
cmd := NewDoCmd(mlm, mws, loader, yamlHost, loadConverter)
2011+
cmd.SetOut(&stdout)
2012+
cmd.SetErr(&stdout)
2013+
cmd.SetArgs([]string{"azure:index:myFunction", "--input-file", inputFile})
2014+
err := cmd.Execute()
2015+
require.NoError(t, err)
2016+
2017+
expected := `{
2018+
"y": "world"
2019+
}
2020+
`
2021+
assert.Equal(t, expected, stdout.String())
2022+
}
2023+
19412024
// TestDoCmdFunctionInvokeWithYAMLInputFileParameterized exercises the ConvertSnippet Package descriptor for a
19422025
// parameterized package — version comes from the @version suffix and Parameterization is populated from the
19432026
// provider's Parameterize response.
@@ -2488,6 +2571,7 @@ func TestDoCmdFunctionInvokeWithFlags(t *testing.T) {
24882571
cmd.SetErr(&stdout)
24892572
cmd.SetArgs([]string{
24902573
"azure:index:myFunction",
2574+
"--input", "pcl",
24912575
"--provider-file", providerFile,
24922576
"--azure:opt-two", "val2",
24932577
"--in1", "p1",

‎pkg/cmd/pulumi/do/do_resource.go‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ func (pc *packageCommand) newResourceCommand(res *schema.Resource) *cobra.Comman
9999
// Provider configuration applies to all sub-operations, so register here as persistent flags.
100100
cmd.PersistentFlags().StringVar(&pc.providerFile, "provider-file", "",
101101
"Path to a file containing provider configuration")
102-
cmd.PersistentFlags().StringVar(&pc.format, "input", "pcl",
102+
cmd.PersistentFlags().StringVar(&pc.format, "input", "yaml",
103103
"Format of the provider configuration file")
104104
cmd.PersistentFlags().StringVar(&pc.providerURN, "provider", "",
105105
"The URN of a provider resource in the current stack whose inputs to use as the "+
@@ -298,7 +298,7 @@ func (pc *packageCommand) newResourcePatchCommand(res *schema.Resource) *cobra.C
298298
return pc.printResourceResult(cmd, id, response.Properties, res)
299299
},
300300
}
301-
cmd.Flags().StringVar(&inputFormat, "input", "pcl", "Format of the configuration files")
301+
cmd.Flags().StringVar(&inputFormat, "input", "yaml", "Format of the configuration files")
302302
cmd.Flags().StringVar(&inputFile, "input-file", "", "Path to a file containing resource inputs")
303303
cmd.Flags().BoolVar(&yes, "yes", false,
304304
"Automatically approve and perform the operation without a confirmation prompt")
@@ -416,7 +416,7 @@ func (pc *packageCommand) newResourceListCommand(res *schema.Resource) *cobra.Co
416416
return pc.printListResults(cmd, results)
417417
},
418418
}
419-
cmd.Flags().StringVar(&inputFormat, "input", "pcl", "Input file format")
419+
cmd.Flags().StringVar(&inputFormat, "input", "yaml", "Input file format")
420420
cmd.Flags().StringVar(&inputFile, "input-file", "", "Path to a file containing resource list inputs")
421421
cmd.Flags().BoolVar(&all, "all", false, "Enumerate all matching resources")
422422
cmd.Flags().Int64Var(&count, "count", 0, "Enumerate up to count matching resources")

‎pkg/cmd/pulumi/do/do_resource_test.go‎

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ Available Commands:
134134
Flags:
135135
--dry-run Run the operation in preview mode
136136
-h, --help help for do
137-
--input string Format of the provider configuration file (default "pcl")
137+
--input string Format of the provider configuration file (default "yaml")
138138
--package string The package to load, in the form 'name@version' or a path to a plugin binary or folder. If the package supports parameterization, additional space-separated parameters can be included after the package name, e.g. --package "name@version param1 \"multi word param\""
139139
--provider string The URN of a provider resource in the current stack whose inputs to use as the base of the provider configuration (requires a stack context)
140140
--provider-file string Path to a file containing provider configuration
@@ -182,7 +182,7 @@ Available Commands:
182182
Flags:
183183
--dry-run Run the operation in preview mode
184184
-h, --help help for do
185-
--input string Format of the provider configuration file (default "pcl")
185+
--input string Format of the provider configuration file (default "yaml")
186186
--package string The package to load, in the form 'name@version' or a path to a plugin binary or folder. If the package supports parameterization, additional space-separated parameters can be included after the package name, e.g. --package "name@version param1 \"multi word param\""
187187
--provider string The URN of a provider resource in the current stack whose inputs to use as the base of the provider configuration (requires a stack context)
188188
--provider-file string Path to a file containing provider configuration
@@ -227,7 +227,10 @@ func TestDoCmdResourceCreate(t *testing.T) {
227227
name = "example"
228228
size = 2
229229
`)
230-
cmd.SetArgs([]string{"--stateless", "azure:index:myResource", "create", "--yes", "--input-file", inputFile})
230+
cmd.SetArgs([]string{
231+
"--stateless", "azure:index:myResource", "create", "--yes",
232+
"--input", "pcl", "--input-file", inputFile,
233+
})
231234
err := cmd.Execute()
232235
require.NoError(t, err)
233236

@@ -290,6 +293,7 @@ func TestDoCmdResourceCreateWithPCLInputFlags(t *testing.T) {
290293
"--stateless",
291294
"azure:index:myResource", "create",
292295
"--yes",
296+
"--input", "pcl",
293297
"--input-file", inputFile,
294298
"--int-value", "42",
295299
"--already-kebab-case", "kebab",
@@ -416,7 +420,10 @@ func TestDoCmdResourceReadDeletePatch(t *testing.T) {
416420
name = "new"
417421
enabled = true
418422
`)
419-
cmd.SetArgs([]string{"--stateless", "azure:index:myResource", "patch", "res-1", "--yes", "--input-file", inputFile})
423+
cmd.SetArgs([]string{
424+
"--stateless", "azure:index:myResource", "patch", "res-1", "--yes",
425+
"--input", "pcl", "--input-file", inputFile,
426+
})
420427
err := cmd.Execute()
421428
require.NoError(t, err)
422429
assert.Equal(t, []string{"read", "check", "diff", "update"}, calls)
@@ -465,7 +472,10 @@ enabled = true
465472
})
466473

467474
inputFile := writeHCLFile(t, "patch.pcl", `enabled = true`)
468-
cmd.SetArgs([]string{"--stateless", "azure:index:myResource", "patch", "res-1", "--yes", "--input-file", inputFile})
475+
cmd.SetArgs([]string{
476+
"--stateless", "azure:index:myResource", "patch", "res-1", "--yes",
477+
"--input", "pcl", "--input-file", inputFile,
478+
})
469479
err := cmd.Execute()
470480
require.NoError(t, err)
471481
assert.JSONEq(t, `{"id":"res-1","name":"existing","enabled":true}`, stdout.String())
@@ -489,7 +499,7 @@ func TestDoCmdResourceList(t *testing.T) {
489499
},
490500
})
491501
inputFile := writeHCLFile(t, "list.pcl", `prefix = "prod"`)
492-
cmd.SetArgs([]string{"azure:index:myResource", "list", "--input-file", inputFile})
502+
cmd.SetArgs([]string{"azure:index:myResource", "list", "--input", "pcl", "--input-file", inputFile})
493503
err := cmd.Execute()
494504
require.NoError(t, err)
495505
require.Len(t, calls, 1)
@@ -616,7 +626,10 @@ func TestDoCmdResourceConfirmationSummary(t *testing.T) {
616626
},
617627
})
618628
inputFile := writeHCLFile(t, "inputs.pcl", `name = "example"`)
619-
cmd.SetArgs([]string{"--stateless", "azure:index:myResource", "create", "--yes", "--input-file", inputFile})
629+
cmd.SetArgs([]string{
630+
"--stateless", "azure:index:myResource", "create", "--yes",
631+
"--input", "pcl", "--input-file", inputFile,
632+
})
620633
require.NoError(t, cmd.Execute())
621634
assert.Contains(t, stderr.String(), "This will create azure:index:myResource")
622635
assert.NotContains(t, stdout.String(), "This will create")
@@ -651,7 +664,10 @@ func TestDoCmdResourceConfirmationSummary(t *testing.T) {
651664
},
652665
})
653666
inputFile := writeHCLFile(t, "patch.pcl", `name = "new"`)
654-
cmd.SetArgs([]string{"--stateless", "azure:index:myResource", "patch", "res-1", "--yes", "--input-file", inputFile})
667+
cmd.SetArgs([]string{
668+
"--stateless", "azure:index:myResource", "patch", "res-1", "--yes",
669+
"--input", "pcl", "--input-file", inputFile,
670+
})
655671
require.NoError(t, cmd.Execute())
656672
assert.Contains(t, stderr.String(), "This will update azure:index:myResource")
657673
assert.Contains(t, stderr.String(), "~ name")

‎pkg/cmd/pulumi/do/do_test.go‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -987,7 +987,7 @@ stack = stack()
987987
cmd := NewDoCmd(mlm, mws, loader, testHost, panicLoadConverterPlugin)
988988
cmd.SetOut(&stdout)
989989
cmd.SetErr(&stdout)
990-
cmd.SetArgs([]string{"azure:index:myFunction", "--input-file", inputFile})
990+
cmd.SetArgs([]string{"azure:index:myFunction", "--input", "pcl", "--input-file", inputFile})
991991
require.NoError(t, cmd.Execute())
992992
}
993993

@@ -1057,7 +1057,7 @@ func TestDoCmdFunctionInvokeWithoutStackContext(t *testing.T) {
10571057
cmd := NewDoCmd(mlm, mws, loader, testHost, panicLoadConverterPlugin)
10581058
cmd.SetOut(&stdout)
10591059
cmd.SetErr(&stdout)
1060-
cmd.SetArgs([]string{"azure:index:myFunction", "--input-file", inputFile})
1060+
cmd.SetArgs([]string{"azure:index:myFunction", "--input", "pcl", "--input-file", inputFile})
10611061
require.NoError(t, cmd.Execute())
10621062
})
10631063

@@ -1075,7 +1075,7 @@ func TestDoCmdFunctionInvokeWithoutStackContext(t *testing.T) {
10751075
cmd := NewDoCmd(mlm, mws, loader, testHost, panicLoadConverterPlugin)
10761076
cmd.SetOut(&stdout)
10771077
cmd.SetErr(&stdout)
1078-
cmd.SetArgs([]string{"azure:index:myFunction", "--input-file", inputFile})
1078+
cmd.SetArgs([]string{"azure:index:myFunction", "--input", "pcl", "--input-file", inputFile})
10791079
err := cmd.Execute()
10801080
require.ErrorContains(t, err, "organization is not supported")
10811081
})

0 commit comments

Comments
 (0)