Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -225,16 +225,15 @@ def set_up_infrastructure_resource_group(self):
self.managed_env_def["properties"]["InfrastructureResourceGroup"] = self.get_argument_infrastructure_resource_group()

def set_up_workload_profiles(self):
# If the environment exists, infer the environment type
existing_environment = None
try:
existing_environment = self.client.show(cmd=self.cmd,
resource_group_name=self.get_argument_resource_group_name(),
name=self.get_argument_name())
except Exception as e:
handle_non_404_status_code_exception(e)
if self.get_argument_enable_workload_profiles():
# If the environment exists, infer the environment type
existing_environment = None
try:
existing_environment = self.client.show(cmd=self.cmd,
resource_group_name=self.get_argument_resource_group_name(),
name=self.get_argument_name())
except Exception as e:
handle_non_404_status_code_exception(e)

if existing_environment and safe_get(existing_environment, "properties", "workloadProfiles") is None:
# check if input params include -w/--enable-workload-profiles
if self.cmd.cli_ctx.data.get('safe_params') and ('-w' in self.cmd.cli_ctx.data.get(
Expand All @@ -244,6 +243,10 @@ def set_up_workload_profiles(self):
return

self.managed_env_def["properties"]["workloadProfiles"] = get_default_workload_profiles(self.cmd, self.get_argument_location())
else:
if existing_environment and safe_get(existing_environment, "properties", "workloadProfiles") is not None:
raise ValidationError(
f"Existing environment {self.get_argument_name()} uses workload profiles. If you want to use Consumption-Only environment, please create a new one.")
Comment on lines +248 to +249
Copy link

Copilot AI Jan 15, 2026

Choose a reason for hiding this comment

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

The else block should only raise an error when the user explicitly specifies --enable-workload-profiles false, not when it's unspecified (None). Currently, if a user runs 'az containerapp env create -n test -g rg' without specifying --enable-workload-profiles, and an existing workload-profiles environment exists, they'll get an error about trying to create a Consumption-Only environment even though they didn't explicitly request one. Consider adding a check similar to line 239-242 that only raises the error when '--enable-workload-profiles' is in safe_params, and returning early otherwise to maintain idempotency.

Suggested change
raise ValidationError(
f"Existing environment {self.get_argument_name()} uses workload profiles. If you want to use Consumption-Only environment, please create a new one.")
# check if input params include -w/--enable-workload-profiles
if self.cmd.cli_ctx.data.get('safe_params') and ('-w' in self.cmd.cli_ctx.data.get(
'safe_params') or '--enable-workload-profiles' in self.cmd.cli_ctx.data.get('safe_params')):
raise ValidationError(
f"Existing environment {self.get_argument_name()} uses workload profiles. If you want to use Consumption-Only environment, please create a new one.")
return

Copilot uses AI. Check for mistakes.

def set_up_app_log_configuration(self):
if (self.get_argument_logs_customer_id() is None or self.get_argument_logs_key() is None) and self.get_argument_logs_destination() == "log-analytics":
Expand Down
Loading
Loading