From 27b849d652e85138a9c2f5566f63da708904c50a Mon Sep 17 00:00:00 2001 From: "patchback[bot]" <45432694+patchback[bot]@users.noreply.github.com> Date: Fri, 3 Feb 2023 13:03:39 +0000 Subject: [PATCH] eks_cluster: adding tags to eks cluster (#1591) (#1699) [PR #1591/3c1c903a backport][stable-5] eks_cluster: adding tags to eks cluster This is a backport of PR #1591 as merged into main (3c1c903). SUMMARY As described by issue #1513 All the other community aws modules that I use support applying tags to the created resources (where such a feature is supported by aws). Using aws_eks_cluster it is not possible to add tags, although this appears to be a supported feature when viewing a cluster in the aws console. ISSUE TYPE Feature Pull Request COMPONENT NAME aws_eks_cluster ADDITIONAL INFORMATION Reviewed-by: Mark Chappell --- changelogs/fragments/1591-eks-add-tags-cluster.yml | 2 ++ plugins/modules/eks_cluster.py | 8 ++++++++ tests/integration/targets/eks_cluster/tasks/full_test.yml | 4 ++++ 3 files changed, 14 insertions(+) create mode 100644 changelogs/fragments/1591-eks-add-tags-cluster.yml diff --git a/changelogs/fragments/1591-eks-add-tags-cluster.yml b/changelogs/fragments/1591-eks-add-tags-cluster.yml new file mode 100644 index 00000000000..0801e948eb9 --- /dev/null +++ b/changelogs/fragments/1591-eks-add-tags-cluster.yml @@ -0,0 +1,2 @@ +bugfixes: + - eks_cluster - adding tags to eks cluster creation (https://github.com/ansible-collections/community.aws/pull/1591). diff --git a/plugins/modules/eks_cluster.py b/plugins/modules/eks_cluster.py index 1b8e7a866fe..18a5055e9b9 100644 --- a/plugins/modules/eks_cluster.py +++ b/plugins/modules/eks_cluster.py @@ -45,6 +45,11 @@ - present default: present type: str + tags: + description: + - A dictionary of tags to add the EKS cluster. + type: dict + version_added: 5.3.0 wait: description: >- Specifies whether the module waits until the cluster is active or deleted @@ -211,6 +216,8 @@ def ensure_present(client, module): ) if module.params['version']: params['version'] = module.params['version'] + if module.params['tags']: + params['tags'] = module.params['tags'] cluster = client.create_cluster(**params)['cluster'] except botocore.exceptions.EndpointConnectionError as e: module.fail_json(msg="Region %s is not supported by EKS" % client.meta.region_name) @@ -275,6 +282,7 @@ def main(): subnets=dict(type='list', elements='str'), security_groups=dict(type='list', elements='str'), state=dict(choices=['absent', 'present'], default='present'), + tags=dict(type='dict', required=False), wait=dict(default=False, type='bool'), wait_timeout=dict(default=1200, type='int') ) diff --git a/tests/integration/targets/eks_cluster/tasks/full_test.yml b/tests/integration/targets/eks_cluster/tasks/full_test.yml index e71fafaf32b..e3aca286386 100644 --- a/tests/integration/targets/eks_cluster/tasks/full_test.yml +++ b/tests/integration/targets/eks_cluster/tasks/full_test.yml @@ -80,6 +80,9 @@ security_groups: "{{ eks_security_groups | map(attribute='name') }}" subnets: "{{ setup_subnets.results | map(attribute='subnet.id') }}" role_arn: "{{ iam_role.arn }}" + tags: + Name: "{{ resource_prefix }}" + another: foobar register: eks_create - name: check that EKS cluster was created @@ -87,6 +90,7 @@ that: - eks_create is changed - eks_create.name == eks_cluster_name + - eks_create.tags.another == "foobar" - name: create EKS cluster with same details but wait for it to become active aws_eks_cluster: