| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
from __future__ import absolute_import, division, print_function |
| 8 |
|
| 9 |
__metaclass__ = type |
| 10 |
|
| 11 |
DOCUMENTATION = ''' |
| 12 |
--- |
| 13 |
module: azure_rm_aks |
| 14 |
version_added: "0.1.2" |
| 15 |
short_description: Manage a managed Azure Container Service (AKS) instance |
| 16 |
description: |
| 17 |
- Create, update and delete a managed Azure Container Service (AKS) instance. |
| 18 |
- You can only specify C(identity) or C(service_principal), not both. If you don't specify either it will |
| 19 |
default to identity->type->SystemAssigned. |
| 20 |
|
| 21 |
options: |
| 22 |
resource_group: |
| 23 |
description: |
| 24 |
- Name of a resource group where the managed Azure Container Services (AKS) exists or will be created. |
| 25 |
required: true |
| 26 |
type: str |
| 27 |
name: |
| 28 |
description: |
| 29 |
- Name of the managed Azure Container Services (AKS) instance. |
| 30 |
required: true |
| 31 |
type: str |
| 32 |
state: |
| 33 |
description: |
| 34 |
- Assert the state of the AKS. Use C(present) to create or update an AKS and C(absent) to delete it. |
| 35 |
default: present |
| 36 |
type: str |
| 37 |
choices: |
| 38 |
- absent |
| 39 |
- present |
| 40 |
location: |
| 41 |
description: |
| 42 |
- Valid azure location. Defaults to location of the resource group. |
| 43 |
type: str |
| 44 |
dns_prefix: |
| 45 |
description: |
| 46 |
- DNS prefix specified when creating the managed cluster. |
| 47 |
type: str |
| 48 |
kubernetes_version: |
| 49 |
description: |
| 50 |
- Version of Kubernetes specified when creating the managed cluster. |
| 51 |
type: str |
| 52 |
linux_profile: |
| 53 |
description: |
| 54 |
- The Linux profile suboptions. |
| 55 |
- Optional, provide if you need an ssh access to the cluster nodes. |
| 56 |
type: dict |
| 57 |
suboptions: |
| 58 |
admin_username: |
| 59 |
description: |
| 60 |
- The Admin Username for the cluster. |
| 61 |
required: true |
| 62 |
type: str |
| 63 |
ssh_key: |
| 64 |
description: |
| 65 |
- The Public SSH Key used to access the cluster. |
| 66 |
required: true |
| 67 |
type: str |
| 68 |
agent_pool_profiles: |
| 69 |
description: |
| 70 |
- The agent pool profile suboptions. |
| 71 |
type: list |
| 72 |
elements: dict |
| 73 |
suboptions: |
| 74 |
name: |
| 75 |
description: |
| 76 |
- Unique name of the agent pool profile in the context of the subscription and resource group. |
| 77 |
required: true |
| 78 |
type: str |
| 79 |
count: |
| 80 |
description: |
| 81 |
- Number of agents (VMs) to host docker containers. |
| 82 |
- Allowed values must be in the range of C(1) to C(100) (inclusive). |
| 83 |
required: true |
| 84 |
type: int |
| 85 |
vm_size: |
| 86 |
description: |
| 87 |
- The VM Size of each of the Agent Pool VM's (e.g. C(Standard_F1) / C(Standard_D2v2)). |
| 88 |
required: true |
| 89 |
type: str |
| 90 |
os_disk_size_gb: |
| 91 |
description: |
| 92 |
- Size of the OS disk. |
| 93 |
type: int |
| 94 |
enable_auto_scaling: |
| 95 |
description: |
| 96 |
- To enable auto-scaling. |
| 97 |
type: bool |
| 98 |
max_count: |
| 99 |
description: |
| 100 |
- Maximum number of nodes for auto-scaling. |
| 101 |
- Required if I(enable_auto_scaling=True). |
| 102 |
type: int |
| 103 |
min_count: |
| 104 |
description: |
| 105 |
- Minmum number of nodes for auto-scaling. |
| 106 |
- Required if I(enable_auto_scaling=True). |
| 107 |
type: int |
| 108 |
max_pods: |
| 109 |
description: |
| 110 |
- Maximum number of pods schedulable on nodes. |
| 111 |
type: int |
| 112 |
type: |
| 113 |
description: |
| 114 |
- AgentPoolType represents types of an agent pool. |
| 115 |
- Possible values include C(VirtualMachineScaleSets) and C(AvailabilitySet). |
| 116 |
choices: |
| 117 |
- 'VirtualMachineScaleSets' |
| 118 |
- 'AvailabilitySet' |
| 119 |
type: str |
| 120 |
mode: |
| 121 |
description: |
| 122 |
- AgentPoolMode represents mode of an agent pool. |
| 123 |
- Possible values include C(System) and C(User). |
| 124 |
- System AgentPoolMode requires a minimum VM SKU of at least 2 vCPUs and 4GB memory. |
| 125 |
choices: |
| 126 |
- 'System' |
| 127 |
- 'User' |
| 128 |
type: str |
| 129 |
orchestrator_version: |
| 130 |
description: |
| 131 |
- Version of kubernetes running on the node pool. |
| 132 |
type: str |
| 133 |
node_labels: |
| 134 |
description: |
| 135 |
- Agent pool node labels to be persisted across all nodes in agent pool. |
| 136 |
type: dict |
| 137 |
vnet_subnet_id: |
| 138 |
description: |
| 139 |
- Specifies the VNet's subnet identifier. |
| 140 |
type: str |
| 141 |
availability_zones: |
| 142 |
description: |
| 143 |
- Availability zones for nodes. Must use VirtualMachineScaleSets AgentPoolType. |
| 144 |
type: list |
| 145 |
elements: int |
| 146 |
choices: |
| 147 |
- 1 |
| 148 |
- 2 |
| 149 |
- 3 |
| 150 |
os_type: |
| 151 |
description: |
| 152 |
- The operating system type. |
| 153 |
type: str |
| 154 |
choices: |
| 155 |
- Linux |
| 156 |
- Windows |
| 157 |
- linux |
| 158 |
- windows |
| 159 |
storage_profiles: |
| 160 |
description: |
| 161 |
- Storage profile specifies what kind of storage used. |
| 162 |
type: str |
| 163 |
choices: |
| 164 |
- StorageAccount |
| 165 |
- ManagedDisks |
| 166 |
ports: |
| 167 |
description: |
| 168 |
- List of the agent pool's port. |
| 169 |
type: list |
| 170 |
elements: int |
| 171 |
dns_prefix: |
| 172 |
description: |
| 173 |
- DNS prefix specified when creating the managed cluster. |
| 174 |
type: str |
| 175 |
tags: |
| 176 |
description: |
| 177 |
- The tags to be persisted on the agent pool virtual machine scale set. |
| 178 |
type: dict |
| 179 |
os_sku: |
| 180 |
description: |
| 181 |
- The operating system sku. |
| 182 |
type: str |
| 183 |
choices: |
| 184 |
- Ubuntu |
| 185 |
- AzureLinux |
| 186 |
- Windows2019 |
| 187 |
- Windows2022 |
| 188 |
security_profile: |
| 189 |
description: |
| 190 |
- The security settings of an agent pool. |
| 191 |
type: dict |
| 192 |
suboptions: |
| 193 |
enable_vtpm: |
| 194 |
description: |
| 195 |
- Whether to disable or enabled the vTPM. |
| 196 |
type: bool |
| 197 |
default: false |
| 198 |
enable_secure_boot: |
| 199 |
description: |
| 200 |
- Whether to disable or enabled the secure boot. |
| 201 |
default: false |
| 202 |
type: bool |
| 203 |
scale_set_priority: |
| 204 |
description: |
| 205 |
- Virtual Vachine Scale Set priority for the agent pool. |
| 206 |
- C(Regular) uses standard on-demand VMs. |
| 207 |
- C(Spot) uses Azure Spot VMs which can be evicted at any time. |
| 208 |
- This property is immutable after the agent pool is created. |
| 209 |
type: str |
| 210 |
choices: |
| 211 |
- Regular |
| 212 |
- Spot |
| 213 |
scale_set_eviction_policy: |
| 214 |
description: |
| 215 |
- Eviction policy for Spot VM agent pools. |
| 216 |
- Only applicable when I(scale_set_priority=Spot). |
| 217 |
- C(Delete) removes the VM and its disk on eviction. |
| 218 |
- C(Deallocate) deallocates the VM, but retains the disk on eviction. |
| 219 |
- This property is immutable after the agent pool is created. |
| 220 |
type: str |
| 221 |
choices: |
| 222 |
- Delete |
| 223 |
- Deallocate |
| 224 |
spot_max_price: |
| 225 |
description: |
| 226 |
- The maximum price (in USD per hour) for Spot VMs in the agent pool. |
| 227 |
- Use C(-1) to indicate the on-demand price. |
| 228 |
- Only applicable when I(scale_set_priority=Spot). |
| 229 |
- This property is immutable after the agent pool is created. |
| 230 |
type: float |
| 231 |
security_profile: |
| 232 |
description: |
| 233 |
- Security profile for the container service cluster. |
| 234 |
type: dict |
| 235 |
suboptions: |
| 236 |
workload_identity: |
| 237 |
description: |
| 238 |
- Workload identity settings for the security profile. |
| 239 |
- Workload identity enables Kubernetes applications to access Azure cloud resources securely with Azure AD. |
| 240 |
- See U(https://aka.ms/aks/wi) for more details. |
| 241 |
type: dict |
| 242 |
suboptions: |
| 243 |
enabled: |
| 244 |
description: |
| 245 |
- Whether to enable workload identity. |
| 246 |
type: bool |
| 247 |
image_cleaner: |
| 248 |
description: |
| 249 |
- Image Cleaner settings for the security profile. |
| 250 |
type: dict |
| 251 |
suboptions: |
| 252 |
enabled: |
| 253 |
description: |
| 254 |
- Whether to enable Image Cleaner on AKS cluster. |
| 255 |
type: bool |
| 256 |
interval_hours: |
| 257 |
description: |
| 258 |
- Image Cleaner scanning interval in hours. |
| 259 |
type: int |
| 260 |
defender: |
| 261 |
description: |
| 262 |
- Microsoft Defender settings for the security profile. |
| 263 |
type: dict |
| 264 |
suboptions: |
| 265 |
log_analytics_workspace_resource_id: |
| 266 |
description: |
| 267 |
- Resource ID of the Log Analytics workspace to be associated with Microsoft Defender. |
| 268 |
- When Microsoft Defender is enabled, this field is required and must be a valid workspace resource ID. |
| 269 |
- When Microsoft Defender is disabled, leave the field empty. |
| 270 |
type: str |
| 271 |
security_monitoring: |
| 272 |
description: |
| 273 |
- Microsoft Defender threat detection for Cloud settings for the security profile. |
| 274 |
type: dict |
| 275 |
suboptions: |
| 276 |
enabled: |
| 277 |
description: |
| 278 |
- Whether to enable Defender threat detection. |
| 279 |
type: bool |
| 280 |
azure_key_vault_kms: |
| 281 |
description: |
| 282 |
- Azure Key Vault. |
| 283 |
- See U(https://kubernetes.io/docs/tasks/administer-cluster/kms-provider/) settings for the security profile. |
| 284 |
type: dict |
| 285 |
suboptions: |
| 286 |
enabled: |
| 287 |
description: |
| 288 |
- Whether to enable Azure Key Vault key management service. The default is C(false). |
| 289 |
type: bool |
| 290 |
default: false |
| 291 |
key_id: |
| 292 |
description: |
| 293 |
- Identifier of Azure Key Vault key. |
| 294 |
type: str |
| 295 |
key_vault_network_access: |
| 296 |
description: |
| 297 |
- Network access of key vault. |
| 298 |
type: str |
| 299 |
choices: |
| 300 |
- Public |
| 301 |
- Private |
| 302 |
default: Public |
| 303 |
key_vault_resource_id: |
| 304 |
description: |
| 305 |
- Resource ID of key vault. |
| 306 |
- When I(key_vault_network_access=Private), this field is required and must be a valid resource ID. |
| 307 |
- When I(key_vault_network_access=Public), leave the field empty. |
| 308 |
type: str |
| 309 |
service_principal: |
| 310 |
description: |
| 311 |
- The service principal suboptions. |
| 312 |
type: dict |
| 313 |
suboptions: |
| 314 |
client_id: |
| 315 |
description: |
| 316 |
- The ID for the Service Principal. |
| 317 |
type: str |
| 318 |
required: true |
| 319 |
client_secret: |
| 320 |
description: |
| 321 |
- The secret password associated with the service principal. |
| 322 |
type: str |
| 323 |
identity: |
| 324 |
description: |
| 325 |
- Identity for the Server. |
| 326 |
type: dict |
| 327 |
version_added: '2.4.0' |
| 328 |
suboptions: |
| 329 |
type: |
| 330 |
description: |
| 331 |
- Type of the managed identity |
| 332 |
required: false |
| 333 |
choices: |
| 334 |
- UserAssigned |
| 335 |
- SystemAssigned |
| 336 |
default: SystemAssigned |
| 337 |
type: str |
| 338 |
user_assigned_identities: |
| 339 |
description: |
| 340 |
- User Assigned Managed Identity |
| 341 |
type: str |
| 342 |
enable_rbac: |
| 343 |
description: |
| 344 |
- Enable RBAC. |
| 345 |
- Existing non-RBAC enabled AKS clusters cannot currently be updated for RBAC use. |
| 346 |
type: bool |
| 347 |
default: no |
| 348 |
network_profile: |
| 349 |
description: |
| 350 |
- Profile of network configuration. |
| 351 |
type: dict |
| 352 |
suboptions: |
| 353 |
network_plugin: |
| 354 |
description: |
| 355 |
- Network plugin used for building Kubernetes network. |
| 356 |
- This property cannot been changed. |
| 357 |
- With C(kubenet), nodes get an IP address from the Azure virtual network subnet. |
| 358 |
- AKS features such as Virtual Nodes or network policies aren't supported with C(kubenet). |
| 359 |
- C(azure) enables Azure Container Networking Interface(CNI), every pod gets an IP address from the subnet and can be accessed directly. |
| 360 |
- use BYO CNI for custom networking solutions. |
| 361 |
type: str |
| 362 |
choices: |
| 363 |
- azure |
| 364 |
- kubenet |
| 365 |
- none |
| 366 |
network_plugin_mode: |
| 367 |
description: |
| 368 |
- Network plugin mode used for building the Kubernetes network. |
| 369 |
type: str |
| 370 |
choices: |
| 371 |
- Overlay |
| 372 |
network_policy: |
| 373 |
description: Network policy used for building Kubernetes network. |
| 374 |
type: str |
| 375 |
choices: |
| 376 |
- azure |
| 377 |
- calico |
| 378 |
pod_cidr: |
| 379 |
description: |
| 380 |
- A CIDR notation IP range from which to assign pod IPs when I(network_plugin=kubenet) is used. |
| 381 |
- It should be a large address space that isn't in use elsewhere in your network environment. |
| 382 |
- This address range must be large enough to accommodate the number of nodes that you expect to scale up to. |
| 383 |
type: str |
| 384 |
service_cidr: |
| 385 |
description: |
| 386 |
- A CIDR notation IP range from which to assign service cluster IPs. |
| 387 |
- It must not overlap with any Subnet IP ranges. |
| 388 |
- It should be the *.10 address of your service IP address range. |
| 389 |
type: str |
| 390 |
dns_service_ip: |
| 391 |
description: |
| 392 |
- An IP address assigned to the Kubernetes DNS service. |
| 393 |
- It must be within the Kubernetes service address range specified in serviceCidr. |
| 394 |
type: str |
| 395 |
load_balancer_sku: |
| 396 |
description: |
| 397 |
- The load balancer sku for the managed cluster. |
| 398 |
type: str |
| 399 |
choices: |
| 400 |
- standard |
| 401 |
- basic |
| 402 |
outbound_type: |
| 403 |
description: |
| 404 |
- How outbound traffic will be configured for a cluster. |
| 405 |
type: str |
| 406 |
default: loadBalancer |
| 407 |
choices: |
| 408 |
- loadBalancer |
| 409 |
- userDefinedRouting |
| 410 |
- managedNATGateway |
| 411 |
- userAssignedNATGateway |
| 412 |
api_server_access_profile: |
| 413 |
description: |
| 414 |
- Profile of API Access configuration. |
| 415 |
type: dict |
| 416 |
suboptions: |
| 417 |
authorized_ip_ranges: |
| 418 |
description: |
| 419 |
- Authorized IP Ranges to kubernetes API server. |
| 420 |
- Cannot be enabled when using private cluster |
| 421 |
type: list |
| 422 |
elements: str |
| 423 |
enable_private_cluster: |
| 424 |
description: |
| 425 |
- Whether to create the cluster as a private cluster or not. |
| 426 |
- Cannot be changed for an existing cluster. |
| 427 |
type: bool |
| 428 |
aad_profile: |
| 429 |
description: |
| 430 |
- Profile of Azure Active Directory configuration. |
| 431 |
type: dict |
| 432 |
suboptions: |
| 433 |
client_app_id: |
| 434 |
description: The client AAD application ID. |
| 435 |
type: str |
| 436 |
server_app_id: |
| 437 |
description: The server AAD application ID. |
| 438 |
type: str |
| 439 |
server_app_secret: |
| 440 |
description: The server AAD application secret. |
| 441 |
type: str |
| 442 |
tenant_id: |
| 443 |
description: |
| 444 |
- The AAD tenant ID to use for authentication. |
| 445 |
- If not specified, will use the tenant of the deployment subscription. |
| 446 |
type: str |
| 447 |
managed: |
| 448 |
description: |
| 449 |
- Whether to enable managed AAD. |
| 450 |
type: bool |
| 451 |
default: false |
| 452 |
enable_azure_rbac: |
| 453 |
description: |
| 454 |
- Whether to enable Azure RBAC for Kubernetes authorization. |
| 455 |
type: bool |
| 456 |
default: false |
| 457 |
admin_group_object_ids: |
| 458 |
description: |
| 459 |
- AAD group object IDs that will have admin role of the cluster. |
| 460 |
type: list |
| 461 |
elements: str |
| 462 |
addon: |
| 463 |
description: |
| 464 |
- Profile of managed cluster add-on. |
| 465 |
- Key can be C(http_application_routing), C(monitoring), C(virtual_node) and C(azure_keyvault_secrets_provider). |
| 466 |
- Value must be a dict contains a bool variable C(enabled). |
| 467 |
type: dict |
| 468 |
suboptions: |
| 469 |
http_application_routing: |
| 470 |
description: |
| 471 |
- The HTTP application routing solution makes it easy to access applications that are deployed to your cluster. |
| 472 |
type: dict |
| 473 |
aliases: |
| 474 |
- httpApplicationRouting |
| 475 |
suboptions: |
| 476 |
enabled: |
| 477 |
description: |
| 478 |
- Whether the solution enabled. |
| 479 |
type: bool |
| 480 |
default: true |
| 481 |
azure_keyvault_secrets_provider: |
| 482 |
description: |
| 483 |
- Whether to enable the Azure Key Vault provider in an AKS cluster. |
| 484 |
type: dict |
| 485 |
version_added: "3.7.0" |
| 486 |
aliases: |
| 487 |
- azureKeyvaultSecretsProvider |
| 488 |
suboptions: |
| 489 |
enabled: |
| 490 |
description: |
| 491 |
- Enabled or disabled the Azure Key Vault provider in the AKS cluster. |
| 492 |
type: bool |
| 493 |
default: true |
| 494 |
monitoring: |
| 495 |
description: |
| 496 |
- It gives you performance visibility by collecting memory and processor metrics from controllers, nodes, |
| 497 |
and containers that are available in Kubernetes through the Metrics API. |
| 498 |
type: dict |
| 499 |
aliases: |
| 500 |
- omsagent |
| 501 |
suboptions: |
| 502 |
enabled: |
| 503 |
description: |
| 504 |
- Whether the solution enabled. |
| 505 |
type: bool |
| 506 |
default: true |
| 507 |
log_analytics_workspace_resource_id: |
| 508 |
description: |
| 509 |
- Where to store the container metrics. |
| 510 |
type: str |
| 511 |
required: true |
| 512 |
aliases: |
| 513 |
- logAnalyticsWorkspaceResourceID |
| 514 |
virtual_node: |
| 515 |
description: |
| 516 |
- With virtual nodes, you have quick provisioning of pods, and only pay per second for their execution time. |
| 517 |
- You don't need to wait for Kubernetes cluster autoscaler to deploy VM compute nodes to run the additional pods. |
| 518 |
type: dict |
| 519 |
aliases: |
| 520 |
- aciConnector |
| 521 |
suboptions: |
| 522 |
enabled: |
| 523 |
description: |
| 524 |
- Whether the solution enabled. |
| 525 |
type: bool |
| 526 |
default: true |
| 527 |
subnet_resource_id: |
| 528 |
description: |
| 529 |
- Subnet associated to the cluster. |
| 530 |
type: str |
| 531 |
required: true |
| 532 |
aliases: |
| 533 |
- SubnetName |
| 534 |
node_resource_group: |
| 535 |
description: |
| 536 |
- Name of the resource group containing agent pool nodes. |
| 537 |
- Unable to update. |
| 538 |
type: str |
| 539 |
pod_identity_profile: |
| 540 |
description: |
| 541 |
- Config pod identities in managed Kubernetes cluster. |
| 542 |
type: dict |
| 543 |
suboptions: |
| 544 |
enabled: |
| 545 |
description: |
| 546 |
- Whether the pod identity addon is enabled. |
| 547 |
type: bool |
| 548 |
allow_network_plugin_kubenet: |
| 549 |
description: |
| 550 |
- Whether using Kubenet network plugin with AAD Pod Identity. |
| 551 |
type: bool |
| 552 |
user_assigned_identities: |
| 553 |
description: |
| 554 |
- The pod identities to use in the cluster. |
| 555 |
type: list |
| 556 |
elements: dict |
| 557 |
suboptions: |
| 558 |
name: |
| 559 |
description: |
| 560 |
- The name of the pod identity. |
| 561 |
type: str |
| 562 |
required: true |
| 563 |
namespace: |
| 564 |
description: |
| 565 |
- The namespace of the pod identity. |
| 566 |
type: str |
| 567 |
required: true |
| 568 |
binding_selector: |
| 569 |
description: |
| 570 |
- The binding selector to use for the AzureIdentityBinding resource. |
| 571 |
type: str |
| 572 |
identity: |
| 573 |
description: |
| 574 |
- The user assigned identity details. |
| 575 |
type: dict |
| 576 |
required: true |
| 577 |
suboptions: |
| 578 |
resource_id: |
| 579 |
description: |
| 580 |
- The resource ID of the user assigned identity. |
| 581 |
type: str |
| 582 |
object_id: |
| 583 |
description: |
| 584 |
- The object ID of the user assigned identity. |
| 585 |
type: str |
| 586 |
client_id: |
| 587 |
description: |
| 588 |
- The client ID of the user assigned identity. |
| 589 |
type: str |
| 590 |
windows_profile: |
| 591 |
description: |
| 592 |
- The Windows profile suboptions. |
| 593 |
type: dict |
| 594 |
suboptions: |
| 595 |
admin_username: |
| 596 |
description: |
| 597 |
- The Admin Username for the cluster. |
| 598 |
required: true |
| 599 |
type: str |
| 600 |
admin_password: |
| 601 |
description: |
| 602 |
- The Admin password for the cluster. |
| 603 |
required: true |
| 604 |
type: str |
| 605 |
gmsa_profile: |
| 606 |
description: |
| 607 |
- Windows Group Managed Service Accounts (gMSA). |
| 608 |
type: dict |
| 609 |
suboptions: |
| 610 |
enabled: |
| 611 |
description: |
| 612 |
- Whether to enable gMSA in the cluster. |
| 613 |
type: bool |
| 614 |
default: false |
| 615 |
dns_server: |
| 616 |
description: |
| 617 |
- Specifies the DNS server for Windows gMSA. Optional if you have |
| 618 |
configured the DNS server in the vnet which is used to create |
| 619 |
the managed cluster. |
| 620 |
required: false |
| 621 |
type: str |
| 622 |
root_domain_name: |
| 623 |
description: |
| 624 |
- Specifies the root domain name for Windows gMSA. Optional if you have |
| 625 |
configured the DNS server in the vnet which is used to create |
| 626 |
the managed cluster. |
| 627 |
required: false |
| 628 |
type: str |
| 629 |
disable_local_accounts: |
| 630 |
description: |
| 631 |
- If set to true, getting static credentials will be disabled for this cluster. |
| 632 |
- This must only be used on Managed Clusters that are AAD enabled. |
| 633 |
type: bool |
| 634 |
auto_upgrade_profile: |
| 635 |
description: |
| 636 |
- Auto upgrade profile for a managed cluster. |
| 637 |
type: dict |
| 638 |
suboptions: |
| 639 |
upgrade_channel: |
| 640 |
description: |
| 641 |
- Setting the AKS cluster auto-upgrade channel. |
| 642 |
type: str |
| 643 |
default: node-image |
| 644 |
choices: |
| 645 |
- rapid |
| 646 |
- stable |
| 647 |
- patch |
| 648 |
- node-image |
| 649 |
- none |
| 650 |
node_os_upgrade_channel: |
| 651 |
description: |
| 652 |
- Manner in which the OS on your nodes is updated. |
| 653 |
type: str |
| 654 |
default: NodeImage |
| 655 |
choices: |
| 656 |
- None |
| 657 |
- Unmanaged |
| 658 |
- SecurityPatch |
| 659 |
- NodeImage |
| 660 |
extends_documentation_fragment: |
| 661 |
- azure.azcollection.azure |
| 662 |
- azure.azcollection.azure_tags |
| 663 |
|
| 664 |
author: |
| 665 |
- Sertac Ozercan (@sozercan) |
| 666 |
- Yuwei Zhou (@yuwzho) |
| 667 |
|
| 668 |
''' |
| 669 |
|
| 670 |
EXAMPLES = ''' |
| 671 |
- name: Create an AKS instance With A System Node Pool & A User Node Pool |
| 672 |
azure_rm_aks: |
| 673 |
name: myAKS |
| 674 |
resource_group: myResourceGroup |
| 675 |
location: eastus |
| 676 |
dns_prefix: akstest |
| 677 |
kubernetes_version: 1.14.6 |
| 678 |
linux_profile: |
| 679 |
admin_username: azureuser |
| 680 |
ssh_key: ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAA... |
| 681 |
service_principal: |
| 682 |
client_id: "cf72ca99-f6b9-4004-b0e0-bee10c521948" |
| 683 |
client_secret: "Password1234!" |
| 684 |
agent_pool_profiles: |
| 685 |
- name: default |
| 686 |
count: 1 |
| 687 |
vm_size: Standard_B2s |
| 688 |
enable_auto_scaling: true |
| 689 |
type: VirtualMachineScaleSets |
| 690 |
mode: System |
| 691 |
max_count: 3 |
| 692 |
min_count: 1 |
| 693 |
enable_rbac: true |
| 694 |
tags: |
| 695 |
key1: value1 |
| 696 |
- name: user |
| 697 |
count: 1 |
| 698 |
vm_size: Standard_D2_v2 |
| 699 |
enable_auto_scaling: true |
| 700 |
type: VirtualMachineScaleSets |
| 701 |
mode: User |
| 702 |
max_count: 3 |
| 703 |
min_count: 1 |
| 704 |
enable_rbac: true |
| 705 |
|
| 706 |
- name: Create a managed Azure Container Services (AKS) instance |
| 707 |
azure_rm_aks: |
| 708 |
name: myAKS |
| 709 |
location: eastus |
| 710 |
resource_group: myResourceGroup |
| 711 |
dns_prefix: akstest |
| 712 |
kubernetes_version: 1.14.6 |
| 713 |
linux_profile: |
| 714 |
admin_username: azureuser |
| 715 |
ssh_key: ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAA... |
| 716 |
service_principal: |
| 717 |
client_id: "cf72ca99-f6b9-4004-b0e0-bee10c521948" |
| 718 |
client_secret: "Password123!" |
| 719 |
agent_pool_profiles: |
| 720 |
- name: default |
| 721 |
count: 5 |
| 722 |
mode: System |
| 723 |
vm_size: Standard_B2s |
| 724 |
tags: |
| 725 |
Environment: Production |
| 726 |
|
| 727 |
- name: Use minimal parameters and system-assigned identity |
| 728 |
azure_rm_aks: |
| 729 |
name: myMinimalCluster |
| 730 |
location: eastus |
| 731 |
resource_group: myExistingResourceGroup |
| 732 |
dns_prefix: akstest |
| 733 |
agent_pool_profiles: |
| 734 |
- name: default |
| 735 |
count: 1 |
| 736 |
vm_size: Standard_D2_v2 |
| 737 |
|
| 738 |
- name: Create AKS with userDefinedRouting "Link:https://docs.microsoft.com/en-us/azure/aks/limit-egress-traffic#add-a-dnat-rule-to-azure-firewall" |
| 739 |
azure_rm_aks: |
| 740 |
name: "minimal{{ rpfx }}" |
| 741 |
location: eastus |
| 742 |
resource_group: "{{ resource_group }}" |
| 743 |
kubernetes_version: "{{ versions.azure_aks_versions[0] }}" |
| 744 |
dns_prefix: "aks{{ rpfx }}" |
| 745 |
service_principal: |
| 746 |
client_id: "{{ client_id }}" |
| 747 |
client_secret: "{{ client_secret }}" |
| 748 |
network_profile: |
| 749 |
network_plugin: azure |
| 750 |
load_balancer_sku: standard |
| 751 |
outbound_type: userDefinedRouting |
| 752 |
service_cidr: "10.41.0.0/16" |
| 753 |
dns_service_ip: "10.41.0.10" |
| 754 |
api_server_access_profile: |
| 755 |
authorized_ip_ranges: |
| 756 |
- "20.106.246.252/32" |
| 757 |
enable_private_cluster: false |
| 758 |
agent_pool_profiles: |
| 759 |
- name: default |
| 760 |
count: 1 |
| 761 |
vm_size: Standard_B2s |
| 762 |
mode: System |
| 763 |
vnet_subnet_id: "{{ output.subnets[0].id }}" |
| 764 |
type: VirtualMachineScaleSets |
| 765 |
enable_auto_scaling: false |
| 766 |
|
| 767 |
- name: Create an AKS instance wit pod_identity_profile settings |
| 768 |
azure_rm_aks: |
| 769 |
name: "aks{{ rpfx }}" |
| 770 |
resource_group: "{{ resource_group }}" |
| 771 |
location: eastus |
| 772 |
dns_prefix: "aks{{ rpfx }}" |
| 773 |
kubernetes_version: "{{ versions.azure_aks_versions[0] }}" |
| 774 |
service_principal: |
| 775 |
client_id: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx |
| 776 |
client_secret: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx |
| 777 |
linux_profile: |
| 778 |
admin_username: azureuser |
| 779 |
ssh_key: ssh-rsa AAAAB3Ip6*************** |
| 780 |
agent_pool_profiles: |
| 781 |
- name: default |
| 782 |
count: 1 |
| 783 |
vm_size: Standard_B2s |
| 784 |
type: VirtualMachineScaleSets |
| 785 |
mode: System |
| 786 |
node_labels: {"release":"stable"} |
| 787 |
max_pods: 42 |
| 788 |
availability_zones: |
| 789 |
- 1 |
| 790 |
- 2 |
| 791 |
node_resource_group: "node{{ noderpfx }}" |
| 792 |
enable_rbac: true |
| 793 |
network_profile: |
| 794 |
load_balancer_sku: standard |
| 795 |
pod_identity_profile: |
| 796 |
enabled: false |
| 797 |
allow_network_plugin_kubenet: false |
| 798 |
user_assigned_identities: |
| 799 |
- name: fredtest |
| 800 |
namespace: fredtest |
| 801 |
binding_selector: test |
| 802 |
identity: |
| 803 |
client_id: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx |
| 804 |
object_id: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx |
| 805 |
|
| 806 |
- name: Create a kubernet service with I(os_type=Windows) |
| 807 |
azure_rm_aks: |
| 808 |
name: myaks02 |
| 809 |
location: eastus |
| 810 |
resource_group: "{{ resource_group }}" |
| 811 |
kubernetes_version: "{{ versions }}" |
| 812 |
dns_prefix: "aks_dns" |
| 813 |
enable_rbac: true |
| 814 |
windows_profile: |
| 815 |
admin_username: azureuser |
| 816 |
admin_password: Password@0329 |
| 817 |
gmsa_profile: |
| 818 |
enabled: true |
| 819 |
aad_profile: |
| 820 |
managed: true |
| 821 |
agent_pool_profiles: |
| 822 |
- name: default |
| 823 |
count: 1 |
| 824 |
vm_size: Standard_D8ds_v5 |
| 825 |
mode: System |
| 826 |
os_type: Linux |
| 827 |
os_sku: Ubuntu |
| 828 |
- name: def |
| 829 |
count: 1 |
| 830 |
vm_size: Standard_D2as_v4 |
| 831 |
mode: User |
| 832 |
os_type: Windows |
| 833 |
os_sku: Windows2022 |
| 834 |
api_server_access_profile: |
| 835 |
authorized_ip_ranges: |
| 836 |
- "192.0.2.0" |
| 837 |
- "198.51.100.0" |
| 838 |
- "203.0.113.0" |
| 839 |
enable_private_cluster: false |
| 840 |
network_profile: |
| 841 |
load_balancer_sku: standard |
| 842 |
network_plugin: azure |
| 843 |
outbound_type: loadBalancer |
| 844 |
|
| 845 |
- name: Create an AKS instance with a Spot user node pool |
| 846 |
azure_rm_aks: |
| 847 |
name: myAKSWithSpot |
| 848 |
resource_group: myResourceGroup |
| 849 |
location: eastus |
| 850 |
dns_prefix: aksspot |
| 851 |
kubernetes_version: 1.28.5 |
| 852 |
linux_profile: |
| 853 |
admin_username: azureuser |
| 854 |
ssh_key: ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAA... |
| 855 |
service_principal: |
| 856 |
client_id: "cf72ca99-f6b9-4004-b0e0-bee10c521948" |
| 857 |
client_secret: "Password1234!" |
| 858 |
enable_rbac: true |
| 859 |
agent_pool_profiles: |
| 860 |
- name: systempool |
| 861 |
count: 1 |
| 862 |
vm_size: Standard_B2s |
| 863 |
mode: System |
| 864 |
- name: spotpool |
| 865 |
count: 2 |
| 866 |
vm_size: Standard_D2_v2 |
| 867 |
mode: User |
| 868 |
scale_set_priority: Spot |
| 869 |
scale_set_eviction_policy: Deallocate |
| 870 |
spot_max_price: -1 |
| 871 |
enable_auto_scaling: true |
| 872 |
min_count: 1 |
| 873 |
max_count: 5 |
| 874 |
|
| 875 |
- name: Remove a managed Azure Container Services (AKS) instance |
| 876 |
azure_rm_aks: |
| 877 |
name: myAKS |
| 878 |
resource_group: myResourceGroup |
| 879 |
state: absent |
| 880 |
''' |
| 881 |
|
| 882 |
RETURN = ''' |
| 883 |
state: |
| 884 |
description: Current state of the Azure Container Service (AKS). |
| 885 |
returned: always |
| 886 |
type: dict |
| 887 |
example: |
| 888 |
addon: |
| 889 |
azure_keyvault_secrets_provider: { "enabled": true } |
| 890 |
http_application_routing: { "enabled": false } |
| 891 |
monitoring: null |
| 892 |
virtual_node: null |
| 893 |
agent_pool_profiles: |
| 894 |
- count: 1 |
| 895 |
dns_prefix: Null |
| 896 |
name: default |
| 897 |
os_disk_size_gb: Null |
| 898 |
os_type: Linux |
| 899 |
moode: System |
| 900 |
node_labels: { "environment": "dev", "release": "stable" } |
| 901 |
ports: Null |
| 902 |
storage_profile: ManagedDisks |
| 903 |
vm_size: Standard_B2s |
| 904 |
vnet_subnet_id: Null |
| 905 |
os_sku: Ubuntu |
| 906 |
security_profile: { 'enable_secure_boot': true, 'enable_vtpm': false } |
| 907 |
auto_upgrade_profile: |
| 908 |
node_os_upgrade_channel: NodeImage |
| 909 |
upgrade_channel: patch |
| 910 |
changed: false |
| 911 |
dns_prefix: aks9860bdcd89 |
| 912 |
disable_local_accounts: true |
| 913 |
id: "/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourcegroups/myResourceGroup/providers/Microsoft.ContainerService/managedClusters/aks9860bdc" |
| 914 |
kube_config: ["......"] |
| 915 |
kubernetes_version: 1.14.6 |
| 916 |
linux_profile: |
| 917 |
admin_username: azureuser |
| 918 |
ssh_key: ssh-rsa AAAAB3NzaC1yc2EAAAADA..... |
| 919 |
location: eastus |
| 920 |
name: aks9860bdc |
| 921 |
provisioning_state: Succeeded |
| 922 |
service_principal_profile: |
| 923 |
client_id: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx |
| 924 |
identity: |
| 925 |
"type": "UserAssigned" |
| 926 |
"user_assigned_identities": {} |
| 927 |
pod_identity_profile: { |
| 928 |
"allow_network_plugin_kubenet": false, |
| 929 |
"user_assigned_identities": [ |
| 930 |
{ |
| 931 |
"binding_selector": "test", |
| 932 |
"identity": { |
| 933 |
"client_id": xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx, |
| 934 |
"object_id": xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" |
| 935 |
}, |
| 936 |
"name": "fredtest", |
| 937 |
"namespace": "fredtest", |
| 938 |
"provisioning_state": "Updating" |
| 939 |
} |
| 940 |
] |
| 941 |
} |
| 942 |
security_profile: { |
| 943 |
'defender': { |
| 944 |
"log_analytics_workspace_resource_id": "/subscriptions/xxx/resourceGroups/rg/providers/Microsoft.OperationalInsights/workspaces/fred01", |
| 945 |
"security_monitoring": { |
| 946 |
"enabled": true |
| 947 |
} |
| 948 |
}, |
| 949 |
"image_cleaner": { |
| 950 |
"enabled": false, |
| 951 |
"interval_hours": 38 |
| 952 |
} |
| 953 |
} |
| 954 |
tags: {} |
| 955 |
type: Microsoft.ContainerService/ManagedClusters |
| 956 |
windows_profile: None |
| 957 |
''' |
| 958 |
from ansible_collections.azure.azcollection.plugins.module_utils.azure_rm_common_ext import AzureRMModuleBaseExt |
| 959 |
|
| 960 |
try: |
| 961 |
from azure.core.exceptions import ResourceNotFoundError |
| 962 |
from azure.core.exceptions import HttpResponseError |
| 963 |
except ImportError: |
| 964 |
|
| 965 |
pass |
| 966 |
|
| 967 |
|
| 968 |
def create_aks_dict(aks): |
| 969 |
''' |
| 970 |
Helper method to deserialize a ContainerService to a dict |
| 971 |
:param: aks: ContainerService or AzureOperationPoller with the Azure callback object |
| 972 |
:return: dict with the state on Azure |
| 973 |
''' |
| 974 |
|
| 975 |
return dict( |
| 976 |
id=aks.id, |
| 977 |
name=aks.name, |
| 978 |
location=aks.location, |
| 979 |
dns_prefix=aks.dns_prefix, |
| 980 |
kubernetes_version=aks.kubernetes_version, |
| 981 |
tags=aks.tags, |
| 982 |
disable_local_accounts=aks.disable_local_accounts, |
| 983 |
linux_profile=create_linux_profile_dict(aks.linux_profile), |
| 984 |
identity=aks.identity.as_dict() if aks.identity else {}, |
| 985 |
service_principal_profile=create_service_principal_profile_dict( |
| 986 |
aks.service_principal_profile), |
| 987 |
provisioning_state=aks.provisioning_state, |
| 988 |
agent_pool_profiles=create_agent_pool_profiles_dict( |
| 989 |
aks.agent_pool_profiles), |
| 990 |
type=aks.type, |
| 991 |
kube_config=aks.kube_config, |
| 992 |
enable_rbac=aks.enable_rbac, |
| 993 |
network_profile=create_network_profiles_dict(aks.network_profile), |
| 994 |
aad_profile=create_aad_profiles_dict(aks.aad_profile), |
| 995 |
api_server_access_profile=create_api_server_access_profile_dict(aks.api_server_access_profile), |
| 996 |
addon=create_addon_dict(aks.addon_profiles), |
| 997 |
fqdn=aks.fqdn, |
| 998 |
node_resource_group=aks.node_resource_group, |
| 999 |
auto_upgrade_profile=create_auto_upgrade_profile_dict(aks.auto_upgrade_profile), |
| 1000 |
windows_profile=create_windows_profile_dict(aks.windows_profile), |
| 1001 |
pod_identity_profile=create_pod_identity_profile(aks.pod_identity_profile.as_dict()) if aks.pod_identity_profile else None, |
| 1002 |
security_profile=aks.security_profile.as_dict() if aks.security_profile else None, |
| 1003 |
) |
| 1004 |
|
| 1005 |
|
| 1006 |
def create_auto_upgrade_profile_dict(auto_upgrade_profile): |
| 1007 |
return dict( |
| 1008 |
upgrade_channel=auto_upgrade_profile.upgrade_channel, |
| 1009 |
node_os_upgrade_channel=auto_upgrade_profile.node_os_upgrade_channel |
| 1010 |
) if auto_upgrade_profile else None |
| 1011 |
|
| 1012 |
|
| 1013 |
def create_pod_identity_profile(pod_profile): |
| 1014 |
return dict( |
| 1015 |
enabled=pod_profile.get('enabled', False), |
| 1016 |
allow_network_plugin_kubenet=pod_profile.get('allow_network_plugin_kubenet', False), |
| 1017 |
user_assigned_identities=pod_profile.get('user_assigned_identities') |
| 1018 |
) if pod_profile else {} |
| 1019 |
|
| 1020 |
|
| 1021 |
def create_network_profiles_dict(network): |
| 1022 |
return dict( |
| 1023 |
network_plugin=network.network_plugin, |
| 1024 |
network_plugin_mode=network.network_plugin_mode, |
| 1025 |
network_policy=network.network_policy, |
| 1026 |
pod_cidr=network.pod_cidr, |
| 1027 |
service_cidr=network.service_cidr, |
| 1028 |
dns_service_ip=network.dns_service_ip, |
| 1029 |
load_balancer_sku=network.load_balancer_sku, |
| 1030 |
outbound_type=network.outbound_type |
| 1031 |
) if network else dict() |
| 1032 |
|
| 1033 |
|
| 1034 |
def create_aad_profiles_dict(aad): |
| 1035 |
return aad.as_dict() if aad else dict() |
| 1036 |
|
| 1037 |
|
| 1038 |
def create_api_server_access_profile_dict(api_server): |
| 1039 |
return api_server.as_dict() if api_server else dict() |
| 1040 |
|
| 1041 |
|
| 1042 |
def create_addon_dict(addon): |
| 1043 |
result = dict() |
| 1044 |
addon = addon or dict() |
| 1045 |
for key in addon.keys(): |
| 1046 |
result[key] = addon[key].config |
| 1047 |
if result[key] is None: |
| 1048 |
result[key] = {} |
| 1049 |
result[key]['enabled'] = addon[key].enabled |
| 1050 |
return result |
| 1051 |
|
| 1052 |
|
| 1053 |
def create_linux_profile_dict(linuxprofile): |
| 1054 |
''' |
| 1055 |
Helper method to deserialize a ContainerServiceLinuxProfile to a dict |
| 1056 |
:param: linuxprofile: ContainerServiceLinuxProfile with the Azure callback object |
| 1057 |
:return: dict with the state on Azure |
| 1058 |
''' |
| 1059 |
if linuxprofile: |
| 1060 |
return dict( |
| 1061 |
ssh_key=linuxprofile.ssh.public_keys[0].key_data, |
| 1062 |
admin_username=linuxprofile.admin_username |
| 1063 |
) |
| 1064 |
else: |
| 1065 |
return None |
| 1066 |
|
| 1067 |
|
| 1068 |
def create_service_principal_profile_dict(serviceprincipalprofile): |
| 1069 |
''' |
| 1070 |
Helper method to deserialize a ContainerServiceServicePrincipalProfile to a dict |
| 1071 |
Note: For security reason, the service principal secret is skipped on purpose. |
| 1072 |
:param: serviceprincipalprofile: ContainerServiceServicePrincipalProfile with the Azure callback object |
| 1073 |
:return: dict with the state on Azure |
| 1074 |
''' |
| 1075 |
return dict( |
| 1076 |
client_id=serviceprincipalprofile.client_id |
| 1077 |
) |
| 1078 |
|
| 1079 |
|
| 1080 |
def create_windows_profile_dict(windowsprofile): |
| 1081 |
''' |
| 1082 |
Helper method to deserialize a ManagedClusterWindowsProfile to a dict |
| 1083 |
:param: windowsprofile: ManagedClusterWindowsProfile with the Azure callback object |
| 1084 |
:return: dict with the state on Azure |
| 1085 |
''' |
| 1086 |
if windowsprofile: |
| 1087 |
return dict( |
| 1088 |
admin_username=windowsprofile.admin_username, |
| 1089 |
admin_password=windowsprofile.admin_password, |
| 1090 |
gmsa_profile=windowsprofile.gmsa_profile.as_dict() if windowsprofile.gmsa_profile else {}, |
| 1091 |
) |
| 1092 |
else: |
| 1093 |
return None |
| 1094 |
|
| 1095 |
|
| 1096 |
def create_agent_pool_profiles_dict(agentpoolprofiles): |
| 1097 |
''' |
| 1098 |
Helper method to deserialize a ContainerServiceAgentPoolProfile to a dict |
| 1099 |
:param: agentpoolprofiles: ContainerServiceAgentPoolProfile with the Azure callback object |
| 1100 |
:return: dict with the state on Azure |
| 1101 |
''' |
| 1102 |
return [dict( |
| 1103 |
count=profile.count, |
| 1104 |
vm_size=profile.vm_size, |
| 1105 |
name=profile.name, |
| 1106 |
os_disk_size_gb=profile.os_disk_size_gb, |
| 1107 |
scale_set_priority=getattr(profile, 'scale_set_priority', None), |
| 1108 |
scale_set_eviction_policy=getattr(profile, 'scale_set_eviction_policy', None), |
| 1109 |
spot_max_price=getattr(profile, 'spot_max_price', None), |
| 1110 |
vnet_subnet_id=profile.vnet_subnet_id, |
| 1111 |
availability_zones=profile.availability_zones, |
| 1112 |
os_type=profile.os_type, |
| 1113 |
type=profile.type, |
| 1114 |
mode=profile.mode, |
| 1115 |
orchestrator_version=profile.orchestrator_version, |
| 1116 |
enable_auto_scaling=profile.enable_auto_scaling, |
| 1117 |
max_count=profile.max_count, |
| 1118 |
node_labels=profile.node_labels, |
| 1119 |
min_count=profile.min_count, |
| 1120 |
max_pods=profile.max_pods, |
| 1121 |
tags=profile.tags, |
| 1122 |
os_sku=profile.os_sku, |
| 1123 |
security_profile=dict( |
| 1124 |
enable_secure_boot=profile.security_profile.enable_secure_boot, |
| 1125 |
enable_vtpm=profile.security_profile.enable_vtpm |
| 1126 |
) if profile.security_profile is not None else None |
| 1127 |
) for profile in agentpoolprofiles] if agentpoolprofiles else None |
| 1128 |
|
| 1129 |
|
| 1130 |
def create_addon_profiles_spec(): |
| 1131 |
''' |
| 1132 |
Helper method to parse the ADDONS dictionary and generate the addon spec |
| 1133 |
''' |
| 1134 |
spec = dict() |
| 1135 |
for key in ADDONS.keys(): |
| 1136 |
values = ADDONS[key] |
| 1137 |
addon_spec = dict( |
| 1138 |
enabled=dict(type='bool', default=True) |
| 1139 |
) |
| 1140 |
configs = values.get('config') or {} |
| 1141 |
for item in configs.keys(): |
| 1142 |
addon_spec[item] = dict(type='str', aliases=[configs[item]], required=True) |
| 1143 |
if key == 'azure_keyvault_secrets_provider': |
| 1144 |
spec[key] = dict(type='dict', no_log=True, options=addon_spec, aliases=[values['name']]) |
| 1145 |
else: |
| 1146 |
spec[key] = dict(type='dict', options=addon_spec, aliases=[values['name']]) |
| 1147 |
return spec |
| 1148 |
|
| 1149 |
|
| 1150 |
ADDONS = { |
| 1151 |
'http_application_routing': dict(name='httpApplicationRouting'), |
| 1152 |
'monitoring': dict(name='omsagent', config={'log_analytics_workspace_resource_id': 'logAnalyticsWorkspaceResourceID'}), |
| 1153 |
'virtual_node': dict(name='aciConnector', config={'subnet_resource_id': 'SubnetName'}), |
| 1154 |
'azure_keyvault_secrets_provider': dict(name='azureKeyvaultSecretsProvider') |
| 1155 |
} |
| 1156 |
|
| 1157 |
|
| 1158 |
linux_profile_spec = dict( |
| 1159 |
admin_username=dict(type='str', required=True), |
| 1160 |
ssh_key=dict(type='str', no_log=True, required=True) |
| 1161 |
) |
| 1162 |
|
| 1163 |
|
| 1164 |
service_principal_spec = dict( |
| 1165 |
client_id=dict(type='str', required=True), |
| 1166 |
client_secret=dict(type='str', no_log=True) |
| 1167 |
) |
| 1168 |
|
| 1169 |
|
| 1170 |
agent_pool_profile_spec = dict( |
| 1171 |
name=dict(type='str', required=True), |
| 1172 |
count=dict(type='int', required=True), |
| 1173 |
vm_size=dict(type='str', required=True), |
| 1174 |
os_disk_size_gb=dict(type='int'), |
| 1175 |
scale_set_priority=dict(type='str', choices=['Regular', 'Spot']), |
| 1176 |
scale_set_eviction_policy=dict(type='str', choices=['Delete', 'Deallocate']), |
| 1177 |
spot_max_price=dict(type='float'), |
| 1178 |
dns_prefix=dict(type='str'), |
| 1179 |
ports=dict(type='list', elements='int'), |
| 1180 |
storage_profiles=dict(type='str', choices=[ |
| 1181 |
'StorageAccount', 'ManagedDisks']), |
| 1182 |
vnet_subnet_id=dict(type='str'), |
| 1183 |
availability_zones=dict(type='list', elements='int', choices=[1, 2, 3]), |
| 1184 |
os_type=dict(type='str', choices=['Linux', 'Windows', 'linux', 'windows']), |
| 1185 |
orchestrator_version=dict(type='str', required=False), |
| 1186 |
type=dict(type='str', choices=['VirtualMachineScaleSets', 'AvailabilitySet']), |
| 1187 |
mode=dict(type='str', choices=['System', 'User']), |
| 1188 |
enable_auto_scaling=dict(type='bool'), |
| 1189 |
max_count=dict(type='int'), |
| 1190 |
node_labels=dict(type='dict'), |
| 1191 |
min_count=dict(type='int'), |
| 1192 |
max_pods=dict(type='int'), |
| 1193 |
tags=dict(type='dict'), |
| 1194 |
os_sku=dict(type='str', choices=['Ubuntu', 'AzureLinux', 'Windows2019', 'Windows2022']), |
| 1195 |
security_profile=dict( |
| 1196 |
type='dict', |
| 1197 |
options=dict( |
| 1198 |
enable_secure_boot=dict(type='bool', default=False), |
| 1199 |
enable_vtpm=dict(type='bool', default=False) |
| 1200 |
) |
| 1201 |
) |
| 1202 |
) |
| 1203 |
|
| 1204 |
|
| 1205 |
network_profile_spec = dict( |
| 1206 |
network_plugin=dict(type='str', choices=['azure', 'kubenet', 'none']), |
| 1207 |
network_plugin_mode=dict(type='str', choices=['Overlay']), |
| 1208 |
network_policy=dict(type='str', choices=['azure', 'calico']), |
| 1209 |
pod_cidr=dict(type='str'), |
| 1210 |
service_cidr=dict(type='str'), |
| 1211 |
dns_service_ip=dict(type='str'), |
| 1212 |
load_balancer_sku=dict(type='str', choices=['standard', 'basic']), |
| 1213 |
outbound_type=dict(type='str', default='loadBalancer', choices=['userDefinedRouting', 'loadBalancer', 'userAssignedNATGateway', 'managedNATGateway']) |
| 1214 |
) |
| 1215 |
|
| 1216 |
|
| 1217 |
aad_profile_spec = dict( |
| 1218 |
client_app_id=dict(type='str'), |
| 1219 |
server_app_id=dict(type='str'), |
| 1220 |
server_app_secret=dict(type='str', no_log=True), |
| 1221 |
tenant_id=dict(type='str'), |
| 1222 |
managed=dict(type='bool', default='false'), |
| 1223 |
enable_azure_rbac=dict(type='bool', default='false'), |
| 1224 |
admin_group_object_ids=dict(type='list', elements='str') |
| 1225 |
) |
| 1226 |
|
| 1227 |
|
| 1228 |
api_server_access_profile_spec = dict( |
| 1229 |
authorized_ip_ranges=dict(type='list', elements='str'), |
| 1230 |
enable_private_cluster=dict(type='bool'), |
| 1231 |
) |
| 1232 |
|
| 1233 |
|
| 1234 |
managed_identity_spec = dict( |
| 1235 |
type=dict(type='str', choices=['SystemAssigned', 'UserAssigned'], default='SystemAssigned'), |
| 1236 |
user_assigned_identities=dict(type='str'), |
| 1237 |
) |
| 1238 |
|
| 1239 |
|
| 1240 |
windows_profile_spec = dict( |
| 1241 |
admin_username=dict(type='str', required=True), |
| 1242 |
admin_password=dict(type='str', no_log=True, required=True), |
| 1243 |
gmsa_profile=dict( |
| 1244 |
type='dict', |
| 1245 |
options=dict( |
| 1246 |
enabled=dict(type='bool', default=False), |
| 1247 |
dns_server=dict(type='str', required=False), |
| 1248 |
root_domain_name=dict(type='str', required=False), |
| 1249 |
) |
| 1250 |
) |
| 1251 |
) |
| 1252 |
|
| 1253 |
|
| 1254 |
class dotdict(dict): |
| 1255 |
"""dot.notation access to dictionary attributes""" |
| 1256 |
__getattr__ = dict.get |
| 1257 |
__setattr__ = dict.__setitem__ |
| 1258 |
__delattr__ = dict.__delitem__ |
| 1259 |
|
| 1260 |
|
| 1261 |
class AzureRMManagedCluster(AzureRMModuleBaseExt): |
| 1262 |
"""Configuration class for an Azure RM container service (AKS) resource""" |
| 1263 |
|
| 1264 |
def __init__(self): |
| 1265 |
self.module_arg_spec = dict( |
| 1266 |
resource_group=dict( |
| 1267 |
type='str', |
| 1268 |
required=True |
| 1269 |
), |
| 1270 |
name=dict( |
| 1271 |
type='str', |
| 1272 |
required=True |
| 1273 |
), |
| 1274 |
state=dict( |
| 1275 |
type='str', |
| 1276 |
default='present', |
| 1277 |
choices=['present', 'absent'] |
| 1278 |
), |
| 1279 |
location=dict( |
| 1280 |
type='str' |
| 1281 |
), |
| 1282 |
dns_prefix=dict( |
| 1283 |
type='str' |
| 1284 |
), |
| 1285 |
kubernetes_version=dict( |
| 1286 |
type='str' |
| 1287 |
), |
| 1288 |
linux_profile=dict( |
| 1289 |
type='dict', |
| 1290 |
options=linux_profile_spec |
| 1291 |
), |
| 1292 |
agent_pool_profiles=dict( |
| 1293 |
type='list', |
| 1294 |
elements='dict', |
| 1295 |
options=agent_pool_profile_spec |
| 1296 |
), |
| 1297 |
windows_profile=dict( |
| 1298 |
type='dict', |
| 1299 |
options=windows_profile_spec |
| 1300 |
), |
| 1301 |
service_principal=dict( |
| 1302 |
type='dict', |
| 1303 |
options=service_principal_spec |
| 1304 |
), |
| 1305 |
identity=dict( |
| 1306 |
type='dict', |
| 1307 |
options=managed_identity_spec, |
| 1308 |
required_if=[ |
| 1309 |
('type', 'UserAssigned', [ |
| 1310 |
'user_assigned_identities']), |
| 1311 |
] |
| 1312 |
), |
| 1313 |
enable_rbac=dict( |
| 1314 |
type='bool', |
| 1315 |
default=False |
| 1316 |
), |
| 1317 |
network_profile=dict( |
| 1318 |
type='dict', |
| 1319 |
options=network_profile_spec |
| 1320 |
), |
| 1321 |
aad_profile=dict( |
| 1322 |
type='dict', |
| 1323 |
options=aad_profile_spec |
| 1324 |
), |
| 1325 |
addon=dict( |
| 1326 |
type='dict', |
| 1327 |
options=create_addon_profiles_spec() |
| 1328 |
), |
| 1329 |
api_server_access_profile=dict( |
| 1330 |
type='dict', |
| 1331 |
options=api_server_access_profile_spec |
| 1332 |
), |
| 1333 |
node_resource_group=dict( |
| 1334 |
type='str' |
| 1335 |
), |
| 1336 |
pod_identity_profile=dict( |
| 1337 |
type='dict', |
| 1338 |
options=dict( |
| 1339 |
enabled=dict(type='bool'), |
| 1340 |
allow_network_plugin_kubenet=dict(type='bool'), |
| 1341 |
user_assigned_identities=dict( |
| 1342 |
type='list', |
| 1343 |
elements='dict', |
| 1344 |
options=dict( |
| 1345 |
name=dict(type='str', required=True), |
| 1346 |
namespace=dict(type='str', required=True), |
| 1347 |
binding_selector=dict(type='str'), |
| 1348 |
identity=dict( |
| 1349 |
type='dict', |
| 1350 |
required=True, |
| 1351 |
options=dict( |
| 1352 |
resource_id=dict(type='str'), |
| 1353 |
client_id=dict(type='str'), |
| 1354 |
object_id=dict(type='str') |
| 1355 |
) |
| 1356 |
) |
| 1357 |
) |
| 1358 |
) |
| 1359 |
) |
| 1360 |
), |
| 1361 |
auto_upgrade_profile=dict( |
| 1362 |
type='dict', |
| 1363 |
options=dict( |
| 1364 |
upgrade_channel=dict( |
| 1365 |
type='str', |
| 1366 |
choices=["rapid", "stable", "patch", "node-image", "none"], |
| 1367 |
default='node-image' |
| 1368 |
), |
| 1369 |
node_os_upgrade_channel=dict( |
| 1370 |
type='str', |
| 1371 |
choices=["None", "Unmanaged", "SecurityPatch", "NodeImage"], |
| 1372 |
default='NodeImage' |
| 1373 |
) |
| 1374 |
) |
| 1375 |
), |
| 1376 |
disable_local_accounts=dict( |
| 1377 |
type='bool' |
| 1378 |
), |
| 1379 |
security_profile=dict( |
| 1380 |
type='dict', |
| 1381 |
options=dict( |
| 1382 |
defender=dict( |
| 1383 |
type='dict', |
| 1384 |
options=dict( |
| 1385 |
log_analytics_workspace_resource_id=dict(type='str'), |
| 1386 |
security_monitoring=dict( |
| 1387 |
type='dict', |
| 1388 |
options=dict( |
| 1389 |
enabled=dict(type='bool') |
| 1390 |
) |
| 1391 |
) |
| 1392 |
) |
| 1393 |
), |
| 1394 |
azure_key_vault_kms=dict( |
| 1395 |
type='dict', |
| 1396 |
no_log=True, |
| 1397 |
options=dict( |
| 1398 |
enabled=dict(type='bool', default=False), |
| 1399 |
key_id=dict(type='str'), |
| 1400 |
key_vault_network_access=dict(type='str', choices=['Private', 'Public'], default='Public'), |
| 1401 |
key_vault_resource_id=dict(type='str') |
| 1402 |
) |
| 1403 |
), |
| 1404 |
workload_identity=dict( |
| 1405 |
type='dict', |
| 1406 |
options=dict( |
| 1407 |
enabled=dict(type='bool'), |
| 1408 |
) |
| 1409 |
), |
| 1410 |
image_cleaner=dict( |
| 1411 |
type='dict', |
| 1412 |
options=dict( |
| 1413 |
enabled=dict(type='bool'), |
| 1414 |
interval_hours=dict(type='int') |
| 1415 |
) |
| 1416 |
), |
| 1417 |
) |
| 1418 |
), |
| 1419 |
) |
| 1420 |
|
| 1421 |
self.resource_group = None |
| 1422 |
self.name = None |
| 1423 |
self.location = None |
| 1424 |
self.dns_prefix = None |
| 1425 |
self.kubernetes_version = None |
| 1426 |
self.tags = None |
| 1427 |
self.state = None |
| 1428 |
self.linux_profile = None |
| 1429 |
self.agent_pool_profiles = None |
| 1430 |
self.service_principal = None |
| 1431 |
self.identity = None |
| 1432 |
self.enable_rbac = False |
| 1433 |
self.network_profile = None |
| 1434 |
self.aad_profile = None |
| 1435 |
self.api_server_access_profile = None |
| 1436 |
self.addon = None |
| 1437 |
self.node_resource_group = None |
| 1438 |
self.pod_identity_profile = None |
| 1439 |
self.auto_upgrade_profile = None |
| 1440 |
self.windows_profile = None |
| 1441 |
self.disable_local_accounts = None |
| 1442 |
self.security_profile = None |
| 1443 |
|
| 1444 |
mutually_exclusive = [('identity', 'service_principal')] |
| 1445 |
|
| 1446 |
required_if = [ |
| 1447 |
('state', 'present', [ |
| 1448 |
'dns_prefix', 'agent_pool_profiles']) |
| 1449 |
] |
| 1450 |
|
| 1451 |
self.results = dict(changed=False) |
| 1452 |
|
| 1453 |
super(AzureRMManagedCluster, self).__init__(derived_arg_spec=self.module_arg_spec, |
| 1454 |
supports_check_mode=True, |
| 1455 |
supports_tags=True, |
| 1456 |
required_if=required_if, |
| 1457 |
mutually_exclusive=mutually_exclusive) |
| 1458 |
|
| 1459 |
def exec_module(self, **kwargs): |
| 1460 |
"""Main module execution method""" |
| 1461 |
|
| 1462 |
for key in list(self.module_arg_spec.keys()) + ['tags']: |
| 1463 |
setattr(self, key, kwargs[key]) |
| 1464 |
|
| 1465 |
resource_group = None |
| 1466 |
to_be_updated = False |
| 1467 |
update_tags = False |
| 1468 |
update_agentpool = False |
| 1469 |
|
| 1470 |
resource_group = self.get_resource_group(self.resource_group) |
| 1471 |
if not self.location: |
| 1472 |
self.location = resource_group.location |
| 1473 |
|
| 1474 |
response = self.get_aks() |
| 1475 |
|
| 1476 |
|
| 1477 |
if self.state == 'present': |
| 1478 |
available_versions = self.get_all_versions() |
| 1479 |
if not response: |
| 1480 |
to_be_updated = True |
| 1481 |
|
| 1482 |
if not self.service_principal and not self.identity: |
| 1483 |
self.identity = dotdict({'type': 'SystemAssigned'}) |
| 1484 |
if self.identity: |
| 1485 |
changed, new_identity_obj = self.update_identity(self.identity, {}) |
| 1486 |
if changed: |
| 1487 |
self.identity_obj = new_identity_obj |
| 1488 |
if self.kubernetes_version not in available_versions.keys(): |
| 1489 |
self.fail("Unsupported kubernetes version. Expected one of {0} but got {1}".format(available_versions.keys(), self.kubernetes_version)) |
| 1490 |
else: |
| 1491 |
self.results = response |
| 1492 |
self.results['changed'] = False |
| 1493 |
self.log('Results : {0}'.format(response)) |
| 1494 |
update_tags, response['tags'] = self.update_tags(response['tags']) |
| 1495 |
|
| 1496 |
if response and not self.service_principal and not self.identity: |
| 1497 |
current_id = response.get('identity', {}) |
| 1498 |
if current_id.get('type') in ['UserAssigned', 'SystemAssigned']: |
| 1499 |
|
| 1500 |
self.identity = {'type': current_id['type']} |
| 1501 |
|
| 1502 |
if current_id['type'] == 'UserAssigned' and current_id.get('user_assigned_identities'): |
| 1503 |
|
| 1504 |
uai_list = list(current_id['user_assigned_identities'].keys()) |
| 1505 |
if uai_list: |
| 1506 |
self.identity['user_assigned_identities'] = uai_list[0] |
| 1507 |
else: |
| 1508 |
|
| 1509 |
self.identity = {'type': 'SystemAssigned'} |
| 1510 |
|
| 1511 |
if response['provisioning_state'] == "Succeeded": |
| 1512 |
|
| 1513 |
def is_property_changed(profile, property, ignore_case=False): |
| 1514 |
base = response[profile].get(property) |
| 1515 |
new = getattr(self, profile).get(property) |
| 1516 |
if ignore_case: |
| 1517 |
return base.lower() != new.lower() |
| 1518 |
else: |
| 1519 |
return base != new |
| 1520 |
|
| 1521 |
|
| 1522 |
if self.linux_profile and is_property_changed('linux_profile', 'ssh_key'): |
| 1523 |
self.log(("Linux Profile Diff SSH, Was {0} / Now {1}" |
| 1524 |
.format(response['linux_profile']['ssh_key'], self.linux_profile.get('ssh_key')))) |
| 1525 |
to_be_updated = True |
| 1526 |
|
| 1527 |
|
| 1528 |
|
| 1529 |
|
| 1530 |
|
| 1531 |
if self.linux_profile and is_property_changed('linux_profile', 'admin_username'): |
| 1532 |
self.log(("Linux Profile Diff User, Was {0} / Now {1}" |
| 1533 |
.format(response['linux_profile']['admin_username'], self.linux_profile.get('admin_username')))) |
| 1534 |
to_be_updated = True |
| 1535 |
|
| 1536 |
|
| 1537 |
|
| 1538 |
if len(response['agent_pool_profiles']) != len(self.agent_pool_profiles): |
| 1539 |
self.log("Agent Pool count is diff, need to update") |
| 1540 |
update_agentpool = True |
| 1541 |
|
| 1542 |
if response['kubernetes_version'] != self.kubernetes_version: |
| 1543 |
upgrade_versions = available_versions.get(response['kubernetes_version']) or available_versions.keys() |
| 1544 |
if upgrade_versions and self.kubernetes_version not in upgrade_versions: |
| 1545 |
self.fail('Cannot upgrade kubernetes version to {0}, supported value are {1}'.format(self.kubernetes_version, upgrade_versions)) |
| 1546 |
to_be_updated = True |
| 1547 |
|
| 1548 |
if response['enable_rbac'] != self.enable_rbac: |
| 1549 |
to_be_updated = True |
| 1550 |
|
| 1551 |
if self.disable_local_accounts is not None: |
| 1552 |
if response.get('disable_local_accounts') is None: |
| 1553 |
to_be_updated = True |
| 1554 |
elif bool(self.disable_local_accounts) != bool(response.get('disable_local_accounts')): |
| 1555 |
to_be_updated = True |
| 1556 |
else: |
| 1557 |
self.disable_local_accounts = response.get('disable_local_accounts') |
| 1558 |
|
| 1559 |
if response['api_server_access_profile'] != self.api_server_access_profile and self.api_server_access_profile is not None: |
| 1560 |
if bool(self.api_server_access_profile.get('enable_private_cluster')) != \ |
| 1561 |
bool(response['api_server_access_profile'].get('enable_private_cluster')): |
| 1562 |
self.log(("Api Server Access Diff - Origin {0} / Update {1}" |
| 1563 |
.format(str(self.api_server_access_profile), str(response['api_server_access_profile'])))) |
| 1564 |
self.fail("The enable_private_cluster of the api server access profile cannot be updated") |
| 1565 |
elif self.api_server_access_profile.get('authorized_ip_ranges') is not None and \ |
| 1566 |
len(self.api_server_access_profile.get('authorized_ip_ranges')) != \ |
| 1567 |
len(response['api_server_access_profile'].get('authorized_ip_ranges', [])): |
| 1568 |
self.log(("Api Server Access Diff - Origin {0} / Update {1}" |
| 1569 |
.format(str(self.api_server_access_profile), str(response['api_server_access_profile'])))) |
| 1570 |
to_be_updated = True |
| 1571 |
|
| 1572 |
if self.network_profile: |
| 1573 |
for key in self.network_profile.keys(): |
| 1574 |
original = response['network_profile'].get(key) or '' |
| 1575 |
if self.network_profile[key] and self.network_profile[key].lower() != original.lower(): |
| 1576 |
to_be_updated = True |
| 1577 |
|
| 1578 |
def compare_addon(origin, patch, config): |
| 1579 |
if not patch: |
| 1580 |
return True |
| 1581 |
if not origin: |
| 1582 |
return False |
| 1583 |
if origin['enabled'] != patch['enabled']: |
| 1584 |
return False |
| 1585 |
config = config or dict() |
| 1586 |
for key in config.keys(): |
| 1587 |
if origin.get(config[key]) != patch.get(key): |
| 1588 |
return False |
| 1589 |
return True |
| 1590 |
|
| 1591 |
if self.addon: |
| 1592 |
for key in ADDONS.keys(): |
| 1593 |
addon_name = ADDONS[key]['name'] |
| 1594 |
if not compare_addon(response['addon'].get(addon_name), self.addon.get(key), ADDONS[key].get('config')): |
| 1595 |
to_be_updated = True |
| 1596 |
|
| 1597 |
if self.windows_profile: |
| 1598 |
if not self.default_compare({}, |
| 1599 |
self.windows_profile.get('gmsa_profile'), |
| 1600 |
response['windows_profile'].get('gmsa_profile'), |
| 1601 |
'', dict(compare=[])): |
| 1602 |
to_be_updated = True |
| 1603 |
else: |
| 1604 |
self.windows_profile['gmsa_profile'] = response['windows_profile']['gmsa_profile'] |
| 1605 |
|
| 1606 |
if not self.default_compare({}, self.security_profile, response['security_profile'], '', dict(compare=[])): |
| 1607 |
to_be_updated = True |
| 1608 |
else: |
| 1609 |
self.security_profile = response['security_profile'] |
| 1610 |
|
| 1611 |
if not self.default_compare({}, self.auto_upgrade_profile, response['auto_upgrade_profile'], '', dict(compare=[])): |
| 1612 |
to_be_updated = True |
| 1613 |
else: |
| 1614 |
self.auto_upgrade_profile = response['auto_upgrade_profile'] |
| 1615 |
|
| 1616 |
if self.aad_profile and 'admin_group_object_ids' in self.aad_profile and 'admin_group_object_i_ds' not in self.aad_profile: |
| 1617 |
self.aad_profile['admin_group_object_i_ds'] = self.aad_profile.pop('admin_group_object_ids') |
| 1618 |
|
| 1619 |
if not self.default_compare({}, self.aad_profile, response['aad_profile'], '', dict(compare=[])): |
| 1620 |
to_be_updated = True |
| 1621 |
else: |
| 1622 |
self.aad_profile = response['aad_profile'] |
| 1623 |
|
| 1624 |
for profile_result in response['agent_pool_profiles']: |
| 1625 |
matched = False |
| 1626 |
for profile_self in self.agent_pool_profiles: |
| 1627 |
if profile_result['name'] == profile_self['name']: |
| 1628 |
matched = True |
| 1629 |
os_disk_size_gb = profile_self.get('os_disk_size_gb') or profile_result['os_disk_size_gb'] |
| 1630 |
vnet_subnet_id = profile_self.get('vnet_subnet_id', profile_result['vnet_subnet_id']) |
| 1631 |
count = profile_self['count'] |
| 1632 |
orchestrator_version = profile_self['orchestrator_version'] |
| 1633 |
vm_size = profile_self['vm_size'] |
| 1634 |
availability_zones = profile_self['availability_zones'] |
| 1635 |
enable_auto_scaling = profile_self['enable_auto_scaling'] |
| 1636 |
mode = profile_self['mode'] |
| 1637 |
max_count = profile_self['max_count'] |
| 1638 |
node_labels = profile_self['node_labels'] |
| 1639 |
min_count = profile_self['min_count'] |
| 1640 |
max_pods = profile_self['max_pods'] |
| 1641 |
tags = profile_self['tags'] |
| 1642 |
security_profile = profile_self.get('security_profile') |
| 1643 |
|
| 1644 |
if max_pods is not None and profile_result['max_pods'] != max_pods: |
| 1645 |
self.log(("Agent Profile Diff - Origin {0} / Update {1}".format(str(profile_result), str(profile_self)))) |
| 1646 |
self.fail("The max_pods of the agent pool cannot be updated") |
| 1647 |
elif vnet_subnet_id is not None and profile_result['vnet_subnet_id'] != vnet_subnet_id: |
| 1648 |
self.log(("Agent Profile Diff - Origin {0} / Update {1}".format(str(profile_result), str(profile_self)))) |
| 1649 |
self.fail("The vnet_subnet_id of the agent pool cannot be updated") |
| 1650 |
elif availability_zones is not None and \ |
| 1651 |
' '.join(map(str, profile_result['availability_zones'])) != ' '.join(map(str, availability_zones)): |
| 1652 |
self.log(("Agent Profile Diff - Origin {0} / Update {1}".format(str(profile_result), str(profile_self)))) |
| 1653 |
self.fail("The availability_zones of the agent pool cannot be updated") |
| 1654 |
|
| 1655 |
if count is not None and profile_result['count'] != count: |
| 1656 |
self.log(("Agent Profile Diff - Origin {0} / Update {1}".format(str(profile_result), str(profile_self)))) |
| 1657 |
to_be_updated = True |
| 1658 |
elif vm_size is not None and profile_result['vm_size'] != vm_size: |
| 1659 |
self.log(("Agent Profile Diff - Origin {0} / Update {1}".format(str(profile_result), str(profile_self)))) |
| 1660 |
to_be_updated = True |
| 1661 |
elif os_disk_size_gb is not None and profile_result['os_disk_size_gb'] != os_disk_size_gb: |
| 1662 |
self.log(("Agent Profile Diff - Origin {0} / Update {1}".format(str(profile_result), str(profile_self)))) |
| 1663 |
to_be_updated = True |
| 1664 |
elif enable_auto_scaling is not None and profile_result['enable_auto_scaling'] != enable_auto_scaling: |
| 1665 |
self.log(("Agent Profile Diff - Origin {0} / Update {1}".format(str(profile_result), str(profile_self)))) |
| 1666 |
to_be_updated = True |
| 1667 |
elif max_count is not None and profile_result['max_count'] != max_count: |
| 1668 |
self.log(("Agent Profile Diff - Origin {0} / Update {1}".format(str(profile_result), str(profile_self)))) |
| 1669 |
to_be_updated = True |
| 1670 |
elif min_count is not None and profile_result['min_count'] != min_count: |
| 1671 |
self.log(("Agent Profile Diff - Origin {0} / Update {1}".format(str(profile_result), str(profile_self)))) |
| 1672 |
to_be_updated = True |
| 1673 |
elif mode is not None and profile_result['mode'] != mode: |
| 1674 |
self.log(("Agent Profile Diff - Origin {0} / Update {1}".format(str(profile_result), str(profile_self)))) |
| 1675 |
to_be_updated = True |
| 1676 |
elif node_labels is not None and profile_result['node_labels'] != node_labels: |
| 1677 |
self.log(("Agent Profile Diff - Origin {0} / Update {1}".format(str(profile_result), str(profile_self)))) |
| 1678 |
to_be_updated = True |
| 1679 |
elif not self.default_compare({}, tags, profile_result['tags'], '', dict(compare=[])): |
| 1680 |
self.log("Agent Profile Diff - Origin {0} / Update {1}".format(profile_result['tags'], tags)) |
| 1681 |
to_be_updated = True |
| 1682 |
elif security_profile is not None: |
| 1683 |
if bool(security_profile['enable_secure_boot']) != bool(profile_result['security_profile']['enable_secure_boot']) or \ |
| 1684 |
bool(security_profile['enable_vtpm']) != bool(profile_result['security_profile']['enable_vtpm']): |
| 1685 |
self.log(("Agent Profile Diff - Origin {0} / Update {1}".format(str(profile_result), str(profile_self)))) |
| 1686 |
to_be_updated = True |
| 1687 |
|
| 1688 |
if profile_self.get('scale_set_priority') is None and profile_result.get('scale_set_priority') is not None: |
| 1689 |
profile_self['scale_set_priority'] = profile_result.get('scale_set_priority') |
| 1690 |
if profile_self.get('scale_set_eviction_policy') is None and profile_result.get('scale_set_eviction_policy') is not None: |
| 1691 |
profile_self['scale_set_eviction_policy'] = profile_result.get('scale_set_eviction_policy') |
| 1692 |
if profile_self.get('spot_max_price') is None and profile_result.get('spot_max_price') is not None: |
| 1693 |
profile_self['spot_max_price'] = profile_result.get('spot_max_price') |
| 1694 |
|
| 1695 |
if not matched: |
| 1696 |
self.log("Agent Pool not found") |
| 1697 |
to_be_updated = True |
| 1698 |
if not self.default_compare({}, self.pod_identity_profile, response['pod_identity_profile'], '', dict(compare=[])): |
| 1699 |
to_be_updated = True |
| 1700 |
else: |
| 1701 |
self.pod_identity_profile = response['pod_identity_profile'] |
| 1702 |
|
| 1703 |
|
| 1704 |
if not self.service_principal and not self.identity: |
| 1705 |
self.identity = dotdict({'type': 'SystemAssigned'}) |
| 1706 |
if self.identity: |
| 1707 |
changed, new_identity_obj = self.update_identity(self.identity, response.get('identity', {})) |
| 1708 |
if changed: |
| 1709 |
|
| 1710 |
self.identity_obj = new_identity_obj |
| 1711 |
to_be_updated = True |
| 1712 |
|
| 1713 |
if self.windows_profile and is_property_changed('windows_profile', 'admin_username'): |
| 1714 |
self.log(("Windows Profile Diff User, Was {0} / Now {1}" |
| 1715 |
.format(response['windows_profile']['admin_username'], self.windows_profile.get('admin_username')))) |
| 1716 |
to_be_updated = True |
| 1717 |
|
| 1718 |
|
| 1719 |
if update_agentpool: |
| 1720 |
self.log("Need to update agentpool") |
| 1721 |
if not self.check_mode: |
| 1722 |
response_profile_name_list = [response_profile['name'] for response_profile in response['agent_pool_profiles']] |
| 1723 |
self_profile_name_list = [self_profile['name'] for self_profile in self.agent_pool_profiles] |
| 1724 |
to_update = list(set(self_profile_name_list) - set(response_profile_name_list)) |
| 1725 |
to_delete = list(set(response_profile_name_list) - set(self_profile_name_list)) |
| 1726 |
if len(to_delete) > 0: |
| 1727 |
self.delete_agentpool(to_delete) |
| 1728 |
for profile in self.results['agent_pool_profiles']: |
| 1729 |
if profile['name'] in to_delete: |
| 1730 |
self.results['agent_pool_profiles'].remove(profile) |
| 1731 |
if len(to_update) > 0: |
| 1732 |
self.results['agent_pool_profiles'].extend(self.create_update_agentpool(to_update)) |
| 1733 |
self.log("Creation / Update done") |
| 1734 |
self.results['changed'] = True |
| 1735 |
|
| 1736 |
if to_be_updated: |
| 1737 |
self.log("Need to Create / Update the AKS instance") |
| 1738 |
|
| 1739 |
if not self.check_mode: |
| 1740 |
self.results = self.create_update_aks() |
| 1741 |
self.log("Creation / Update done") |
| 1742 |
|
| 1743 |
self.results['changed'] = True |
| 1744 |
elif update_tags: |
| 1745 |
self.log("Need to Update the AKS tags") |
| 1746 |
|
| 1747 |
if not self.check_mode: |
| 1748 |
self.results['tags'] = self.update_aks_tags() |
| 1749 |
self.results['changed'] = True |
| 1750 |
return self.results |
| 1751 |
|
| 1752 |
elif self.state == 'absent' and response: |
| 1753 |
self.log("Need to Delete the AKS instance") |
| 1754 |
self.results['changed'] = True |
| 1755 |
|
| 1756 |
if self.check_mode: |
| 1757 |
return self.results |
| 1758 |
|
| 1759 |
self.delete_aks() |
| 1760 |
|
| 1761 |
self.log("AKS instance deleted") |
| 1762 |
|
| 1763 |
return self.results |
| 1764 |
|
| 1765 |
def create_update_aks(self): |
| 1766 |
''' |
| 1767 |
Creates or updates a managed Azure container service (AKS) with the specified configuration of agents. |
| 1768 |
|
| 1769 |
:return: deserialized AKS instance state dictionary |
| 1770 |
''' |
| 1771 |
self.log("Creating / Updating the AKS instance {0}".format(self.name)) |
| 1772 |
|
| 1773 |
agentpools = [] |
| 1774 |
|
| 1775 |
if self.agent_pool_profiles: |
| 1776 |
agentpools = [self.create_agent_pool_profile_instance(profile) for profile in self.agent_pool_profiles] |
| 1777 |
|
| 1778 |
|
| 1779 |
if self.service_principal: |
| 1780 |
service_principal_profile = self.create_service_principal_profile_instance(self.service_principal) |
| 1781 |
else: |
| 1782 |
service_principal_profile = None |
| 1783 |
|
| 1784 |
if self.linux_profile: |
| 1785 |
linux_profile = self.create_linux_profile_instance(self.linux_profile) |
| 1786 |
else: |
| 1787 |
linux_profile = None |
| 1788 |
|
| 1789 |
if self.windows_profile: |
| 1790 |
windows_profile = self.create_windows_profile_instance(self.windows_profile) |
| 1791 |
else: |
| 1792 |
windows_profile = None |
| 1793 |
|
| 1794 |
if self.pod_identity_profile: |
| 1795 |
pod_identity_profile = self.managedcluster_models.ManagedClusterPodIdentityProfile( |
| 1796 |
enabled=self.pod_identity_profile.get('enabled'), |
| 1797 |
allow_network_plugin_kubenet=self.pod_identity_profile.get('allow_network_plugin_kubenet'), |
| 1798 |
user_assigned_identities=self.pod_identity_profile.get('user_assigned_identities') |
| 1799 |
) |
| 1800 |
else: |
| 1801 |
pod_identity_profile = None |
| 1802 |
|
| 1803 |
if self.auto_upgrade_profile is not None: |
| 1804 |
auto_upgrade_profile = self.managedcluster_models.ManagedClusterAutoUpgradeProfile( |
| 1805 |
upgrade_channel=self.auto_upgrade_profile.get('upgrade_channel'), |
| 1806 |
node_os_upgrade_channel=self.auto_upgrade_profile.get('node_os_upgrade_channel') |
| 1807 |
) |
| 1808 |
else: |
| 1809 |
auto_upgrade_profile = None |
| 1810 |
|
| 1811 |
if self.security_profile is not None: |
| 1812 |
security_profile = self.managedcluster_models.ManagedClusterSecurityProfile(**self.security_profile) |
| 1813 |
else: |
| 1814 |
security_profile = None |
| 1815 |
|
| 1816 |
identity_param = getattr(self, 'identity_obj', None) |
| 1817 |
if self.identity and identity_param is None: |
| 1818 |
identity_param = self.managedcluster_models.ManagedClusterIdentity( |
| 1819 |
type=self.identity['type'], |
| 1820 |
user_assigned_identities=({self.identity['user_assigned_identities']: {}} |
| 1821 |
if self.identity.get('user_assigned_identities') |
| 1822 |
else None)) |
| 1823 |
|
| 1824 |
if self.aad_profile: |
| 1825 |
|
| 1826 |
if not self.aad_profile.get('tenant_id'): |
| 1827 |
self.aad_profile['tenant_id'] = (self.results.get('aad_profile') or {}).get('tenant_id') |
| 1828 |
|
| 1829 |
|
| 1830 |
if 'managed' not in self.aad_profile: |
| 1831 |
current_managed = (self.results.get('aad_profile') or {}).get('managed') |
| 1832 |
if current_managed is not None: |
| 1833 |
self.aad_profile['managed'] = current_managed |
| 1834 |
|
| 1835 |
|
| 1836 |
if 'enable_azure_rbac' not in self.aad_profile: |
| 1837 |
current_rbac = (self.results.get('aad_profile') or {}).get('enable_azure_rbac') |
| 1838 |
if current_rbac is not None: |
| 1839 |
self.aad_profile['enable_azure_rbac'] = current_rbac |
| 1840 |
|
| 1841 |
if 'admin_group_object_ids' in self.aad_profile and 'admin_group_object_i_ds' not in self.aad_profile: |
| 1842 |
self.aad_profile['admin_group_object_i_ds'] = self.aad_profile.pop('admin_group_object_ids') |
| 1843 |
|
| 1844 |
parameters = self.managedcluster_models.ManagedCluster( |
| 1845 |
location=self.location, |
| 1846 |
dns_prefix=self.dns_prefix, |
| 1847 |
kubernetes_version=self.kubernetes_version, |
| 1848 |
tags=self.tags, |
| 1849 |
service_principal_profile=service_principal_profile, |
| 1850 |
agent_pool_profiles=agentpools, |
| 1851 |
linux_profile=linux_profile, |
| 1852 |
windows_profile=windows_profile, |
| 1853 |
identity=identity_param, |
| 1854 |
enable_rbac=self.enable_rbac, |
| 1855 |
network_profile=self.create_network_profile_instance(self.network_profile), |
| 1856 |
aad_profile=self.create_aad_profile_instance(self.aad_profile), |
| 1857 |
api_server_access_profile=self.create_api_server_access_profile_instance(self.api_server_access_profile), |
| 1858 |
addon_profiles=self.create_addon_profile_instance(self.addon), |
| 1859 |
node_resource_group=self.node_resource_group, |
| 1860 |
pod_identity_profile=pod_identity_profile, |
| 1861 |
auto_upgrade_profile=auto_upgrade_profile, |
| 1862 |
disable_local_accounts=self.disable_local_accounts, |
| 1863 |
security_profile=security_profile, |
| 1864 |
) |
| 1865 |
|
| 1866 |
|
| 1867 |
|
| 1868 |
|
| 1869 |
|
| 1870 |
|
| 1871 |
|
| 1872 |
try: |
| 1873 |
poller = self.managedcluster_client.managed_clusters.begin_create_or_update(self.resource_group, self.name, parameters) |
| 1874 |
response = self.get_poller_result(poller) |
| 1875 |
response.kube_config = self.get_aks_kubeconfig() |
| 1876 |
return create_aks_dict(response) |
| 1877 |
except Exception as exc: |
| 1878 |
self.log('Error attempting to create the AKS instance.') |
| 1879 |
self.fail("Error creating the AKS instance: {0}".format(exc)) |
| 1880 |
|
| 1881 |
def update_aks_tags(self): |
| 1882 |
try: |
| 1883 |
poller = self.managedcluster_client.managed_clusters.begin_update_tags(self.resource_group, self.name, self.tags) |
| 1884 |
response = self.get_poller_result(poller) |
| 1885 |
return response.tags |
| 1886 |
except Exception as exc: |
| 1887 |
self.fail("Error attempting to update AKS tags: {0}".format(exc.message)) |
| 1888 |
|
| 1889 |
def create_update_agentpool(self, to_update_name_list): |
| 1890 |
response_all = [] |
| 1891 |
for profile in self.agent_pool_profiles: |
| 1892 |
if (profile['name'] in to_update_name_list): |
| 1893 |
self.log("Creating / Updating the AKS agentpool {0}".format(profile['name'])) |
| 1894 |
parameters = self.managedcluster_models.AgentPool( |
| 1895 |
count=profile["count"], |
| 1896 |
vm_size=profile["vm_size"], |
| 1897 |
os_disk_size_gb=profile["os_disk_size_gb"], |
| 1898 |
scale_set_priority=profile.get("scale_set_priority"), |
| 1899 |
scale_set_eviction_policy=profile.get("scale_set_eviction_policy"), |
| 1900 |
spot_max_price=profile.get("spot_max_price"), |
| 1901 |
max_count=profile["max_count"], |
| 1902 |
node_labels=profile["node_labels"], |
| 1903 |
min_count=profile["min_count"], |
| 1904 |
orchestrator_version=profile["orchestrator_version"], |
| 1905 |
max_pods=profile["max_pods"], |
| 1906 |
enable_auto_scaling=profile["enable_auto_scaling"], |
| 1907 |
agent_pool_type=profile["type"], |
| 1908 |
mode=profile["mode"], |
| 1909 |
tags=profile['tags'], |
| 1910 |
security_profile=profile['security_profile'] |
| 1911 |
) |
| 1912 |
try: |
| 1913 |
poller = self.managedcluster_client.agent_pools.begin_create_or_update(self.resource_group, self.name, profile["name"], parameters) |
| 1914 |
response = self.get_poller_result(poller) |
| 1915 |
response_all.append(response) |
| 1916 |
except Exception as exc: |
| 1917 |
self.fail("Error attempting to update AKS agentpool: {0}".format(exc.message)) |
| 1918 |
return create_agent_pool_profiles_dict(response_all) |
| 1919 |
|
| 1920 |
def delete_agentpool(self, to_delete_name_list): |
| 1921 |
for name in to_delete_name_list: |
| 1922 |
self.log("Deleting the AKS agentpool {0}".format(name)) |
| 1923 |
try: |
| 1924 |
poller = self.managedcluster_client.agent_pools.begin_delete(self.resource_group, self.name, name) |
| 1925 |
self.get_poller_result(poller) |
| 1926 |
except Exception as exc: |
| 1927 |
self.fail("Error attempting to update AKS agentpool: {0}".format(exc.message)) |
| 1928 |
|
| 1929 |
def delete_aks(self): |
| 1930 |
''' |
| 1931 |
Deletes the specified managed container service (AKS) in the specified subscription and resource group. |
| 1932 |
|
| 1933 |
:return: True |
| 1934 |
''' |
| 1935 |
self.log("Deleting the AKS instance {0}".format(self.name)) |
| 1936 |
try: |
| 1937 |
poller = self.managedcluster_client.managed_clusters.begin_delete(self.resource_group, self.name) |
| 1938 |
self.get_poller_result(poller) |
| 1939 |
return True |
| 1940 |
except Exception as e: |
| 1941 |
self.log('Error attempting to delete the AKS instance.') |
| 1942 |
self.fail("Error deleting the AKS instance: {0}".format(e.message)) |
| 1943 |
return False |
| 1944 |
|
| 1945 |
def get_aks(self): |
| 1946 |
''' |
| 1947 |
Gets the properties of the specified container service. |
| 1948 |
|
| 1949 |
:return: deserialized AKS instance state dictionary |
| 1950 |
''' |
| 1951 |
self.log("Checking if the AKS instance {0} is present".format(self.name)) |
| 1952 |
try: |
| 1953 |
response = self.managedcluster_client.managed_clusters.get(self.resource_group, self.name) |
| 1954 |
self.log("Response : {0}".format(response)) |
| 1955 |
self.log("AKS instance : {0} found".format(response.name)) |
| 1956 |
response.kube_config = self.get_aks_kubeconfig() |
| 1957 |
return create_aks_dict(response) |
| 1958 |
except ResourceNotFoundError: |
| 1959 |
self.log('Did not find the AKS instance.') |
| 1960 |
return False |
| 1961 |
|
| 1962 |
def get_all_versions(self): |
| 1963 |
try: |
| 1964 |
result = dict() |
| 1965 |
response = self.containerservice_client.container_services.list_orchestrators(self.location, resource_type='managedClusters') |
| 1966 |
orchestrators = response.orchestrators |
| 1967 |
for item in orchestrators: |
| 1968 |
result[item.orchestrator_version] = [x.orchestrator_version for x in item.upgrades] if item.upgrades else [] |
| 1969 |
return result |
| 1970 |
except Exception as exc: |
| 1971 |
self.fail('Error when getting AKS supported kubernetes version list for location {0} - {1}'.format(self.location, exc.message or str(exc))) |
| 1972 |
|
| 1973 |
def get_aks_kubeconfig(self): |
| 1974 |
''' |
| 1975 |
Gets kubeconfig for the specified AKS instance. |
| 1976 |
|
| 1977 |
:return: AKS instance kubeconfig |
| 1978 |
''' |
| 1979 |
try: |
| 1980 |
access_profile = self.managedcluster_client.managed_clusters.list_cluster_user_credentials(self.resource_group, self.name) |
| 1981 |
except HttpResponseError as ec: |
| 1982 |
self.log("Lists the cluster user credentials of a managed cluster Failed, Exception as {0}".format(ec)) |
| 1983 |
return [] |
| 1984 |
return [item.value.decode('utf-8') for item in access_profile.kubeconfigs] |
| 1985 |
|
| 1986 |
def create_agent_pool_profile_instance(self, agentpoolprofile): |
| 1987 |
''' |
| 1988 |
Helper method to serialize a dict to a ManagedClusterAgentPoolProfile |
| 1989 |
:param: agentpoolprofile: dict with the parameters to setup the ManagedClusterAgentPoolProfile |
| 1990 |
:return: ManagedClusterAgentPoolProfile |
| 1991 |
''' |
| 1992 |
return self.managedcluster_models.ManagedClusterAgentPoolProfile(**agentpoolprofile) |
| 1993 |
|
| 1994 |
def create_service_principal_profile_instance(self, spnprofile): |
| 1995 |
''' |
| 1996 |
Helper method to serialize a dict to a ManagedClusterServicePrincipalProfile |
| 1997 |
:param: spnprofile: dict with the parameters to setup the ManagedClusterServicePrincipalProfile |
| 1998 |
:return: ManagedClusterServicePrincipalProfile |
| 1999 |
''' |
| 2000 |
return self.managedcluster_models.ManagedClusterServicePrincipalProfile( |
| 2001 |
client_id=spnprofile['client_id'], |
| 2002 |
secret=spnprofile['client_secret'] |
| 2003 |
) |
| 2004 |
|
| 2005 |
def create_linux_profile_instance(self, linuxprofile): |
| 2006 |
''' |
| 2007 |
Helper method to serialize a dict to a ContainerServiceLinuxProfile |
| 2008 |
:param: linuxprofile: dict with the parameters to setup the ContainerServiceLinuxProfile |
| 2009 |
:return: ContainerServiceLinuxProfile |
| 2010 |
''' |
| 2011 |
return self.managedcluster_models.ContainerServiceLinuxProfile( |
| 2012 |
admin_username=linuxprofile['admin_username'], |
| 2013 |
ssh=self.managedcluster_models.ContainerServiceSshConfiguration(public_keys=[ |
| 2014 |
self.managedcluster_models.ContainerServiceSshPublicKey(key_data=str(linuxprofile['ssh_key']))]) |
| 2015 |
) |
| 2016 |
|
| 2017 |
def create_windows_profile_instance(self, windowsprofile): |
| 2018 |
''' |
| 2019 |
Helper method to serialize a dict to a ManagedClusterWindowsProfile |
| 2020 |
:param: windowsprofile: dict with the parameters to setup the ManagedClusterWindowsProfile |
| 2021 |
:return: ManagedClusterWindowsProfile |
| 2022 |
''' |
| 2023 |
gmsa_profile = None |
| 2024 |
if windowsprofile.get('gmsa_profile'): |
| 2025 |
gmsa_profile = self.managedcluster_models.WindowsGmsaProfile(**windowsprofile.get('gmsa_profile')) |
| 2026 |
|
| 2027 |
return self.managedcluster_models.ManagedClusterWindowsProfile( |
| 2028 |
admin_username=windowsprofile['admin_username'], |
| 2029 |
admin_password=windowsprofile['admin_password'], |
| 2030 |
gmsa_profile=gmsa_profile |
| 2031 |
) |
| 2032 |
|
| 2033 |
def create_network_profile_instance(self, network): |
| 2034 |
return self.managedcluster_models.ContainerServiceNetworkProfile(**network) if network else None |
| 2035 |
|
| 2036 |
def create_api_server_access_profile_instance(self, server_access): |
| 2037 |
return self.managedcluster_models.ManagedClusterAPIServerAccessProfile(**server_access) if server_access else None |
| 2038 |
|
| 2039 |
def create_aad_profile_instance(self, aad): |
| 2040 |
return self.managedcluster_models.ManagedClusterAADProfile(**aad) if aad else None |
| 2041 |
|
| 2042 |
def create_addon_profile_instance(self, addon): |
| 2043 |
result = dict() |
| 2044 |
addon = addon or {} |
| 2045 |
for key in addon.keys(): |
| 2046 |
if not ADDONS.get(key): |
| 2047 |
self.fail('Unsupported addon {0}'.format(key)) |
| 2048 |
if addon.get(key): |
| 2049 |
name = ADDONS[key]['name'] |
| 2050 |
config_spec = ADDONS[key].get('config') or dict() |
| 2051 |
config = addon[key] |
| 2052 |
for v in config_spec.keys(): |
| 2053 |
config[config_spec[v]] = config[v] |
| 2054 |
result[name] = self.managedcluster_models.ManagedClusterAddonProfile(config=config, enabled=config['enabled']) |
| 2055 |
return result |
| 2056 |
|
| 2057 |
|
| 2058 |
def update_identity(self, param_identity, curr_identity): |
| 2059 |
user_identity = None |
| 2060 |
changed = False |
| 2061 |
current_managed_type = curr_identity.get('type', 'SystemAssigned') |
| 2062 |
current_managed_identity = curr_identity.get('user_assigned_identities', {}) |
| 2063 |
param_managed_identity = param_identity.get('user_assigned_identities') |
| 2064 |
|
| 2065 |
|
| 2066 |
if 'SystemAssigned' in param_identity.get('type') and current_managed_type == 'SystemAssigned': |
| 2067 |
pass |
| 2068 |
|
| 2069 |
elif param_identity.get('type') == 'SystemAssigned': |
| 2070 |
changed = True |
| 2071 |
|
| 2072 |
elif 'UserAssigned' in param_identity.get('type'): |
| 2073 |
if param_managed_identity not in current_managed_identity.keys(): |
| 2074 |
user_identity = {param_managed_identity: {}} |
| 2075 |
changed = True |
| 2076 |
|
| 2077 |
new_identity = self.managedcluster_models.ManagedClusterIdentity( |
| 2078 |
type=param_identity.get('type'), |
| 2079 |
) |
| 2080 |
if user_identity: |
| 2081 |
new_identity.user_assigned_identities = user_identity |
| 2082 |
|
| 2083 |
return changed, new_identity |
| 2084 |
|
| 2085 |
|
| 2086 |
def main(): |
| 2087 |
"""Main execution""" |
| 2088 |
AzureRMManagedCluster() |
| 2089 |
|
| 2090 |
|
| 2091 |
if __name__ == '__main__': |
| 2092 |
main() |