Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support variable imports in .bicepparam files #11879

Merged
merged 6 commits into from
Sep 27, 2023

Conversation

jeskew
Copy link
Contributor

@jeskew jeskew commented Sep 18, 2023

Resolves #11878

This PR adds support for import statements to .bicepparam files. Importing a type symbol into a bicepparam file will raise an error diagnostic, but variables can be imported from local bicep files, template specs, or modules in a remote registry.

Microsoft Reviewers: Open in CodeFlow

@github-actions
Copy link
Contributor

github-actions bot commented Sep 18, 2023

Test this change out locally with the following install scripts (Action run 6326775352)

VSCode
  • Mac/Linux
    bash <(curl -Ls https://aka.ms/bicep/nightly-vsix.sh) --run-id 6326775352
  • Windows
    iex "& { $(irm https://aka.ms/bicep/nightly-vsix.ps1) } -RunId 6326775352"
Azure CLI
  • Mac/Linux
    bash <(curl -Ls https://aka.ms/bicep/nightly-cli.sh) --run-id 6326775352
  • Windows
    iex "& { $(irm https://aka.ms/bicep/nightly-cli.ps1) } -RunId 6326775352"

@github-actions
Copy link
Contributor

github-actions bot commented Sep 18, 2023

Test Results

     132 files  ±  0       132 suites  ±0   3h 18m 16s ⏱️ - 8m 50s
10 557 tests +  4  10 557 ✔️ +  4  0 💤 ±0  0 ±0 
50 779 runs  +16  50 779 ✔️ +16  0 💤 ±0  0 ±0 

Results for commit 525e21a. ± Comparison against base commit 4f24f39.

♻️ This comment has been updated with latest results.

@jeskew
Copy link
Contributor Author

jeskew commented Sep 20, 2023

Discussed this feature with @anthony-c-martin and decided to add a few extra checks to make sure this work will be compatible with importing parameter assignment symbols, to wit:

  • The @export() decorator is blocked in .bicepparam files (it was unclear if that would be required on param statements, and it would be odd to require a decorator on var statements but not on param statements.
  • Importing a type symbol into a bicepparam file will raise an error diagnostic.

Copy link
Member

@anthony-c-martin anthony-c-martin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great!

@jeskew jeskew merged commit 8ffd934 into main Sep 27, 2023
47 checks passed
@jeskew jeskew deleted the jeskew/imports-in-bicepparam-files branch September 27, 2023 13:38
jeskew added a commit that referenced this pull request Oct 4, 2023
…12048)

Resolves #12042 

#11879 introduced a regression in references to variables imported with
via wildcard syntax were represented in a template's compiled form. For
example,

```
import * as mod from 'mod.bicep'
output s string = mod.s
```

would generate a value of `"[variables('mod').s]"` in the compiled
template. When implementing variable imports for `.bicepparam` files, I
took the shortcut of generating a object value for wildcard imports
whose properties were all the variables exported from the imported
model. There was a gap in test coverage for variable imports in `.bicep`
files, so the regression was not picked up. This PR updates how wildcard
imports are handled in `.bicepparam` files to remove the aforementioned
shortcut.

The PR also adds an extra step in `TemplateWriter`: after `.bicep` files
are converted to the compiler's intermediate representation, expressions
referring to imported values are replaced with expressions that refer to
"synthetic" variables and types.
###### Microsoft Reviewers: [Open in
CodeFlow](https://microsoft.github.io/open-pr/?codeflow=https://github.com/Azure/bicep/pull/12048)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Compile-time imports should be allowed in .bicepparam files
2 participants