diff --git a/src/azure-cli/azure/cli/command_modules/acs/managed_cluster_decorator.py b/src/azure-cli/azure/cli/command_modules/acs/managed_cluster_decorator.py index 6efebb3201c..e46511f1097 100644 --- a/src/azure-cli/azure/cli/command_modules/acs/managed_cluster_decorator.py +++ b/src/azure-cli/azure/cli/command_modules/acs/managed_cluster_decorator.py @@ -2366,13 +2366,21 @@ def get_sku_name(self) -> str: skuName = CONST_MANAGED_CLUSTER_SKU_NAME_BASE return skuName - @staticmethod - def _raise_missing_vnet_subnet_for_outbound_type(outbound_type: str, sku_name: str) -> None: + def _raise_missing_vnet_subnet_for_outbound_type(self, outbound_type: str, sku_name: str) -> None: if outbound_type == CONST_OUTBOUND_TYPE_USER_DEFINED_ROUTING: subnet_requirement = "a route table with egress rules" else: subnet_requirement = "a NAT gateway with outbound ips" + if self.decorator_mode == DecoratorMode.UPDATE: + raise InvalidArgumentValueError( + f"Updating outbound type to {outbound_type} is only supported for clusters created with " + "--vnet-subnet-id. Clusters using an AKS-managed VNet can't be updated to this outbound type. " + "Please refer to " + "https://learn.microsoft.com/en-us/azure/aks/egress-outboundtype#updating-outboundtype-after-cluster-creation " # pylint:disable=line-too-long + "for more details." + ) + if sku_name == CONST_MANAGED_CLUSTER_SKU_NAME_AUTOMATIC: raise RequiredArgumentMissingError( "--vnet-subnet-id must be specified for {outbound_type}. For an Automatic cluster " diff --git a/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_managed_cluster_decorator.py b/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_managed_cluster_decorator.py index be04d278208..ab6a217e15a 100644 --- a/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_managed_cluster_decorator.py +++ b/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_managed_cluster_decorator.py @@ -2020,6 +2020,24 @@ def test_get_outbound_type(self): ctx_1.attach_mc(mc) self.assertEqual(ctx_1.get_outbound_type(), "test_outbound_type") + ctx_1_1 = AKSManagedClusterContext( + self.cmd, + AKSManagedClusterParamDict( + { + "outbound_type": CONST_OUTBOUND_TYPE_USER_DEFINED_ROUTING, + } + ), + self.models, + DecoratorMode.UPDATE, + ) + ctx_1_1.agentpool_context = mock.MagicMock() + ctx_1_1.agentpool_context.get_vnet_subnet_id.return_value = None + with self.assertRaisesRegex( + InvalidArgumentValueError, + "only supported for clusters created with --vnet-subnet-id", + ): + ctx_1_1.get_outbound_type() + # invalid parameter ctx_2 = AKSManagedClusterContext( self.cmd,