Skip to content

Conversation

tsmallig33
Copy link
Contributor

@tsmallig33 tsmallig33 commented Aug 1, 2025

Description

Adds this.exists() for use in resource properties. Should be blocked from usage in all other places as it is a runtime function.

Example Usage

resource storageAccount 'Microsoft.Storage/storageAccounts@2021-09-01' = {
  name: 'mystorageaccount'
  location: 'eastus'
  sku: {
    name: 'Standard_LRS'
  }
  kind: 'StorageV2'
  properties: {
    minimumTlsVersion: 'TLS1_2'
    publicNetworkAccess: this.exists() ? 'Enabled' : 'Disabled'
  }
}

Checklist

Microsoft Reviewers: Open in CodeFlow

Copy link
Contributor

github-actions bot commented Aug 1, 2025

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

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

Copy link
Contributor

github-actions bot commented Aug 1, 2025

Dotnet Test Results

    96 files   -     48      96 suites   - 48   41m 21s ⏱️ - 35m 28s
12 434 tests +     4  12 434 ✅ +     4  0 💤 ±0  0 ❌ ±0 
28 613 runs   - 14 249  28 613 ✅  - 14 249  0 💤 ±0  0 ❌ ±0 

Results for commit f1f4fe6. ± Comparison against base commit f37ea76.

This pull request removes 1917 and adds 669 tests. Note that renamed tests count towards both.

		nestedProp1: 1
		nestedProp2: 2
		prop1: true
		prop2: false
	1
	2
	\$'")
	prop1: true
	prop2: false
…
Bicep.Core.IntegrationTests.AzTypesViaRegistryTests ‑ Bicep_compiler_handles_corrupted_extension_package_gracefully (\u001f�\u0008\u0000\u0000\u0000\u0000\u0000\u0000
�ӽ
�0\u0010\u0007��>E�\u0003�;{I���Ep�\u0001�=�b��\u0015
�\u001b\u0007q��h+��x9����K���e\Պ\u0010h�ħ�g�^�@�\u0000\u0002��\u0015!ۏO�¹n\�G�c�\u001f4I�k�S�\u0006(!0Z�Am�8�k��5�ʓkvi^fܪ}},��EW���\u000c:<��{W�.�\u0010�@
6�ZDŽ��\u001c\u001d�����?��EF���\u0013o\u001a�\u0016\���fr�\u000e5_��-\u0008� ��\u001b�϶|\u0000\u000c\u0000\u0000,"Value cannot be null. (Parameter 'source')")
Bicep.Core.IntegrationTests.AzTypesViaRegistryTests ‑ Bicep_compiler_handles_corrupted_extension_package_gracefully (\u001f�\u0008\u0000\u0000\u0000\u0000\u0000\u0000
�ӽ\u000e�0\u0010\u0007��>\u0005OP��\u001dŁ��Wh�ďP\u000c�@b|w�`�\u0000qA0����K���e�7��0Ǣn$!P,���K�F�\u0007�(P��\u0000ͤ����'\u0019�6��~�%��A*��;�E�:\u0005��/Jn3�\u0018x�k��\u001aF7�Nyk��ꬼ4�\u001d\u001aʩ��\u001f\u001a�z�߷��S�\u0001�@\u0006�0sBC�1a��E2����?֞ \u0008� X�\u0013��\u001c�\u0000\u000c\u0000\u0000,"The path: index.json was not found in artifact contents")
Bicep.Core.IntegrationTests.AzTypesViaRegistryTests ‑ Bicep_compiler_handles_corrupted_extension_package_gracefully (\u001f�\u0008\u0000\u0000\u0000\u0000\u0000\u0000
�Խ
�0\u0010\u0000��>E�\u0001һ��T�Ap�"*\u0008�\u0012l�
��V(���A\Z\�#�o�;����ݝ��Z�:/8!��Y��\u0008�j�/H��|\u0003\u0006R�\u0008s��;�q/J��V�X�\u0007y���$�3�\u0001PH\u0010\u0008\u000e~�#z#�;5�p��Ty�%Y�+~)�٫<m*\u001fz�V���uwD��\u001f<b(@�B\u0008����#<3������c\u001cm\u000e�u�8����x�\u001fx�,˲��=\u0001��y�\u0000\u000c\u0000\u0000,"'7' is an invalid end of a number. Expected a delimiter. Path: $.INVALID_JSON | LineNumber: 0 | BytePositionInLine: 20.")
Bicep.Core.IntegrationTests.AzTypesViaRegistryTests ‑ Bicep_compiler_handles_corrupted_extension_package_gracefully (\u001f�\u0008\u0000\u0000\u0000\u0000\u0000\u0000\u0003��K
�0\u0010\u0006�=EO��4�$��]z��\u0005\u001f4�>� ��t!�HqS\u001b�|�\u000c�L\u0018~��츭�j;.\u0014�������\u000c�O���~\u0001\u0006�\u0008\u0018���7	\u0018�޶~�5f���d�?�U�Z�4�\u0018�(�\u0004�\u001b_���0���X\u000e�⚛��qSC=�\u0010��I����5�S�\u0001
�\u0004Z\u0010i(��\u001f���_%�����#�\u0006I�$I\u000cO����\u0000\u000c\u0000\u0000,"The path: index.json was not found in artifact contents")
Bicep.Core.IntegrationTests.AzTypesViaRegistryTests ‑ Bicep_compiler_handles_corrupted_extension_package_gracefully (\u001f�\u0008\u0000\u0000\u0000\u0000\u0000\u0000\u0003���
�@\u0010\u0000�=�\u0014�\u000f����\u0015x\u0008:d�\u0005A�XR�@\u000b5\u0010z��CtQ��\u0013��qg`f\u0019f����:�qR��\u0017 \��\u0006�`���A�DT�\u0001\u0002�9G\u0008׽w��QV�0��Q�\u0007y
�*͒�J\u0001L1�(��������]1:�w]]�4���\�[ޤg]�S�����p5��?x\u000cQ\u000e��\�G\u0011\u0008n.\u0002£�����	��r\u001b�N��.r\u0016�\�{�,˲��\u0002\u0004��\u0000\u000c\u0000\u0000,"'7' is an invalid end of a number. Expected a delimiter. Path: $.INVALID_JSON | LineNumber: 0 | BytePositionInLine: 20.")
Bicep.Core.IntegrationTests.AzTypesViaRegistryTests ‑ Bicep_compiler_handles_corrupted_extension_package_gracefully (\u001f�\u0008\u0000\u0000\u0000\u0000\u0000\u0000\u0003���
�@\u0010\u0007�=�\u0014�\u000f���~h�KХ\u0007�t"#M\\u0003!z��\u0010]�.~\u0004��30�\u000c��ޛf�&�ʲ@�Z326h)!z�;\h��\u001b\u0010�RJBh3�&=�6U��\u001c�~�\u001fRSg9�\+\u0010�\u0008C�|�\u0014\u0007�jk�P�G�4�9Ί\u0014\u001bv���kχڗ��3�s��f|�?\u0004�p	:�R��	()�<�Y2����P�P`SbRc�������'s��\z7�q\u001cg:/��$I\u0000\u000c\u0000\u0000,"Value cannot be null. (Parameter 'source')")
Bicep.Core.IntegrationTests.DirectResourceCollectionTests ‑ DirectResourceCollectionAccess_NotAllowedWithinLoops ("output loopOutput array = [for i in range(0, 2): {
  prop: map(containerWorkers, (w) => w.properties.ipAddress.ip)
}]")
Bicep.Core.IntegrationTests.DirectResourceCollectionTests ‑ DirectResourceCollectionAccess_NotAllowedWithinLoops ("resource propertyLoop 'Microsoft.ContainerInstance/containerGroups@2022-09-01' = {
  name: 'gh9440-loop'
  location: 'westus'
  properties: {
    containers: [for i in range(0, 2): {
      name: 'gh9440-w1c-${i}'
      properties: {
        command: [
          'echo "${join(map(containerWorkers, (w) => w.properties.ipAddress.ip), ',')}"'
        ]
      }
    }]
  }
}")
Bicep.Core.IntegrationTests.DirectResourceCollectionTests ‑ DirectResourceCollectionAccess_NotAllowedWithinLoops ("var loopVar = [for i in range(0, 2): {
  prop: map(containerWorkers, (w) => w.properties.ipAddress.ip)
}]")
Bicep.Core.IntegrationTests.Emit.ParamsFileWriterTests ‑ Params_file_with_no_errors_should_compile_correctly ("
using 'main.bicep'

// involves all syntax
param myParam = {
  arr: [
    {
      a : 'b'
    }
    {
      c : true
    }
  ]
  name: 'complex object!'
  priority: 3
  val: null
  obj: {
      a: 'b'
      c: [
          'd'
           1
      ]
  }
}","
{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "myParam": {
      "value": {
        "arr" : [
          {
            "a" : "b"
          },
          {
            "c" : true
          }
        ],
        "name" : "complex object!",
        "priority" : 3,
        "val" : null,
        "obj" : {
          "a" : "b",
          "c" : [
            "d",
            1
          ]
        }
      }
    }
  }
}","
param myParam object
")
…

♻️ This comment has been updated with latest results.

@tsmallig33 tsmallig33 marked this pull request as ready for review August 1, 2025 20:53
@tsmallig33 tsmallig33 requested a review from Copilot August 4, 2025 14:22
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR introduces this().exists as an experimental feature for Bicep, allowing developers to conditionally modify resource properties based on whether the resource already exists during deployment. The feature requires explicit enablement through experimental flags and is restricted to resource property contexts only.

Key changes:

  • Adds a new experimental feature flag thisExistsFunction with configuration support
  • Implements the this() function that returns an object with an exists property
  • Restricts usage to resource properties only, with proper validation and error handling

Reviewed Changes

Copilot reviewed 19 out of 19 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/vscode-bicep/schemas/bicepconfig.schema.json Adds schema definition for the new thisExistsFunction experimental feature
src/Bicep.Core/Semantics/Namespaces/AzNamespaceType.cs Implements the this() function with context validation and return type definition
src/Bicep.Core/Semantics/Namespaces/NamespaceProvider.cs Passes feature provider to namespace creation for conditional function registration
src/Bicep.Core/Intermediate/ Adds new ThisFunctionExpression type and visitor pattern support
src/Bicep.Core/Emit/ExpressionConverter.cs Converts this().exists to ARM template targetExists() function
src/Bicep.Core/Features/ Adds feature flag support across the feature provider infrastructure
src/Bicep.Core/Diagnostics/DiagnosticBuilder.cs Adds error message for invalid usage contexts
src/Bicep.Core/Configuration/ExperimentalFeaturesEnabled.cs Extends configuration to include the new experimental feature
Tests and documentation files Comprehensive test coverage and documentation for the new feature
Comments suppressed due to low confidence (1)

@tsmallig33 tsmallig33 requested a review from jeskew August 4, 2025 15:02
@tsmallig33 tsmallig33 changed the title Add this().exists as an experimental feature Add this.exists() as an experimental feature Aug 6, 2025
@tsmallig33 tsmallig33 marked this pull request as draft August 6, 2025 18:31
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.

1 participant