Creating a GCP VPC Peering Connection
There are 2 ways of creating a GCP VPC Peering connection:
-
Use the CLI (recommended)
-
Create a manual connection
Using the Hazelcast Viridian CLI
This option provides the easiest way of creating GCP VPC Peering with your Viridian Dedicated cluster.
Set Up Your Environment
-
Install the Hazelcast Viridian CLI.
-
Set the
GOOGLE_APPLICATION_CREDENTIALS
environment variable to the path of your Google Cloud credentials file.You can check further details about these credentials in the Google Cloud documentation.
Creating a Peering Connection
-
Create the peering connection.
hzcloud gcp-peering create \ --cluster-id=<YOUR CLUSTER ID> \ --project-id=<YOUR PROJECT ID> \ --network-name=<YOUR VPC NETWORK NAME>
Make sure to replace the following placeholders:
-
YOUR CLUSTER ID
with the ID of your cluster.To get your cluster ID, use the
hzcloud enterprise-cluster list
command of the Hazelcast Viridian CLI. -
YOUR PROJECT ID
with the ID of your project which contains your network on Google Cloud.For details about Google Cloud projects, see the Google Cloud documentation.
-
YOUR_VPC_NETWORK_NAME
with the Name of your VPC network on Google Cloud on your terminal.For details about Google Cloud VPC Networks, see the Google Cloud documentation.
-
-
Check for active peerings from the VPC Network Peering tab after you select your VPC on Google Cloud Platform for your side of peering.
Do not overlap the CIDR of your Viridian Dedicated cluster and the CIDR of your VPC, otherwise the connection will fail.
Creating a Manual Connection
You can still create VPC peering without using Hazelcast Viridian CLI. But, you need to handle everything it does properly. This way is more difficult but more configurable.
In order to create VPC Peering, you need to do the following:
-
Collect GCP Peering Properties for your Cluster with our API.
-
Create a GCP Peering connection from your side to our side.
-
Accept our side of the GCP Peering connection you already sent with API.
Collecting Properties
To create your side of the VPC Peering connection, you need to collect GCP Peering properties for your cluster. You can get these properties from the GraphQL API or the Go SDK
query {
gcpPeeringProperties(clusterId: "{YOUR_CLUSTER_ID}") {
projectId
networkName
}
}
client, _, _ := hazelcastcloud.New()
properties, _, _ := client.GcpPeering.GetProperties(context.Background(), &models.GetGcpPeeringPropertiesInput{
ClusterId: "YOUR_CLUSTER_ID",
},
)
fmt.Println(properties.ProjectId)
fmt.Println(properties.NetworkName)
Creating a Peering Connection
After you successfully collect peering properties, you need to create a peering connection from your VPC to the Hazelcast VPC, using values you collected from peering the properties.
Learn how to create a VPC Peering connection on Google Cloud in the Google Cloud documentation. |
Accepting a Peering Connection
After you successfully create a VPC Peering to the Viridian Dedicated cluster, you need to accept that connection, using the GraphQL API or the Go SDK:
mutation {
acceptGcpPeering(input: {
clusterId: "YOUR_CLUSTER_ID",
projectId: "YOUR_PROJECT_ID",
networkName: "YOUR_NETWORK_NAME" }){
status
}
}
client, _, _ := hazelcastcloud.New()
result, _, _ := client.GcpPeering.Accept(context.Background(), &models.AcceptGcpPeeringInput{
ClusterId: "YOUR_CLUSTER_ID",
ProjectId: "YOUR_PROJECT_ID",
NetworkName: "YOUR_NETWORK_NAME",
},
)
fmt.Println(result.Status)
Validating Peering Connections
After you see the status value as Accepted
, you can check active peerings from the Peerings tab after you select your VPC on Google Cloud Platform for your side of peering.
The CIDR of your Viridian Dedicated cluster and the CIDR of your VPC must not overlap. Otherwise you will not see peering in this list. |
Listing Peering Connections
You can list Google Cloud Platform peerings for your cluster on GCP from the Hazelcast Viridian console by going to Cluster Details > Settings > VPC Peerings one by one.
You can check where the connection is established by checking Project ID and Network Name on the list.
Also, you can use the Go SDK, Hazelcast Viridian CLI for this.
hzcloud gcp-peering list --cluster-id={YOUR_CLUSTER_ID}
client, _, _ := hazelcastcloud.New()
peerings, _, _ := client.GcpPeering.List(context.Background(), &models.ListGcpPeeringsInput{
ClusterId: "YOUR_CLUSTER_ID",
},
)
for _,peer := range *peerings {
fmt.Println(peer.Id)
fmt.Println(peer.NetworkName)
fmt.Println(peer.ProjectId)
}