Generator-jhipster: GCP/GAE region mismatch between gcloud app and gcloud sql commands

Created on 16 Jul 2020  ยท  7Comments  ยท  Source: jhipster/generator-jhipster

Overview of the issue

When jhipster gae tries to generate a sql instance, it uses the region set by gcloud app, which is loaded by running

gcloud app describe --format="value(locationId) 
However, sometimes the region described in gcloud app doesn't exist in gcloud sql, and the error below occurs:
Creating New Cloud SQL Instance

Running: gcloud sql instances create "my-app" --region='europe-west' --project=my-app-12345
โœ– ERROR: (gcloud.sql.instances.create) HTTPError 400: Invalid request: Invalid value for region: europe-west.
In the case above, there's no "europe-west" region, but "europe-west1" for database regions. The list of official regions can be found in the links below: https://cloud.google.com/sql/docs/mysql/locations https://cloud.google.com/sql/docs/postgres/locations ##### **Motivation for or Use Case** Trying to deploy for the first time on gcloud gae ##### **Reproduce the error** No entities were used here, other than the default: User 1- Have a project in Europe-West (or us-central) 2- Run jhipster gae 3- Try to create a SQL instance ##### **Related issues** ##### **Suggest a Fix** I already forked the project but I was wondering which would be the best way to fix it. For example: - Should another input option be displayed so the user can choose the region for his/her database server? or - Should we append "1" if the region doesn't end with a number? eg.: europe-west or us-central (so far they are the only exceptions I found, but just had a quick look) ##### **JHipster Version(s)**
[email protected] /Users/lrafaeli/dev/projects/monu-admin
โ””โ”€โ”ฌ [email protected]
  โ””โ”€โ”€ [email protected] 

##### **JHipster configuration, a `.yo-rc.json` file generated in the root folder**
.yo-rc.json file
{
  "generator-jhipster": {
    "promptValues": {
      "packageName": "one.monu.admin",
      "nativeLanguage": "en"
    },
    "jhipsterVersion": "6.9.1",
    "applicationType": "monolith",
    "baseName": "MonuAdmin",
    "packageName": "one.monu.admin",
    "packageFolder": "one/monu/admin",
    "serverPort": "8080",
    "authenticationType": "session",
    "cacheProvider": "no",
    "websocket": false,
    "databaseType": "sql",
    "devDatabaseType": "mysql",
    "prodDatabaseType": "mysql",
    "searchEngine": false,
    "messageBroker": false,
    "serviceDiscoveryType": false,
    "buildTool": "maven",
    "enableSwaggerCodegen": false,
    "rememberMeKey": "YourJWTSecretKeyWasReplacedByThisMeaninglessTextByTheJHipsterInfoCommandForObviousSecurityReasons",
    "embeddableLaunchScript": false,
    "useSass": true,
    "clientPackageManager": "npm",
    "clientFramework": "vue",
    "clientTheme": "united",
    "clientThemeVariant": "primary",
    "creationTimestamp": 1593260724640,
    "testFrameworks": [],
    "jhiPrefix": "jhi",
    "entitySuffix": "",
    "dtoSuffix": "DTO",
    "otherModules": [
      {
        "name": "generator-jhipster-vuejs",
        "version": "1.8.2"
      },
      {
        "name": "generator-jhipster-kotlin",
        "version": "1.8.1"
      }
    ],
    "enableTranslation": true,
    "nativeLanguage": "en",
    "languages": ["en"],
    "blueprints": [
      {
        "name": "generator-jhipster-vuejs",
        "version": "1.8.2"
      },
      {
        "name": "generator-jhipster-kotlin",
        "version": "1.8.1"
      }
    ],
    "gcpProjectId": "menu-service-276215",
    "gcpCloudSqlInstanceName": "",
    "gcpCloudSqlUserName": "admin",
    "gcpCloudSqlDatabaseName": "MonuAdmin",
    "gaeServiceName": "monu-admin",
    "gaeLocation": "europe-west",
    "gaeInstanceClass": "B2",
    "gaeScalingType": "manual",
    "gaeCloudSQLInstanceNeeded": "Y",
    "gaeInstances": "1"
  }
}

JDL for the Entity configuration(s) entityName.json files generated in the .jhipster directory


JDL entity definitions


Environment and Tools

java version "1.8.0_201"
Java(TM) SE Runtime Environment (build 1.8.0_201-b09)
Java HotSpot(TM) 64-Bit Server VM (build 25.201-b09, mixed mode)

git version 2.24.3 (Apple Git-128)

node: v12.18.2

npm: 6.14.5

Docker version 19.03.8, build afacb8b

docker-compose version 1.25.4, build 8d51620a

Entity configuration(s) entityName.json files generated in the .jhipster directory
Browsers and Operating System

  • [ ] Checking this box is mandatory (this is just to show you read everything)
area gae

Most helpful comment

@SudharakaP your PR will not fix the problem. It will fix the gcloud sql create error but will generate an error when gcloud app create is executed
see, the name of the app engine regions are different from sql ones. app create accepts "europe-west" but sql create doesn't, it will accept only "europe-west1".
my suggestion is to use the the up-to-date, current region list provided by gcloud app engine which can be retrieve by running gcloud app regions list
the result of this list should be the options to be displayed when selecting the region it should be deployed.
This way, there's no need to create a PR every time a new region is added/renamed.

All 7 comments

@leozin : Thanks for reporting this. I think we need a separate prompt for CloudSQL regions. Let me add that soon. :smile:

It seems that this was caused by outdated app engine locations. Some of the location values were renamed I think, and I've updated and also added the new app engine locations found in; https://cloud.google.com/appengine/pricing

@SudharakaP your PR will not fix the problem. It will fix the gcloud sql create error but will generate an error when gcloud app create is executed
see, the name of the app engine regions are different from sql ones. app create accepts "europe-west" but sql create doesn't, it will accept only "europe-west1".
my suggestion is to use the the up-to-date, current region list provided by gcloud app engine which can be retrieve by running gcloud app regions list
the result of this list should be the options to be displayed when selecting the region it should be deployed.
This way, there's no need to create a PR every time a new region is added/renamed.

@leozin : Thanks for pointing it out. Yes, you are correct there's some difference between the naming of the sql regions and the app regions. I initially thought they updated both, but it seems that the app regions still have names such as europe-west whereas the corresponding sql region is europe-west1.

I am not sure about using gcloud app regions list as it only gives the tags for the regions not the actual names as we have now (like Tokyo, Toronto etc). Another problem is that gcloud sql doesn't seem to have a list command for regions; so I think we will have to use a manual listing method as we do now for sql regions anyways. I am thinking to include a separate prompt for sql regions now since that way users can mix and match regions for their app and db as well; in case that's something they want. :thinking: :thinking:

I've cross checked the app locations and cloud sql locations and it seems this discrepancy is only there for europe-west1 and us-central1. So I've added some logic to correct that when we create cloud sql. I don't know if this is the optimal solution for this. Maybe if you have a better suggestion feel free to let me know. :smile:

@SudharakaP I was going to suggest a check to see if the region doesn't end with a number (and append 1) but by checking your PR, I think your code change is the safest.
Thanks for the fix, and thanks for the good work ๐Ÿ‘

@SudharakaP I was going to suggest a check to see if the region doesn't end with a number (and append 1) but by checking your PR, I think your code change is the safest.
Thanks for the fix, and thanks for the good work +1

You are welcome :+1:

Was this page helpful?
0 / 5 - 0 ratings

Related issues

pascalgrimaud picture pascalgrimaud  ยท  3Comments

edvjacek picture edvjacek  ยท  3Comments

lsadehaan picture lsadehaan  ยท  3Comments

chegola picture chegola  ยท  4Comments

marcelinobadin picture marcelinobadin  ยท  3Comments