Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Oct 9, 2025

Fix firewall rule validation error and enable descriptions for both network and application rules

This PR addresses the issue where firewall rule descriptions can be empty strings, causing Terraform validation errors.

Changes Completed:

  • Update Terraform rules.tf to handle empty/null descriptions for both network and application rules
  • Enable description field for network rules (was previously commented out)
  • Set description to null when not provided or empty (respecting optional field behavior)
  • Update documentation to clarify description behavior for both rule types
  • Update template_schema.json to validate descriptions properly
  • Fix Terraform formatting
  • Update CHANGELOG.md with correct issue number
  • Bump firewall porter.yaml version to 1.6.0

Technical Details:

Problem: When deploying firewall rules via template_schema.json, if a rule's description is an empty string or not provided, it could cause validation errors.

Solution:

  1. Terraform Code (templates/shared_services/firewall/terraform/rules.tf):

    • Enabled description for network rules (was commented out)
    • Both network and application rules now use: description = try(length(trimspace(rule.value.description)) > 0 ? rule.value.description : null, null)
    • When no description provided or empty string, description is set to null (truly optional field)
    • Fixed formatting to match Terraform standards
  2. Schema Validation (templates/shared_services/firewall/template_schema.json):

    • Removed default: "" from both rule types (description is now optional)
    • Changed pattern from ^.*$ to ^.+$ to reject empty strings
    • Removed "DEPRECATED" label from network rule descriptions
    • Both rule types now have consistent validation
  3. Documentation (docs/tre-workspace-authors/firewall-rules.md):

    • Clarified that both network and application rules support descriptions
    • Noted that if no description is provided, it will be omitted (set to null)
  4. Versioning:

Behavior:

  • ✅ Valid non-empty descriptions are preserved
  • ✅ Empty string descriptions are rejected by schema validation
  • ✅ Omitted descriptions are set to null in Terraform (optional field)
  • ✅ Whitespace-only descriptions are treated as empty and set to null
  • ✅ Both network and application rules have consistent behavior
  • ✅ Aligns with Azure REST API documentation

Impact:

  • ✅ Fixes the reported deployment failure
  • ✅ Backward compatible (existing templates with descriptions work unchanged)
  • ✅ Schema prevents empty strings from being submitted
  • ✅ Descriptions remain truly optional - if not provided, they're omitted
  • ✅ Respects user intent by not substituting values
  • ✅ Code follows Terraform formatting standards

Fixes #4691

Original prompt

This section details on the original issue you should resolve

<issue_title>firewall pipeline step in template_schema.json fails if rule description is an empty string or not set</issue_title>
<issue_description>In the firewall template_schema.json description defaults to an empty string. When an empty string is provided to terraform for the rule description an error occurs. Azure firewall policy rules do not actually contain a description field and is commented out for network rules

# description = rule.value.description

the application rule however description is optional but if set it can't be an empty string due to the error it produces.

https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/firewall_policy_rule_collection_group#description-1

There is inconsistent behaviour between "network_rule_collections" which has descriptions marked as deprecated (and commented out in terraform) but "rule_collections" which still accept a description but defaults to blank causing this error. It would be better if they behaved the same, either both taking descriptions (and putting a non-empty string requirement) or removing that entirely (name should be sufficient)

as a minimum application rules should not accept empty strings for the description field

Describe the bug
firewall pipeline step in template_schema.json fails if rule description is an empty string or not set

Error: expected "application_rule_collection.8.rule.4.description" to not be an empty string, got

with azurerm_firewall_policy_rule_collection_group.dynamic_application,
on rules.tf line 36, in resource "azurerm_firewall_policy_rule_collection_group" "dynamic_application":
36: resource "azurerm_firewall_policy_rule_collection_group" "dynamic_application" {

Steps to reproduce

  1. Create a firewall application rule collection "rule_collections" in a pipeline via template_schema.json.
  2. Create a rule without a description set
  3. Deploy the bundle and observe the error

**Azure TRE release version 0.25.0 **

Deployed Azure TRE components

Azure TRE
UI Version:
0.8.15
API Version:
0.24.5

            "name": "rule_collections",
              "type": "array",
              "arraySubstitutionAction": "replace",
              "arrayMatchField": "name",
              "value": {
                "name": "arc_svc_{{ resource.id }}",
                "action": "Allow",
                "rules": [
                {
                  "name": "Azure",
                  "description": "Allow Azure", <--- To reproduce don't set this or set it to an empty string
                  "source_addresses": "{{ resource.properties.service_addresses }}",
                  "protocols": [
                    {
                      "type": "Https",
                      "port": "443"
                    }
                  ],
                  "fqdn_tags": [
                    "AzureCloud"
                  ]

                }
```</issue_description>

<agent_instructions>I think we go for both taking descriptions and having a none empty string requirement.</agent_instructions>

## Comments on the Issue (you are @copilot in this section)

<comments>
<comment_new><author>@marrobi</author><body>
@JC-wk Thanks. I think descriptions can be useful to explain why the rules are there. 

Where is the commented out description field?

I think we go for both taking descriptions and having a none empty string requirement.</body></comment_new>
</comments>

Fixes #4691


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

Co-authored-by: marrobi <17089773+marrobi@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix firewall pipeline step in template_schema.json Fix firewall application rule validation error when description is empty string Oct 9, 2025
Copilot AI requested a review from marrobi October 9, 2025 13:02
@marrobi
Copy link
Member

marrobi commented Oct 9, 2025

@copilot looking at https://learn.microsoft.com/en-us/rest/api/virtualnetwork/firewall-policy-rule-collection-groups/create-or-update?view=rest-virtualnetwork-2024-07-01&tabs=HTTP#networkrule

description is supported for both application and network rules, and is supported in terraform, its should not be deprecated.

Also ensure where no description is given in template schema, the name is used for the terraform.

Blank values, "", are not allowed if used the schema should fail validation,

…name as fallback

Co-authored-by: marrobi <17089773+marrobi@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Oct 9, 2025

@copilot looking at https://learn.microsoft.com/en-us/rest/api/virtualnetwork/firewall-policy-rule-collection-groups/create-or-update?view=rest-virtualnetwork-2024-07-01&tabs=HTTP#networkrule

descr...

Updated to enable descriptions for both network and application rules. When no description is provided or it's an empty string, the rule name is now used as the description. This ensures all rules have meaningful descriptions while preventing validation errors.

Changes in commit 7cc3467 (short hash will update after push).

Copilot AI changed the title Fix firewall application rule validation error when description is empty string Fix firewall rule validation error and enable descriptions for both network and application rules Oct 9, 2025
@marrobi
Copy link
Member

marrobi commented Oct 9, 2025

@copilot also update templates/shared_services/firewall/template_schema.json

Co-authored-by: marrobi <17089773+marrobi@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Oct 9, 2025

@copilot also update templates/shared_services/firewall/template_schema.json

Updated template_schema.json to:

  • Remove "DEPRECATED" label from network rule descriptions
  • Remove default: "" for both rule types (making description optional)
  • Change pattern from ^.*$ to ^.+$ to reject empty strings

This ensures schema validation prevents empty strings from being submitted, while the Terraform code uses the rule name as fallback when description is not provided.

Changes in commit 12ea9a4.

@marrobi
Copy link
Member

marrobi commented Oct 9, 2025

/test d222c32

@github-actions
Copy link

github-actions bot commented Oct 9, 2025

🤖 pr-bot 🤖

🏃 Running tests: https://github.com/microsoft/AzureTRE/actions/runs/18380188201 (with refid 4693dfe6)

(in response to this comment from @marrobi)

@marrobi
Copy link
Member

marrobi commented Oct 9, 2025

@copilot fix

terraform fmt -check -recursive
templates/shared_services/firewall/terraform/rules.tf

Co-authored-by: marrobi <17089773+marrobi@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Oct 9, 2025

@copilot fix

terraform fmt -check -recursive
...

Fixed Terraform formatting by removing extra alignment spacing on the name field in network rules to match the standard Terraform format.

Changes in commit 8c8f281.

@marrobi
Copy link
Member

marrobi commented Oct 9, 2025

/test-destroy-env

Passed

@marrobi marrobi enabled auto-merge (squash) October 14, 2025 08:35
@marrobi
Copy link
Member

marrobi commented Oct 14, 2025

/test-force-approve

Passed: https://github.com/microsoft/AzureTRE/actions/runs/18380188201

@github-actions
Copy link

🤖 pr-bot 🤖

✅ Marking tests as complete (for commit d576eea)

(in response to this comment from @marrobi)

@marrobi marrobi requested a review from Copilot October 14, 2025 08:38
Copy link
Contributor

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 fixes firewall rule validation errors that occur when rule descriptions are empty strings and standardizes description handling across both network and application rules.

  • Enables descriptions for network rules and implements consistent fallback logic for both rule types
  • Updates schema validation to reject empty strings while making descriptions optional
  • Bumps firewall service version to 1.6.0 with appropriate documentation updates

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.

Show a summary per file
File Description
templates/shared_services/firewall/terraform/rules.tf Enables descriptions for network rules and adds fallback logic using rule name when descriptions are empty
templates/shared_services/firewall/template_schema.json Removes default empty strings and updates pattern validation to reject empty descriptions
templates/shared_services/firewall/porter.yaml Bumps version from 1.5.0 to 1.6.0
docs/tre-workspace-authors/firewall-rules.md Updates documentation to clarify description fallback behavior
CHANGELOG.md Adds entry for the firewall validation fix

@tamirkamara tamirkamara self-requested a review October 15, 2025 07:28
Co-authored-by: marrobi <17089773+marrobi@users.noreply.github.com>
Copy link
Collaborator

@JC-wk JC-wk left a comment

Choose a reason for hiding this comment

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

I'm using this now and it's working perfectly for me

@JC-wk JC-wk requested a review from martinpeck October 20, 2025 09:24
@marrobi
Copy link
Member

marrobi commented Nov 7, 2025

@tamirkamara can you take a look at this? Think it's good to go. Thanks.

@marrobi
Copy link
Member

marrobi commented Nov 26, 2025

/test-force-approve

Passed: https://github.com/microsoft/AzureTRE/actions/runs/18380188201

@github-actions
Copy link

🤖 pr-bot 🤖

✅ Marking tests as complete (for commit 7dc2119)

(in response to this comment from @marrobi)

@marrobi marrobi merged commit cd31a1f into main Nov 26, 2025
15 checks passed
@marrobi marrobi deleted the copilot/fix-firewall-pipeline-step branch November 26, 2025 19:47
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.

firewall pipeline step in template_schema.json fails if rule description is an empty string or not set

5 participants