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

allow using none statements in bicepparam files at build-params command #15107

Merged

Conversation

polatengin
Copy link
Member

@polatengin polatengin commented Sep 18, 2024

When

  • there are multiple projects with a very similar infrastructure needs (usually encountered in software shops)
  • there are multiple layers in the same project with very similar infrastructure needs (usually encountered in multi-tenant softwares)

There should be multiple .bicep files (per project, per layer, etc.) and multiple .bicepparam files pairing with .bicep files (with using {filename}.bicep statements in .bicepparam files)

When az deployment group create --resource-group $rgname --name $rgname --template-file ./main.bicep --parameters ./main.bicepparam command executed, az cli downstreams the parameters to bicep build-params command.

Since the .bicep and .bicepparam files are paired with the using statement in .bicepparam file, it's not possible to re-use the same .bicepparam file with multiple deployments.

This PR relaxes the check in the build-params command that requires the using statement in the .bicepparam file points to the same .bicep file as the build-params command arguments

So, if the .bicepparam file has a using none statement, it'll be possible to use the same .bicepparam file in multiple deployments.


Testing the PR

git worktree add /tmp/bicep-allow-using-none polatengin/allow-using-none-statements-build-params

// main.bicep
param bar string
// main.bicepparam
using none
param bar = 'foo'

When you run the following command;

dotnet run --project src/Bicep.Cli/Bicep.Cli.csproj -- build-params ./main.bicepparam --bicep-file ./main.bicep --stdout

It fails with the following error message; Bicep file ./main.bicep provided with --bicep-file can only be used if the Bicep parameters "using" declaration refers to a Bicep file on disk.

With the changes in this PR, same command runs successfully and builds the main.bicepparam file

BuildParamsCommandTests

I also added a test (https://github.com/Azure/bicep/pull/15107/files#diff-30f70729cbd5bcbfb69d4edd8ff3fa9bee94690e92f5e3e86ac9a7eb98b3f550R431) to ensure the build-params command successfully builds given .bicepparam file when there is a using none statement instead of a using {filename}.bicep statement in the .bicepparam file.


Microsoft Reviewers: Open in CodeFlow

@polatengin polatengin self-assigned this Sep 18, 2024
Copy link
Contributor

github-actions bot commented Sep 18, 2024

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

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

Copy link
Contributor

github-actions bot commented Sep 18, 2024

Dotnet Test Results

    72 files   -     36      72 suites   - 36   29m 14s ⏱️ - 12m 6s
11 358 tests  -     24  11 358 ✅  -     24  0 💤 ±0  0 ❌ ±0 
26 447 runs   - 13 216  26 447 ✅  - 13 216  0 💤 ±0  0 ❌ ±0 

Results for commit 67cafd2. ± Comparison against base commit e7884b8.

♻️ This comment has been updated with latest results.

@polatengin polatengin marked this pull request as ready for review October 15, 2024 23:49
@@ -63,14 +63,17 @@ public async Task<int> RunAsync(BuildParamsArguments args)
if (bicepFileUri is not null &&
compilation.GetEntrypointSemanticModel().Root.TryGetBicepFileSemanticModelViaUsing().IsSuccess(out var usingModel))
{
if (usingModel is not SemanticModel bicepSemanticModel)
Copy link
Member

@anthony-c-martin anthony-c-martin Oct 23, 2024

Choose a reason for hiding this comment

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

How does this work with Azure CLI if the user doesn't provide a template? E.g. here. Would this cause an error?

Copy link
Member Author

@polatengin polatengin Nov 3, 2024

Choose a reason for hiding this comment

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

I have the following content in main.bicep and main.bicepparam files;

// main.bicep
param bar string
// main.bicepparam
using none
param bar = 'foo'

When I run the following command, it successfully build the files;

dotnet run --project src/Bicep.Cli/Bicep.Cli.csproj -- build-params ./main.bicepparam --bicep-file ./main.bicep --stdout

If I understand your comment correctly, you're asking what happens if we don't provide --bicep-file ./main.bicep option;

dotnet run --project src/Bicep.Cli/Bicep.Cli.csproj -- build-params ./main.bicepparam --stdout

I ran the command and saw it successfully build the main.bicepparam file.

@polatengin polatengin merged commit edae013 into main Nov 9, 2024
47 checks passed
@polatengin polatengin deleted the polatengin/allow-using-none-statements-build-params branch November 9, 2024 03:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants