Azure Python needs different env var names to Terraform
import os
import functools
-from azure.identity import DefaultAzureCredential
+import logging
+from azure.identity import EnvironmentCredential
from azure.mgmt.containerservice import ContainerServiceClient
+logger = logging.getLogger("azure")
+logger.setLevel(logging.ERROR)
+
@functools.lru_cache()
def initiate_container_service_client():
subscription_id = os.environ.get("ARM_SUBSCRIPTION_ID", None)
+
+ # Python SDK needs different env var names to Terraform SDK
+ for envname in ("TENANT_ID", "CLIENT_SECRET", "CLIENT_ID"):
+ azure_name = f"AZURE_{envname}"
+ if azure_name not in os.environ:
+ os.environ[azure_name] = os.environ[f"ARM_{envname}"]
+
return ContainerServiceClient(
- credential=DefaultAzureCredential(), subscription_id=subscription_id
+ credential=EnvironmentCredential(), subscription_id=subscription_id
)
@@ -16,7 +27,6 @@ def initiate_container_service_client():
def kubernetes_versions(azure_location="Central US"):
client = initiate_container_service_client()
- azure_location = azure_location.replace(" ", "").lower()
k8s_versions_list = client.container_services.list_orchestrators(
azure_location, resource_type="managedClusters"
