From bd48c1646d1ef86c1d5493e5af2d836c946b4c88 Mon Sep 17 00:00:00 2001 From: Markus Bergholz Date: Wed, 5 Jan 2022 11:01:34 +0100 Subject: [PATCH] Fix short EKS cluster names (#818) Fix short EKS cluster names SUMMARY Fixes #817 ISSUE TYPE Bugfix Pull Request COMPONENT NAME aws_eks ADDITIONAL INFORMATION Reviewed-by: Alina Buzachis Reviewed-by: None --- .../fragments/818-fix-eks-short-name.yml | 2 + plugins/modules/aws_eks_cluster.py | 2 +- .../targets/aws_eks_cluster/defaults/main.yml | 1 + .../aws_eks_cluster/tasks/full_test.yml | 46 +++++++++++++++---- 4 files changed, 42 insertions(+), 9 deletions(-) create mode 100644 changelogs/fragments/818-fix-eks-short-name.yml diff --git a/changelogs/fragments/818-fix-eks-short-name.yml b/changelogs/fragments/818-fix-eks-short-name.yml new file mode 100644 index 00000000000..509519946dd --- /dev/null +++ b/changelogs/fragments/818-fix-eks-short-name.yml @@ -0,0 +1,2 @@ +bugfixes: +- aws_eks - Fix EKS cluster creation with short names (https://github.com/ansible-collections/community.aws/pull/818). \ No newline at end of file diff --git a/plugins/modules/aws_eks_cluster.py b/plugins/modules/aws_eks_cluster.py index 64627377c41..895758f0cf5 100644 --- a/plugins/modules/aws_eks_cluster.py +++ b/plugins/modules/aws_eks_cluster.py @@ -204,7 +204,7 @@ def ensure_present(client, module): resourcesVpcConfig=dict( subnetIds=subnets, securityGroupIds=groups), - clientRequestToken='ansible-create-%s' % name) + ) if module.params['version']: params['version'] = module.params['version'] cluster = client.create_cluster(**params)['cluster'] diff --git a/tests/integration/targets/aws_eks_cluster/defaults/main.yml b/tests/integration/targets/aws_eks_cluster/defaults/main.yml index 214f249611b..a7f6a40c606 100644 --- a/tests/integration/targets/aws_eks_cluster/defaults/main.yml +++ b/tests/integration/targets/aws_eks_cluster/defaults/main.yml @@ -1,4 +1,5 @@ eks_cluster_name: "{{ resource_prefix }}" +eks_cluster_short_name: "{{ lookup('password', '/dev/null chars=ascii_lowercase length=5') }}" eks_subnets: - zone: a cidr: 10.0.1.0/24 diff --git a/tests/integration/targets/aws_eks_cluster/tasks/full_test.yml b/tests/integration/targets/aws_eks_cluster/tasks/full_test.yml index 7906b49cba5..e71fafaf32b 100644 --- a/tests/integration/targets/aws_eks_cluster/tasks/full_test.yml +++ b/tests/integration/targets/aws_eks_cluster/tasks/full_test.yml @@ -77,8 +77,8 @@ - name: create EKS cluster aws_eks_cluster: name: "{{ eks_cluster_name }}" - security_groups: "{{ eks_security_groups | community.general.json_query('[].name') }}" - subnets: "{{ setup_subnets.results | community.general.json_query('[].subnet.id') }}" + security_groups: "{{ eks_security_groups | map(attribute='name') }}" + subnets: "{{ setup_subnets.results | map(attribute='subnet.id') }}" role_arn: "{{ iam_role.arn }}" register: eks_create @@ -91,8 +91,8 @@ - name: create EKS cluster with same details but wait for it to become active aws_eks_cluster: name: "{{ eks_cluster_name }}" - security_groups: "{{ eks_security_groups | community.general.json_query('[].name') }}" - subnets: "{{ setup_subnets.results | community.general.json_query('[].subnet.id') }}" + security_groups: "{{ eks_security_groups | map(attribute='name') }}" + subnets: "{{ setup_subnets.results | map(attribute='subnet.id') }}" role_arn: "{{ iam_role.arn }}" wait: yes register: eks_create @@ -111,8 +111,8 @@ - name: create EKS cluster with same details but using SG ids aws_eks_cluster: name: "{{ eks_cluster_name }}" - security_groups: "{{ setup_security_groups.results | community.general.json_query('[].group_id') }}" - subnets: "{{ setup_subnets.results | community.general.json_query('[].subnet.id') }}" + security_groups: "{{ setup_security_groups.results | map(attribute='group_id') }}" + subnets: "{{ setup_subnets.results | map(attribute='subnet.id') }}" role_arn: "{{ iam_role.arn }}" register: eks_create @@ -137,8 +137,8 @@ - name: create EKS cluster with same details but wait for it to become active aws_eks_cluster: name: "{{ eks_cluster_name }}" - security_groups: "{{ eks_security_groups | community.general.json_query('[].name') }}" - subnets: "{{ setup_subnets.results | community.general.json_query('[].subnet.id') }}" + security_groups: "{{ eks_security_groups | map(attribute='name') }}" + subnets: "{{ setup_subnets.results | map(attribute='subnet.id') }}" role_arn: "{{ iam_role.arn }}" wait: yes register: eks_create @@ -160,6 +160,28 @@ that: - eks_delete is changed + - name: create EKS cluster with short name + aws_eks_cluster: + name: "{{ eks_cluster_short_name }}" + security_groups: "{{ eks_security_groups | map(attribute='name') }}" + subnets: "{{ setup_subnets.results | map(attribute='subnet.id') }}" + role_arn: "{{ iam_role.arn }}" + register: eks_create + + - name: check that EKS cluster was created with short name + assert: + that: + - eks_create is changed + - eks_create.name == eks_cluster_short_name + - eks_create is not failed + + - name: remove EKS cluster with short name + aws_eks_cluster: + name: "{{ eks_cluster_short_name }}" + state: absent + wait: yes + register: eks_delete + always: - name: Announce teardown start debug: @@ -173,6 +195,14 @@ register: eks_delete ignore_errors: yes + - name: remove EKS cluster + aws_eks_cluster: + name: "{{ eks_cluster_short_name }}" + state: absent + wait: yes + register: eks_delete + ignore_errors: yes + - debug: msg: "{{ eks_security_groups|reverse|list }}"