azurerm_subnet
- support for direct network_security_group_id
assignment during subnet creation
#28985
+202
−0
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This PR improves the Terraform AzureRM provider by enabling the assignment of a Network Security Group (NSG) directly during subnet creation. This change addresses compatibility issues encountered with Azure Policy enforcement, particularly in environments utilising the Enterprise-Scale Azure Landing Zone, which enforces a custom Azure Policy that explicitly denies subnet creation unless an NSG is attached.
Previously, the
azurerm_subnet
resource did not permit NSG assignment at creation time, leading to deployment failures in policy-restricted environments.Note for Testers:
Please note that the custom policy applied in the Enterprise-Scale Azure Landing Zone differs from the similarly named built-in Azure Policy. The built-in policy employs an
AuditIfNotExists
effect, whereas the custom policy uses a stricterDeny
effect.Community Note
PR Checklist
For example: “
resource_name_here
- description of change e.g. adding propertynew_property_name_here
”Changes to existing Resource / Data Source
Testing
My submission includes Test coverage as described in the Contribution Guide and the tests pass. (if this is not possible for any reason, please include details of why you did or could not add test coverage)
Allows
network_security_group_id
to be specified at the time of subnet creation.Acceptance tests have been updated to cover this scenario, accounting for environment-specific constraints.
Tests affected by strict Azure policies are conditionally skipped via the environment variable (
TF_ACC_SKIP_EMPTY_NSG_TEST
).Acceptance Tests Output
Scenario1: With
TF_ACC_SKIP_EMPTY_NSG_TEST
set:Scenario 2: Without
TF_ACC_SKIP_EMPTY_NSG_TEST
, where the environment permits subnets without NSGs:Scenario 3: Without
TF_ACC_SKIP_EMPTY_NSG_TEST
, where the environment denies subnets without NSGs:NOTE: Scenario 3 is intended to demonstrate a failure condition, emphasising the necessity of using the conditional environment variable to control behaviour rather than silently masking potential issues.
Change Log
Below please provide what should go into the changelog (if anything) conforming to the Changelog Format documented here.
azurerm_subnet
- support for directnetwork_security_group_id
assignment during subnet creation [GH-00000]This is a (please select all that apply):
Related Issue(s)
Fixes #28701
Note
If this PR changes meaningfully during the course of review please update the title and description as required.