---
- name: EFS provisioning
  community.aws.efs:
    aws_access_key: "{{ communishift_efs_access_key }}"
    aws_secret_key: "{{ communishift_efs_secret_key }}"
    region: "{{ communishift_region }}"
    state: present
    name: "{{ item.value.name }}"
    tags:
      Name: "{{ item.value.name }}"
      communishift: "{{ item.value.name }}"
    targets:
      - subnet_id: "{{ communishift_subnet_id }}"
        security_groups: ["{{ communishift_security_group }}"]
  tags:
    - create_efs
  register: create_efs_filesystem_response

- name: Print the response from the AWS EFS FileSystem creation
  debug:
    msg: "{{ create_efs_filesystem_response }}"

- name: Create the EFS AccessPoint
  communishift_storage_efs:
    project_name: "{{ item.value.name }}"
    aws_access_key_id: "{{ communishift_efs_access_key }}"
    aws_secret_access_key: "{{ communishift_efs_secret_key }}"
    aws_region: "{{ communishift_region }}"
    aws_efs_filesystem_id: >-
      {{create_efs_filesystem_response['efs']['file_system_id']}}
  register: create_efs_accesspoint_response
  ignore_errors: true

- name: Print the response from the AWS EFS AccessPoint creation
  debug:
    msg: "{{ create_efs_accesspoint_response }}"

- name: Store facts
  set_fact:
    accesspoint_id: "{{create_efs_accesspoint_response['accesspoint_id']}}"
    filesystem_id: "{{create_efs_filesystem_response['efs']['file_system_id']}}"
