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

Failing to get AZURE_PARAMETER_DEFAULTS working #2523

Closed
AlexanderSehr opened this issue Sep 2, 2024 · 10 comments
Closed

Failing to get AZURE_PARAMETER_DEFAULTS working #2523

AlexanderSehr opened this issue Sep 2, 2024 · 10 comments
Labels
bug Something isn't working downstream An issue for downstream tracking of PSRule repositories

Comments

@AlexanderSehr
Copy link

AlexanderSehr commented Sep 2, 2024

Hey @BernieWhite, I hope you're doing well.

We recently introduced a new feature to the AVM CI that leds users pass secrets from a KeyVault into our test deployments. Part of that solution is to add a required @secure() parameter to the test file in question.

When running PSRule on those files, we noticed that it would complain about that parameter because it did not have a default. So far so good.

I found that you responded to a very similar issue and implemented a feature that allows you to define defaults for such parameters in the ps-rule.yml file.

Now, I wanted to use just that for our purposes and defined the following fallback values:

configuration:
  (...)
  AZURE_PARAMETER_DEFAULTS:
    backupManagementServiceEnterpriseApplicationObjectId: $GUID_PLACEHOLDER$
    azureDatabricksEnterpriseApplicationObjectId: $GUID_PLACEHOLDER$
    lighthouseManagedByTenantId: $GUID_PLACEHOLDER$

Matching our input parameters like this one:

@description('Required. The object id of the Backup Management Service Enterprise Application. This value is tenant-specific and must be stored in the CI Key Vault in a secret named \'CI-BackupManagementServiceEnterpriseApplicationObjectId\'.')
@secure()
param backupManagementServiceEnterpriseApplicationObjectId string

However, if I run the pipeline using that configuration, it appears that this setting is ignored:

Error: Failed to expand bicep source '/home/runner/work/bicep-registry-modules/bicep-registry-modules/avm/res/compute/virtual-machine/tests/e2e/waf-aligned/main.test.bicep'. Exception calling "GetBicepResources" with "2" argument(s): "Unable to expand resources because the source file '/home/runner/work/bicep-registry-modules/bicep-registry-modules/avm/res/compute/virtual-machine/tests/e2e/waf-aligned/main.test.bicep' was not valid. An error occurred evaluating expression '[parameters('backupManagementServiceEnterpriseApplicationObjectId')]' line 109. The parameter named 'backupManagementServiceEnterpriseApplicationObjectId' was not set or a defaultValue was defined."

I doublechecked if the settings file is in fact used, and it seems to be correctly configured.

Would you happen to know if I'm missing anything? In the docs it sounds like that should do the trick, yet here I am.

@AlexanderSehr AlexanderSehr added the question Further information is requested label Sep 2, 2024
@BernieWhite
Copy link
Member

Hi @AlexanderSehr, Thanks for reporting the issue.

I think this is a specific about how this option is loaded during expansion. It only operates from ps-rule.yaml found in the working path, which may not work based on you are overriding option: in your pipeline to a different option file.

You should be fine as a workaround to add this AZURE_PARAMETER_DEFAULTS key to a separate ps-rule.yaml file in the working path/ repo root leaving the other configuration values where they are.

But agree it's not ideal, confusing, and we'll work on a fix.

@BernieWhite BernieWhite added bug Something isn't working downstream An issue for downstream tracking of PSRule repositories and removed question Further information is requested labels Sep 3, 2024
@BernieWhite
Copy link
Member

@AlexanderSehr This should be fixed in PSRule for Azure v1.39.0 when it is released.

@BernieWhite
Copy link
Member

@AlexanderSehr PSRule for Azure - Pre-release 1.39.0-B0072 includes this fix. Please double check this fix resolves your issue. I couldn't find your working branch to double check myself.

@AlexanderSehr
Copy link
Author

Hey @BernieWhite, I was out of office the last 2 weeks so I was not able to validate it yet. Will do as soon as I caught up 💪

@AlexanderSehr
Copy link
Author

Hey @BernieWhite,
just a quipck update on my part. I did retest the logic a few days ago - yielding the same results (ref).
Did I understand you correctly that the fix you implemented should've made the AZURE_PARAMETER_DEFAULTS usable from the file defined via the option: configuration? For example: option: "${{ github.workspace }}/${{ env.psrulePath}}/ps-rule.yaml" # Path to PSRule configuration options file - OR - was this instead addressed via an update to the docs that the feature is not compatible with the use of option:?

@BernieWhite BernieWhite reopened this Nov 11, 2024
@BernieWhite
Copy link
Member

@AlexanderSehr Thanks for the ref. Double checked with this and found a related issue. Can you please retest with the latest preview PSRule for Azure v1.40.0-B0147.

@AlexanderSehr
Copy link
Author

@AlexanderSehr Thanks for the ref. Double checked with this and found a related issue. Can you please retest with the latest preview PSRule for Azure v1.40.0-B0147.

Hey @eriqua,
would you know where we can configure that in our setup?

@eriqua
Copy link

eriqua commented Nov 11, 2024

Hey @AlexanderSehr,
The job running PSRule reliability pillar is already using the latest released version of PSRule.Rules.Azure by default. Hence a rerun of your dev branch should be enough.

@AlexanderSehr
Copy link
Author

Hey @eriqua, is that also true for preview versions? Interesting. WIll test.

@AlexanderSehr
Copy link
Author

@BernieWhite, that seemed to have done the trick. Thanks for the update 💪
We should be able to close this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working downstream An issue for downstream tracking of PSRule repositories
Projects
None yet
Development

No branches or pull requests

3 participants