# SPDX-License-Identifier: MIT
---
- name: Verify the use of the firewall role to configure SQL Server TCP ports
  hosts: all
  vars:
    mssql_accept_microsoft_odbc_driver_17_for_sql_server_eula: true
    mssql_accept_microsoft_cli_utilities_for_sql_server_eula: true
    mssql_accept_microsoft_sql_server_standard_eula: true
    mssql_manage_firewall: true
    mssql_version: 2019
  tasks:
    - name: Test while not settings mssql_tcp_port to default it to 1433
      vars:
        __mssql_test_port: 1433
      block:
        - name: Set up SQL Server
          include_role:
            name: microsoft.sql.server
          vars:
            mssql_password: "p@55w0rD"
            mssql_edition: Evaluation

        - name: >-
            Verify that the port is configured properly {{ __mssql_test_port }}
          include_tasks: tasks/verify_tcp_port.yml
          vars:
            __mssql_tcp_port_new: "{{ __mssql_test_port }}"

    - name: Configure the mssql-server service start limit interval and burst
      include_tasks: tasks/mssql-sever-increase-start-limit.yml

    - name: Test while settings mssql_tcp_port to to 1433
      vars:
        __mssql_test_port: 1433
      block:
        - name: Set up SQL Server
          include_role:
            name: microsoft.sql.server
          vars:
            mssql_password: "p@55w0rD"
            mssql_edition: Evaluation
            mssql_tcp_port: "{{ __mssql_test_port }}"

        - name: >-
            Verify that the port is configured properly {{ __mssql_test_port }}
          include_tasks: tasks/verify_tcp_port.yml
          vars:
            __mssql_tcp_port_new: "{{ __mssql_test_port }}"

    - name: Test with mssql_tcp_port changed to 1435
      vars:
        __mssql_test_port: 1435
      block:
        - name: Set up SQL Server
          include_role:
            name: microsoft.sql.server
          vars:
            mssql_password: "p@55w0rD"
            mssql_edition: Evaluation
            mssql_tcp_port: "{{ __mssql_test_port }}"

        - name: >-
            Verify that the port is configured properly {{ __mssql_test_port }}
          include_tasks: tasks/verify_tcp_port.yml
          vars:
            __mssql_tcp_port_new: "{{ __mssql_test_port }}"
            __mssql_tcp_port_previous: 1433
