Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow setting the region when creating a site #225

Merged
merged 4 commits into from Aug 19, 2019
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -105,6 +105,7 @@ Additional options are available to further customize the build:project:create c
| --admin-email | The email address to use for the admin |
| --ci | The CI provider to use. Defaults to "circleci" |
| --git | The git repository provider to use. Defaults to "github" |
| --region | The region to create the site in. See [the Pantheon regions documentation](https://pantheon.io/docs/regions#create-a-new-site-in-a-specific-region-using-terminus) for details. |

See `terminus help build:project:create` for more information.

Expand Down
7 changes: 6 additions & 1 deletion src/Commands/BuildToolsBase.php
Expand Up @@ -466,7 +466,7 @@ protected function resetToCommit($repositoryDir, $resetToCommit = 'HEAD^')
// TODO: if we could look up the commandfile for
// Pantheon\Terminus\Commands\Site\CreateCommand,
// then we could just call its 'create' method
public function siteCreate($site_name, $label, $upstream_id, $options = ['org' => null,])
public function siteCreate($site_name, $label, $upstream_id, $options = ['org' => null, 'region' => null,])
{
if ($this->sites()->nameIsTaken($site_name)) {
throw new TerminusException('The site name {site_name} is already taken.', compact('site_name'));
Expand All @@ -487,6 +487,11 @@ public function siteCreate($site_name, $label, $upstream_id, $options = ['org' =
$workflow_options['organization_id'] = $org->id;
}

// Add the site region.
if (!empty($region = $options['region'])) {
$workflow_options['preferred_zone'] = $region;
}

// Create the site
$this->log()->notice('Creating a new Pantheon site {name}', ['name' => $site_name]);
$workflow = $this->sites()->create($workflow_options);
Expand Down
6 changes: 4 additions & 2 deletions src/Commands/ProjectCreateCommand.php
Expand Up @@ -208,6 +208,7 @@ public function createProject(
'keep' => false,
'ci' => '',
'git' => 'github',
'region' => '',
])
{
$this->warnAboutOldPhp();
Expand All @@ -218,6 +219,7 @@ public function createProject(
$team = $options['team'];
$label = $options['label'];
$stability = $options['stability'];
$region = $options['region'];

// Provide default values for other optional variables.
if (empty($label)) {
Expand Down Expand Up @@ -295,13 +297,13 @@ function ($state) use ($ci_env, $target, $target_org, $siteDir) {
// Create a Pantheon site
->progressMessage('Create Pantheon site {site}', ['site' => $site_name])
->addCode(
function ($state) use ($site_name, $label, $team, $target, $siteDir) {
function ($state) use ($site_name, $label, $team, $target, $siteDir, $region) {
// Look up our upstream.
$upstream = $this->autodetectUpstream($siteDir);

$this->log()->notice('About to create Pantheon site {site} in {team} with upstream {upstream}', ['site' => $site_name, 'team' => $team, 'upstream' => $upstream]);

$site = $this->siteCreate($site_name, $label, $upstream, ['org' => $team]);
$site = $this->siteCreate($site_name, $label, $upstream, ['org' => $team, 'region' => $region]);

$siteInfo = $site->serialize();
$site_uuid = $siteInfo['id'];
Expand Down