Skip to content

Commit

Permalink
eks_cluster: adding tags to eks cluster (#1591) (#1699)
Browse files Browse the repository at this point in the history
[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 <None>
  • Loading branch information
patchback[bot] authored Feb 3, 2023
1 parent 374a8ac commit 27b849d
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
2 changes: 2 additions & 0 deletions changelogs/fragments/1591-eks-add-tags-cluster.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bugfixes:
- eks_cluster - adding tags to eks cluster creation (https://github.com/ansible-collections/community.aws/pull/1591).
8 changes: 8 additions & 0 deletions plugins/modules/eks_cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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')
)
Expand Down
4 changes: 4 additions & 0 deletions tests/integration/targets/eks_cluster/tasks/full_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,17 @@
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
assert:
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:
Expand Down

0 comments on commit 27b849d

Please sign in to comment.