def reinit_on_backend_changes(tf_bin,  # pylint: disable=too-many-arguments
                              module_path, backend_options, env_name,
                              env_region, env_vars):
    """Clean terraform directory and run init if necessary.

    If deploying a TF module to multiple regions (or any scenario requiring
    multiple backend configs), switching the backend will cause TF to
    compare the old and new backends. This will frequently cause an access
    error as the creds/role for the new backend won't always have access to
    the old one.

    This method compares the defined & initialized backend configs and
    trashes the terraform directory & re-inits if they're out of sync.
    """
    terraform_dir = os.path.join(module_path, '.terraform')
    local_tfstate_path = os.path.join(terraform_dir, 'terraform.tfstate')
    current_backend_config = {}
    desired_backend_config = {}

    LOGGER.debug('Comparing previous & desired Terraform backend configs')
    if os.path.isfile(local_tfstate_path):
        with open(local_tfstate_path, 'r') as stream:
            current_backend_config = hcl.load(stream).get('backend',
                                                          {}).get('config',
                                                                  {})

    if backend_options.get('config'):
        desired_backend_config = backend_options.get('config')
    elif os.path.isfile(os.path.join(module_path,
                                     backend_options.get('filename'))):
        with open(os.path.join(module_path,
                               backend_options.get('filename')),
                  'r') as stream:
            desired_backend_config = hcl.load(stream)

    # Can't solely rely on the backend info defined in runway options or
    # backend files; merge in the values defined in main.tf
    # (or whatever tf file)
    for filename in ['main.tf'] + glob.glob(os.path.join(module_path, '*.tf')):
        if os.path.isfile(filename):
            with open(filename, 'r') as stream:
                tf_config = hcl.load(stream)
                if tf_config.get('terraform', {}).get('backend'):
                    [(_s3key, tffile_backend_config)] = tf_config['terraform']['backend'].items()  # noqa pylint: disable=line-too-long
                    desired_backend_config = merge_dicts(
                        desired_backend_config,
                        tffile_backend_config
                    )
                    break

    if current_backend_config != desired_backend_config:
        LOGGER.info("Desired and previously initialized TF backend config is "
                    "out of sync; trashing local TF state directory %s",
                    terraform_dir)
        send2trash(terraform_dir)
        run_terraform_init(
            tf_bin=tf_bin,
            module_path=module_path,
            backend_options=backend_options,
            env_name=env_name,
            env_region=env_region,
            env_vars=env_vars
        )
Clean terraform directory and run init if necessary.

    If deploying a TF module to multiple regions (or any scenario requiring
    multiple backend configs), switching the backend will cause TF to
    compare the old and new backends. This will frequently cause an access
    error as the creds/role for the new backend won't always have access to
    the old one.

    This method compares the defined & initialized backend configs and
    trashes the terraform directory & re-inits if they're out of sync.