Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
export PROJECT=<customer-project>
export REGION=<vm-region>
export ZONE=`gcloud compute zones list --filter="name=${REGION}" \
                --limit 1 --uri --project=${PROJECT}| sed 's/.*\///'`
export SUBNET=<customer-vpc-subnet-name>
export NAME=<gce-vm-name>
export MYSQL_CONN=<mysql-instance-connection-name>

# Create the VM
gcloud beta compute --project=${PROJECT} instances create ${NAME} \
   --zone=${ZONE} --machine-type=g1-small --subnet=${SUBNET} \
   --no-address --metadata=startup-script="docker run -d \
   -p 0.0.0.0:5432:5432 gcr.io/cloudsql-docker/gce-proxy:1.16 /cloud_sql_proxy \
   -instances=${MYSQL_CONN}=tcp:0.0.0.0:5432" \
   --maintenance-policy=MIGRATE --scopes=https://www.googleapis.com/auth/cloud-platform \
   --image=cos-69-10895-385-0 --image-project=cos-cloud

# Get the VM internal IP
export IP=`gcloud compute instances describe ${NAME} \
    --zone ${ZONE} | grep "networkIP" | awk '{print $2}'`

# Promote the VM internal IP to static IP
gcloud compute addresses create proxy --addresses ${IP} \
    --region ${REGION} --subnet ${SUBNET}

# Note down the IP to be used in CDF MySQL or PostGreSQL JDBC 
# connection string
echo ${IP}

echo "JDBC Connection strings:"
echo "jdbc:postgresql://${IP}:5432/{PostgreSQL_DB_NAME}"
echo "jdbc:mysql://${IP}:3306/{MySQL_DB_NAME}"

Once the VM is created with a static IP, use this as the host for the mysql or postgresql database to be accessed from Cloud Data Fusion.

...