#!/bin/sh -x
# Copyright 2022 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

echo "Creating Private Connection"

connection_name="${1}"
location="${2}"
project_id="${3}"
vmware_network="${4}"
description="${5}"
routing_mode="${6}"
service_project="${7}"
connection_type="${8}"

gcloud vmware private-connections create ${connection_name} --location=${location} --project=${project_id}  --vmware-engine-network=${vmware_network} --description=${description} --routing-mode=${routing_mode} --service-project=${service_project} --type=${connection_type}

retVal=$?
if [ $retVal -ne 0 ]; then
    echo "Error occured while creating private connection ${connection_name}"
    exit 1
else
    echo "Private Connection ${connection_name} successfully created"
fi