Skip to content

Commit

Permalink
Merge #13479
Browse files Browse the repository at this point in the history
13479: [convert] Consistently use the same non-strict bind options when applicable r=Zaid-Ajaj a=Zaid-Ajaj

# Description

When using `pulumi convert` in non-strict mode, provide a single source of which bind options to use. The newly added options weren't being applied in a few places 


## Checklist

- [ ] I have run `make tidy` to update any new dependencies
- [ ] I have run `make lint` to verify my code passes the lint check
  - [ ] I have formatted my code using `gofumpt`

<!--- Please provide details if the checkbox below is to be left unchecked. -->
- [ ] I have added tests that prove my fix is effective or that my feature works
<!--- 
User-facing changes require a CHANGELOG entry.
-->
- [x] I have run `make changelog` and committed the `changelog/pending/<file>` documenting my change
<!--
If the change(s) in this PR is a modification of an existing call to the Pulumi Cloud,
then the service should honor older versions of the CLI where this change would not exist.
You must then bump the API version in /pkg/backend/httpstate/client/api.go, as well as add
it to the service.
-->
- [ ] Yes, there are changes in this PR that warrants bumping the Pulumi Cloud API version
  <!-- `@Pulumi` employees: If yes, you must submit corresponding changes in the service repo. -->


Co-authored-by: Zaid Ajaj <zaid.naom@gmail.com>
  • Loading branch information
bors[bot] and Zaid-Ajaj committed Jul 13, 2023
2 parents 772a057 + 5841f22 commit 3451a7d
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 22 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
changes:
- type: chore
scope: programgen
description: Consistently use the same non-strict bind options when applicable
14 changes: 2 additions & 12 deletions pkg/cmd/pulumi/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,11 +153,7 @@ func safePclBindDirectory(sourceDirectory string, loader schema.ReferenceLoader,

extraOptions := make([]pcl.BindOption, 0)
if !strict {
extraOptions = append(extraOptions, []pcl.BindOption{
pcl.AllowMissingProperties,
pcl.AllowMissingVariables,
pcl.SkipResourceTypechecking,
}...)
extraOptions = append(extraOptions, pcl.NonStrictBindOptions()...)
}

program, diagnostics, err = pcl.BindDirectory(sourceDirectory, loader, extraOptions...)
Expand Down Expand Up @@ -191,13 +187,7 @@ func generatorWrapper(generator projectGeneratorFunc, targetLanguage string) pro

extraOptions := make([]pcl.BindOption, 0)
if !strict {
extraOptions = append(extraOptions, []pcl.BindOption{
pcl.AllowMissingProperties,
pcl.AllowMissingVariables,
pcl.SkipResourceTypechecking,
pcl.SkipInvokeTypechecking,
pcl.SkipRangeTypechecking,
}...)
extraOptions = append(extraOptions, pcl.NonStrictBindOptions()...)
}

if targetLanguage == "python" {
Expand Down
12 changes: 12 additions & 0 deletions pkg/codegen/pcl/binder.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,18 @@ func ComponentBinder(binder ComponentProgramBinder) BindOption {
}
}

// NonStrictBindOptions returns a set of bind options that make the binder lenient about type checking.
// Changing errors into warnings when possible
func NonStrictBindOptions() []BindOption {
return []BindOption{
AllowMissingVariables,
AllowMissingProperties,
SkipResourceTypechecking,
SkipInvokeTypechecking,
SkipRangeTypechecking,
}
}

// BindProgram performs semantic analysis on the given set of HCL2 files that represent a single program. The given
// host, if any, is used for loading any resource plugins necessary to extract schema information.
func BindProgram(files []*syntax.File, opts ...BindOption) (*Program, hcl.Diagnostics, error) {
Expand Down
6 changes: 1 addition & 5 deletions sdk/go/pulumi-language-go/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -1019,11 +1019,7 @@ func (host *goLanguageHost) GenerateProject(

extraOptions := make([]pcl.BindOption, 0)
if !req.Strict {
extraOptions = append(extraOptions, []pcl.BindOption{
pcl.AllowMissingProperties,
pcl.AllowMissingVariables,
pcl.SkipResourceTypechecking,
}...)
extraOptions = append(extraOptions, pcl.NonStrictBindOptions()...)
}

program, diags, err := pcl.BindDirectory(req.SourceDirectory, loader, extraOptions...)
Expand Down
6 changes: 1 addition & 5 deletions sdk/nodejs/cmd/pulumi-language-nodejs/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -1035,11 +1035,7 @@ func (host *nodeLanguageHost) GenerateProject(
loader := schema.NewPluginLoader(pluginCtx.Host)
extraOptions := make([]pcl.BindOption, 0)
if !req.Strict {
extraOptions = append(extraOptions, []pcl.BindOption{
pcl.AllowMissingProperties,
pcl.AllowMissingVariables,
pcl.SkipResourceTypechecking,
}...)
extraOptions = append(extraOptions, pcl.NonStrictBindOptions()...)
}

// for nodejs, prefer output-versioned invokes
Expand Down

0 comments on commit 3451a7d

Please sign in to comment.