Search code examples
google-cloud-platformgoogle-cloud-sqlgoogle-cloud-build

cloudbuild.yaml create a sql instance


Hi I am new to the GCP world and am creating my first cloudbuild.yaml file.

I haven't found an example of how to create a cloud sql instance(Postgres or MySQL), is this not supported?

it's not listed in the cloud-builders-community on GitHub.

Anything to point me in the right direction would be a big help.

I have this below and don't know if it is the correct or best way to do this:

        # # steps:
    # # # Create Cloud SQL Instance
    # # - name: gcr.io/cloud-builders/gcloud
    # #   id: 'create_cloud_sql_instance'
    # #   entrypoint: "bash"
    # #   args: 
    # #     - '-c' # pass what follows as a command to bash
    # #     - |
    # #       gcloud sql instances create $_INSTANCE_NAME --database-version=POSTGRES_11 \
    # #        --cpu=$_NUMBER_CPUS --memory=$_MEMORY_SIZE \
    # #        --region=[$_REGION] 
    # #   waitFor: ["-"]

Thanks in advance.


Solution

  • You are on the right track, but you don't need to change the entrypoint to be bash and then execute the gcloud command, as the gcr.io/cloud-builders/gcloud image already has gcloud as the entrypoint.

    Doing this works:

    steps:
    - name: 'gcr.io/cloud-builders/gcloud'
      args: ["sql", "instances", "create", "$_INSTANCE_NAME", "--database-version=POSTGRES_11", "--region=$_REGION"]
    

    Also you don't need the waitFor tag for the step either, if you are not concerned about concurrent/consecutive build steps.