Skip to content

Commit

Permalink
Allow setting the region when creating a site (#225)
Browse files Browse the repository at this point in the history
  • Loading branch information
erichomanchuk authored and ataylorme committed Aug 19, 2019
1 parent c58f0b7 commit 5750782
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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

0 comments on commit 5750782

Please sign in to comment.