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

[AVM Module Issue]: avm/ptn/lz/sub-vending: Re-running tries to delete a subnet (and possibly more) #3330

Closed
1 task done
cspring86 opened this issue Sep 18, 2024 · 9 comments · Fixed by #3366
Closed
1 task done
Assignees
Labels
Class: Pattern Module 📦 This is a pattern module Needs: Attention 👋 Reply has been added to issue, maintainer to review Needs: Triage 🔍 Maintainers need to triage still Type: AVM 🅰️ ✌️ Ⓜ️ This is an AVM related issue

Comments

@cspring86
Copy link

Check for previous/existing GitHub issues

  • I have checked for previous/existing GitHub issues

Issue Type?

I'm not sure

Module Name

avm/ptn/lz/sub-vending

(Optional) Module Version

0.1.2

Description

I've got an Azure subscription vending repository using Bicep and Azure DevOps pipelines to manage the creation, update and cancelling of Azure subscriptions.

I'm using the avm/ptn/lz/sub-vending module to handle the subscription creation/update part of the process.

I've created a subscription using the module, which went fine.

Another team has then proceeded to populate the VNet with subnets and other resources, as expected. One of these resources is an AKS cluster.

I've since re-run the pipeline to update the same subscription by enabling more resource providers in the avm/ptn/lz/sub-vending module configuration and it fails trying to delete one of the subnets.

The bottom-most error message in a nested stack of messages is this:

{
    "code": "InUseSubnetCannotBeDeleted",
    "message": "Subnet alz-spoke-t2awudh7kzl5o-eastus2-subnet-AKS is in use by /subscriptions/xxx/resourceGroups/MC_rg-alz-landingzones-online_xxx-akscluster_eastus2/providers/Microsoft.Network/networkInterfaces/|providers|Microsoft.Compute|virtualMachineScaleSets|aks-agentpool-xxx-vmss|virtualMachines|0|networkInterfaces|aks-agentpool-xxx-vmss/ipConfigurations/ipconfig1 and cannot be deleted. In order to delete the subnet, delete all the resources within the subnet. See aka.ms/deletesubnet.",
    "details": []
}

Is this expected behaviour?

I thought Bicep ran in incremental mode by default, not complete mode, so it shouldn't be attempting to delete anything.

I need the avm/ptn/lz/sub-vending module to be able to create and update subscriptions when needed, such that it only updates the configuration/resources that it owns. I don't want it to interfere with resources created outside of it.

(Optional) Correlation Id

No response

@cspring86 cspring86 added Needs: Triage 🔍 Maintainers need to triage still Type: AVM 🅰️ ✌️ Ⓜ️ This is an AVM related issue labels Sep 18, 2024
@avm-team-linter avm-team-linter bot added the Class: Pattern Module 📦 This is a pattern module label Sep 18, 2024
Copy link

@cspring86, thanks for submitting this issue for the avm/ptn/lz/sub-vending module!

Important

A member of the @Azure/avm-ptn-lz-subvending-module-owners-bicep or @Azure/avm-ptn-lz-subvending-module-contributors-bicep team will review it soon!

@sebassem
Copy link
Contributor

Please switch to the latest version where we have updated the network resource API which overcomes the problem of rebuilding the subnets.

@cspring86
Copy link
Author

Please switch to the latest version where we have updated the network resource API which overcomes the problem of rebuilding the subnets.

@sebassem I've upgraded to 0.1.4 and I'm still getting the error.

It's in the "lz-vend-vnet-create-[random]" deployment.

Screenshot from 2024-09-19 12-20-35

{"code":"DeploymentFailed","target":"/subscriptions/xxx/resourceGroups/rg-alz-landingzones-online/providers/Microsoft.Resources/deployments/lz-vend-vnet-create-c7vzwtpwxvg7e","message":"At least one resource deployment operation failed. Please list deployment operations for details. Please see https://aka.ms/arm-deployment-operations for usage details.","details":[{"code":"InUseSubnetCannotBeDeleted","message":"Subnet alz-spoke-t2awudh7kzl5o-eastus2-subnet-AKS is in use by /subscriptions/xxx/resourceGroups/MC_rg-alz-landingzones-online_xxx-akscluster_eastus2/providers/Microsoft.Network/networkInterfaces/|providers|Microsoft.Compute|virtualMachineScaleSets|aks-agentpool-xxx-vmss|virtualMachines|0|networkInterfaces|aks-agentpool-xxx-vmss/ipConfigurations/ipconfig1 and cannot be deleted. In order to delete the subnet, delete all the resources within the subnet. See aka.ms/deletesubnet.","details":[]}]}

@jtracey93
Copy link
Contributor

Hey @cspring86,

Could you share an example module declaration and the values you are setting for this deployment?

**Please redact any sensitive information 👍 **

Myself & @sebassem can then look further into this

#RR

@microsoft-github-policy-service microsoft-github-policy-service bot added the Needs: Author Feedback 👂 Awaiting feedback from the issue/PR author label Sep 19, 2024
@cspring86
Copy link
Author

cspring86 commented Sep 19, 2024

@jtracey93 sure, here you go.

module subVending 'br/public:avm/ptn/lz/sub-vending:0.1.4' = {
  name: 'subVending_${deploymentNameRandom}'
  params: {
    existingSubscriptionId: existingSubscriptionId
    subscriptionAliasEnabled: subscriptionAliasEnabled
    subscriptionAliasName: subscriptionName
    subscriptionDisplayName: subscriptionName
    subscriptionBillingScope: subscriptionBillingScope
    subscriptionWorkload: subscriptionWorkload
    subscriptionManagementGroupAssociationEnabled: true
    subscriptionManagementGroupId: 'alz-landingzones-online'
    subscriptionTags: {}
    resourceProviders: {
      'Microsoft.Advisor': []
      'Microsoft.AlertsManagement': []
      'Microsoft.Automation': []
      'Microsoft.Blueprint': []
      'Microsoft.Cache': []
      'Microsoft.Capacity': []
      'Microsoft.Compute': []
      'Microsoft.EventGrid': []
      'Microsoft.GuestConfiguration': []
      'Microsoft.Insights': []
      'Microsoft.KeyVault': []
      'Microsoft.ManagedIdentity': []
      'Microsoft.ManagedServices': []
      'Microsoft.Management': []
      'Microsoft.Network': []
      'Microsoft.OperationalInsights': []
      'Microsoft.OperationsManagement': []
      'Microsoft.PolicyInsights': []
      'Microsoft.RecoveryServices': []
      'Microsoft.ResourceHealth': []
      'Microsoft.Security': []
      'Microsoft.SecurityInsights': []
      'Microsoft.Sql': []
      'Microsoft.Storage': []
    }
    deploymentScriptLocation: location
    deploymentScriptManagedIdentityName: 'id-sv-ds-${subscriptionNameUnique}-${location}'
    deploymentScriptName: 'ds-sv-ds-${subscriptionNameUnique}'
    deploymentScriptNetworkSecurityGroupName: 'nsg-sv-ds-${subscriptionNameUnique}-${location}'
    deploymentScriptResourceGroupName: 'rg-sv-ds-${subscriptionNameUnique}-${location}'
    deploymentScriptStorageAccountName: 'stsvds${subscriptionNameUnique}${locationShortNameMap[location]}'
    deploymentScriptVirtualNetworkName: 'vnet-sv-ds-${subscriptionNameUnique}-${location}'
    roleAssignmentEnabled: true
    roleAssignments: [
      {
        definition: '/providers/Microsoft.Authorization/roleDefinitions/xxx'  // Reader BuiltInRole
        principalId: roleAssignmentPrincipalId  // Should be a group
        relativeScope: '/'
      }
    ]
    virtualNetworkAddressSpace: [
      virtualNetworkAddressSpace
    ]
    virtualNetworkEnabled: true
    virtualNetworkResourceGroupName: 'rg-alz-landingzones-online'
    virtualNetworkLocation: location
    virtualNetworkName: 'alz-spoke-${subscriptionNameUnique}-${location}'
    virtualNetworkPeeringEnabled: true
    hubNetworkResourceId: '/subscriptions/xxx/resourceGroups/rg-alz-connectivity/providers/Microsoft.Network/virtualNetworks/alz-hub-${location}'
    virtualNetworkResourceGroupLockEnabled: false
    virtualNetworkUseRemoteGateways: false
  }
}

Let me know if you need anything else.

@microsoft-github-policy-service microsoft-github-policy-service bot added Needs: Attention 👋 Reply has been added to issue, maintainer to review and removed Needs: Author Feedback 👂 Awaiting feedback from the issue/PR author labels Sep 19, 2024
@sebassem
Copy link
Contributor

@cspring86 Thanks Chris, we have identified the problem and a PR is on the way

@cspring86
Copy link
Author

@cspring86 Thanks Chris, we have identified the problem and a PR is on the way

Amazing, thanks @sebassem !

@cspring86
Copy link
Author

@sebassem Unrelated to this issue, but I've just tried to create a new subscription using 0.1.4 version (the upgrade you requested as part of this issue) of the sub-vending module and I'm getting an InternalServerError.

If I downgrade to 0.1.2 (my previous version), it works.

The error also happens in 0.1.3.

Is this a known issue or shall I raise another issue here?

@sebassem
Copy link
Contributor

@sebassem Unrelated to this issue, but I've just tried to create a new subscription using 0.1.4 version (the upgrade you requested as part of this issue) of the sub-vending module and I'm getting an InternalServerError.

If I downgrade to 0.1.2 (my previous version), it works.

The error also happens in 0.1.3.

Is this a known issue or shall I raise another issue here?

Hi @cspring86 , this is a current issue in Azure and on the way to be resolved. Once it's resolved I will submit the PR for this GitHub issue

@sebassem sebassem self-assigned this Sep 26, 2024
sebassem added a commit that referenced this issue Sep 30, 2024
## Description
Bump the LZ virtual network resource to avoid subnet deletion on PUT
requests
Fixes #3330 
<!--
>Thank you for your contribution !
> Please include a summary of the change and which issue is fixed.
> Please also include the context.
> List any dependencies that are required for this change.
-->

## Pipeline Reference

<!-- Insert your Pipeline Status Badge below -->

| Pipeline |
| -------- |
|
[![avm.ptn.lz.sub-vending](https://github.com/sebassem/bicep-registry-modules/actions/workflows/avm.ptn.lz.sub-vending.yml/badge.svg?branch=avm-ptn-sub-vending-network-api)](https://github.com/sebassem/bicep-registry-modules/actions/workflows/avm.ptn.lz.sub-vending.yml)
|

## Type of Change

<!-- Use the checkboxes [x] on the options that are relevant. -->

- [ ] Update to CI Environment or utilities (Non-module affecting
changes)
- [ ] Azure Verified Module updates:
- [X] Bugfix containing backwards-compatible bug fixes, and I have NOT
bumped the MAJOR or MINOR version in `version.json`:
- [X] Someone has opened a bug report issue, and I have included "Closes
#{bug_report_issue_number}" in the PR description.
- [ ] The bug was found by the module author, and no one has opened an
issue to report it yet.
- [ ] Feature update backwards compatible feature updates, and I have
bumped the MINOR version in `version.json`.
- [ ] Breaking changes and I have bumped the MAJOR version in
`version.json`.
  - [ ] Update to documentation

## Checklist

- [X] I'm sure there are no other open Pull Requests for the same
update/change
- [X] I have run `Set-AVMModule` locally to generate the supporting
module files.
- [X] My corresponding pipelines / checks run clean and green without
any errors or warnings

<!-- Please keep up to date with the contribution guide at
https://aka.ms/avm/contribute/bicep -->
@github-project-automation github-project-automation bot moved this from Needs: Triage to Done in AVM - Module Issues Sep 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Class: Pattern Module 📦 This is a pattern module Needs: Attention 👋 Reply has been added to issue, maintainer to review Needs: Triage 🔍 Maintainers need to triage still Type: AVM 🅰️ ✌️ Ⓜ️ This is an AVM related issue
Projects
Development

Successfully merging a pull request may close this issue.

3 participants