Skip to content

Commit

Permalink
Fix short EKS cluster names (#818)
Browse files Browse the repository at this point in the history
Fix short EKS cluster names

SUMMARY
Fixes #817
ISSUE TYPE


Bugfix Pull Request

COMPONENT NAME

aws_eks
ADDITIONAL INFORMATION

Reviewed-by: Alina Buzachis <None>
Reviewed-by: None <None>
  • Loading branch information
markuman authored Jan 5, 2022
1 parent d698409 commit bd48c16
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 9 deletions.
2 changes: 2 additions & 0 deletions changelogs/fragments/818-fix-eks-short-name.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bugfixes:
- aws_eks - Fix EKS cluster creation with short names (https://github.com/ansible-collections/community.aws/pull/818).
2 changes: 1 addition & 1 deletion plugins/modules/aws_eks_cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
46 changes: 38 additions & 8 deletions tests/integration/targets/aws_eks_cluster/tasks/full_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand All @@ -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

Expand All @@ -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
Expand All @@ -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:
Expand All @@ -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 }}"

Expand Down

0 comments on commit bd48c16

Please sign in to comment.