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

Fix short EKS cluster names #818

Merged
merged 6 commits into from
Jan 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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