Skip to content

Instantly share code, notes, and snippets.

@zuernBernhard
Last active January 18, 2024 09:20
Show Gist options
  • Select an option

  • Save zuernBernhard/73cdaf36186b69da71576d099ebb154c to your computer and use it in GitHub Desktop.

Select an option

Save zuernBernhard/73cdaf36186b69da71576d099ebb154c to your computer and use it in GitHub Desktop.
Get elasticsearch credentials for drupal on platform.sh (eg with drush core-cli)

Prerequists

Assuming that you already use the platform.sh Config-Reader with composer.json like that:

...
"require": {
  ...
  "platformsh/config-reader": "^2.4",
  ...
}
...

Retrieving Creds to elastic on platform.sh

First get a shell on the system

platform ssh
# then on the platform-instance
drush core-cli

Show / Retrieve Credentials

Then in this Shell from drush core-cli

$platformsh = new Platformsh\ConfigReader\Config();
$relationship = $platformsh->credentials('elasticsearch');

If everything works fine it leads to something like that:

[
    "username" => null,
    "fragment" => null,
    "ip" => "169.254.160.252",
    "cluster" => "oo4im7ibtndbq-pr-304-hnfhj7a",
    "host" => "elasticsearch.internal",
    "path" => null,
    "query" => [],
    "password" => null,
    "port" => 9200,
    "host_mapped" => false,
    "service" => "elasticsearch",
    "hostname" => "1234xyz.elasticsearch.service._.de-2.platformsh.site",
    "epoch" => 0,
    "instance_ips" => [
      "248.5.113.6",
    ],
    "rel" => "elasticsearch",
    "scheme" => "http",
    "type" => "elasticsearch:7.10",
    "public" => false,
  ]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment