0

I am experimenting with deployment manager and each time I try to deploy an SQL instance with a DB on it and 2 users; some of the tasks are failing. Most of the time they are the users:

conf.yaml:

resources:
  - name: mycloudsql
    type: gcp-types/sqladmin-v1beta4:instances
    properties:
      name: mycloudsql-01
      backendType: SECOND_GEN
      instanceType: CLOUD_SQL_INSTANCE
      databaseVersion: MYSQL_5_7
      region: europe-west6
      settings:
        tier: db-f1-micro
        locationPreference:
          zone: europe-west6-a
        activationPolicy: ALWAYS
        dataDiskSizeGb: 10

  - name: mydjangodb
    type: gcp-types/sqladmin-v1beta4:databases
    properties:
      name: django-db-01
      instance: $(ref.mycloudsql.name)
      charset: utf8

  - name: sqlroot
    type: gcp-types/sqladmin-v1beta4:users
    properties:
      name: root
      host: "%" 
      instance: $(ref.mycloudsql.name)
      password: root


  - name: sqluser
    type: gcp-types/sqladmin-v1beta4:users
    properties:
      name: user
      instance: $(ref.mycloudsql.name)
      password: user

Error:

PS C:\Users\user\Desktop\Python\GCP> gcloud --project=sound-catalyst-263911 deployment-manager deployments create dm-sql-test-11 --config conf.yaml
The fingerprint of the deployment is TZ_wYom9Q64Hno6X0bpv9g==
Waiting for create [operation-1589869946223-5a5fa71623bc9-1912fcb9-bc59aafc]...failed.
ERROR: (gcloud.deployment-manager.deployments.create) Error in Operation [operation-1589869946223-5a5fa71623bc9-1912fcb9-bc59aafc]: errors:
- code: RESOURCE_ERROR
  location: /deployments/dm-sql-test-11/resources/sqluser
  message: '{"ResourceType":"gcp-types/sqladmin-v1beta4:users","ResourceErrorCode":"400","ResourceErrorMessage":{"code":400,"message":"Precondition
    check failed.","status":"FAILED_PRECONDITION","statusMessage":"Bad Request","requestPath":"https://www.googleapis.com/sql/v1beta4/projects/sound-catalyst-263911/instances/mycloudsql-01/users","httpMethod":"POST"}}'
- code: RESOURCE_ERROR
  location: /deployments/dm-sql-test-11/resources/sqlroot
  message: '{"ResourceType":"gcp-types/sqladmin-v1beta4:users","ResourceErrorCode":"400","ResourceErrorMessage":{"code":400,"message":"Precondition
    check failed.","status":"FAILED_PRECONDITION","statusMessage":"Bad Request","requestPath":"https://www.googleapis.com/sql/v1beta4/projects/sound-catalyst-263911/instances/mycloudsql-01/users","httpMethod":"POST"}}'

Console View: enter image description here

It doesn`t say what that precondition failing is or am I missing something?

gonuladami
  • 97
  • 1
  • 13

1 Answers1

0

It seems the installation of database is not completed by the time the Deployment Manager starts to create users despite the reference notation is used in the YAML code to take care of dependencies. That is why you receive the "FAILED_PRECONDITION" error.

As a workaround you can split the deployment into two parts:

  1. Create a CloudSQL instance and a database;
  2. Create users.

This does not look elegant, but it works.

Alternatively, you can consider using Terraform. Fortunately, Cloud Shell instance is provided with Terraform pre-installed. There are sample Terraform code for Cloud SQL out there, for example this one:

CloudSQL deployment with Terraform

mebius99
  • 2,495
  • 1
  • 5
  • 9
  • Thank you for your response. I am using references to the SQL instance to make sure that that task has been completed before the others. A database was also created on this SQL instance so i think something else is going on here. – gonuladami May 20 '20 at 06:17