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

Option in azure_rm_aks to set tags for agent_pool_profiles #1713

Closed
Ezopek opened this issue Sep 13, 2024 · 10 comments · Fixed by #1718
Closed

Option in azure_rm_aks to set tags for agent_pool_profiles #1713

Ezopek opened this issue Sep 13, 2024 · 10 comments · Fixed by #1718
Labels
hold The problem holds for a particular reason medium_priority Medium priority question Further information is requested work in In trying to solve, or in working with contributors

Comments

@Ezopek
Copy link

Ezopek commented Sep 13, 2024

SUMMARY

Add option for agent_pools vmss to inherits tags from main azure_rm_aks object.

ISSUE TYPE
  • Feature Idea
COMPONENT NAME

azure_rm_aks

ADDITIONAL INFORMATION

Hi, my company requires that every object created in Azure should have specific tags when we deploy it. And right now, when I try create AKS using azure_rm_aks it ultimately fails with ResourceOperationFailure -> RequestDisallowedByPolicy and message requesting adding required tags on resource aks-master-69745823-vmss.
Other objects created by AKS (like new Resource Group or Load Balancer) do inherit those tags, but for some reason, azure_rm_aks tries to create agent_pools VMSS without providing them.

vars/main.yml:

az_default_tags:
  env: "{{ env }}"
  created-date: "{{ '%Y-%m-%d' | strftime }}"
  iac: ansible

aks_system_pools:
  - name: master
    enable_auto_scaling: false
    count: 1
    mode: System
    vm_size: Standard_B2s
    node_labels:
      master: ""
    os_type: Linux
    type: VirtualMachineScaleSets
    availability_zones:
      - 1
      - 2
      - 3
    vnet_subnet_id: "{{ subnets_4_id }}"

task/main.yml:

- name: Create AKS
  environment:
    HTTP_PROXY: "{{ http_proxy }}"
    HTTPS_PROXY: "{{ https_proxy }}"
    NO_PROXY: "{{ no_proxy }}"
    AZURE_SUBSCRIPTION_ID: "{{ az_subscription_id }}"
    AZURE_CLIENT_ID: "{{ az_client_id }}"
    AZURE_SECRET: "{{ az_client_secret }}"
    AZURE_TENANT: "{{ az_tenant_id }}"
  azure_rm_aks:
    name: "{{ aks_name }}"
    location: "{{ location }}"
    resource_group: "{{ resource_group }}"
    dns_prefix: "{{ aks_name }}"
    kubernetes_version: "{{ aks_version }}"
    linux_profile:
      admin_username: "{{ aks_host_admin_username }}"
      ssh_key: "{{ aks_ssh_key_public }}"
    agent_pool_profiles: "{{ aks_system_pools }}"
    enable_rbac: true
    tags: "{{ az_default_tags }}"

With configuration like that I get following error:

TASK [az-create-aks : Create AKS] ***************************************************************************************************************************************************************************
fatal: [localhost]: FAILED! => changed=false
  msg: |-
    Error creating the AKS instance: (RequestDisallowedByPolicy) Code="RequestDisallowedByPolicy" Message="Resource 'aks-master-69745823-vmss' was disallowed by policy. Reasons: 'Please add tag 'created-date' on resource with YYYY-MM-DD format','Please add tag 'created-date' on resource with  YYYY-MM-DD format','Please add tag 'iac' on resource'. See error details for policy resource IDs." Target="aks-master-69745823-vmss" [...]
@Ezopek Ezopek changed the title Option for azure_rm_aks agent_pools vmss inherit to tags Option for azure_rm_aks agent_pools vmss to inherit tags Sep 13, 2024
@Fred-sun
Copy link
Collaborator

@Ezopek Thank you for submitting the problem, but I can manage the AKS resource in your way, and the resource was created successfully. But from your error, is your error because the policy does not allow your subscription to manage this resource? Thank you!

@Fred-sun Fred-sun added question Further information is requested medium_priority Medium priority work in In trying to solve, or in working with contributors labels Sep 14, 2024
@Ezopek
Copy link
Author

Ezopek commented Sep 14, 2024

@Fred-sun AKS resource itself is created, but with failed agent(s)_pool. The error I posted is targeted on deployment of VMSS (VirtualMachineScaleSets) for the agent_pool - my company doesn't allow creating that resource since it doesn't have required custom tags.

So yea, as a workaround I could just handle this specific error and create needed agent_pools later with azure_rm_aksagentpool with those tags. But it would be nice-to-have to do that with just azure_rm_aks without errors since the option is there (and it needs atleast one system agent_pool).

To speak more plainly - I would like the VirtualMachineScaleSets created by azure_rm_aks for agent_pools to have the tags that we provide in the properties of azure_rm_aks, as at the moment they seem to be created without them.
It is possible to do so via Azure GUI:
image

@Fred-sun
Copy link
Collaborator

@Ezopek Currently the SDK does not support defining tags in this way, so it is not possible to do so for the time being. Thank you!

@Fred-sun Fred-sun added the hold The problem holds for a particular reason label Sep 14, 2024
@Ezopek
Copy link
Author

Ezopek commented Sep 14, 2024

@Ezopek
Copy link
Author

Ezopek commented Sep 14, 2024

Actually after some thought I might have overcomplicate this issue a little.
All that I actually want to achieve is to be able to set tags on agent_pool_profiles like that:

- name: Create AKS
  azure_rm_aks:
    name: "{{ aks_name }}"
    location: "{{ location }}"
    resource_group: "{{ resource_group }}"
    # [...]
    agent_pool_profiles:
      - name: master
        mode: System
        vm_size: Standard_B2s
        type: VirtualMachineScaleSets
        # [...]
        tags: # <-- this right now is not possible in ansible azure_rm_aks, yet it is via REST API, Terraform azurerm provider or Python Azure SDK
          some: custom
          tags: aks
    tags:
      some: custom
      tags: aks

Sorry for all the confusion with "inheriting" stuff... At first I thought simply of copying tags from main azure_rm_aks properties to agent_pool_profiles, but simply being able to set them manually will be well and enough

@Ezopek Ezopek changed the title Option for azure_rm_aks agent_pools vmss to inherit tags Option in azure_rm_aks to set tags for agent_pool_profiles Sep 14, 2024
@Ezopek
Copy link
Author

Ezopek commented Sep 18, 2024

@Fred-sun can you look at it once again and verify 'hold' label - there are available features for agent-pools tags in Azure Python SDK - #1713 (comment)

@Fred-sun
Copy link
Collaborator

@Ezopek You mean to add tags to the parameter 'agent_pool_profiles', right?

@Fred-sun

This comment was marked as resolved.

@Fred-sun
Copy link
Collaborator

@Ezopek What you're asking for is something like #1713, add tags to agent_pools ?

@Ezopek
Copy link
Author

Ezopek commented Sep 20, 2024

@Fred-sun @xuzhang3 Sorry I was out-of-office. Yes, exactly. Again sorry for all the misunderstanding and overcomplicating and thank you very much for cooperation and quick change!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hold The problem holds for a particular reason medium_priority Medium priority question Further information is requested work in In trying to solve, or in working with contributors
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants