How do I add an external link in a module?
There seems to be very little information on this matter, maybe it's not that common to try to achieve something like this, but I stumbled across this thread while searching for a solution and I'd like to add my thoughts.
The comments stating that links.task.yml is for local tasks is right, but when it comes to external links, it's not that simple. As far as I know, you need routing to add links that way, and routing is for internal links, right?
So in the end I did it this way in Drupal 9:
  function my_module_menu_local_tasks_alter(&amp;$data, $route_name) {    
    $data['tabs'][0]['node.extra_tab'] = array(
      '#theme' =&gt; 'menu_local_task',
      '#link' =&gt; array(
        'title' =&gt; t('Extra tab'),
        'url' =&gt; Url::fromUri('https://theurl.com', array('attributes' =&gt; array('target' =&gt; '_blank'))),
        'localized_options' =&gt; array(
          'attributes' =&gt; array(
            'title' =&gt; t('Extra tab'),
          ),
        ),
      ),
    );
  }

You can also add something like if ($route_name == 'entity.node.canonical') to narrow it down and also if (\Drupal::routeMatch()-&gt;getParameter('node') == 'my_content_type') in case you want this to work only on certain content type(s).