cloudamqp / terraform-provider-cloudamqp

Terraform Provider for CloudAMQP
https://registry.terraform.io/providers/cloudamqp/cloudamqp
Mozilla Public License 2.0
35 stars 39 forks source link

Documentation for VPC peering on Google Cloud Platform #74

Closed sig-abyreddy closed 2 years ago

sig-abyreddy commented 4 years ago

Can someone help me understand how vpc peering should be between CloudAMQP instance and Google Cloud Platform. I tried referring couple of articles but couldn't able to find exact solution. I know it is possible through UI, but i'm looking for terraform based solution.

Thanks in advance.

tbroden84 commented 4 years ago

@adityabyreddy74 There is no support yet for VPC other than through Amazon Web Services in the provider. You are also the first one requesting this feature, so it has not been prioritised. Can add a task to investigate the issue and what kind of effort is required.

sig-abyreddy commented 4 years ago

@tbroden84 Thanks for response. Currently the provider only support accepting peering requests. Ideally it should support peering request mechanism as well. UI and API already have support for that.

I figured an alternative solution for this with terraform followed by a curl request.

Terraform Script

resource "google_compute_network_peering" "peering" {
       name         = "${var.cluster_name}-cloudamqp-peering"
       network      = "projects/${var.gcp_project}/global/networks/${var.gcp_vpc_network}"
       peer_network = "projects/cloudamqp/global/networks/${element(split(".", cloudamqp_instance.instance.host), 0)}"
}

Curl Request

curl -XPOST -u :${cloudamqp_instance_api_key} https://api.cloudamqp.com/api/vpc-peering -d "peer_network_uri=projects/<your-project-id>/global/networks/<your-vpc-name>&peer_subnet=<pod-cidr-range>" -H "Content-Type: application/x-www-form-urlencoded"

To conclude, We need terraform support for the curl request part.

yashbhutwala commented 3 years ago

@tbroden84 can this item be prioritized please?

oreststetsiak commented 3 years ago

Hi @tbroden84 ! do you have any plans/estimates on when we can see this functionality? thanks!

oreststetsiak commented 3 years ago

still waiting for it ...

orlandothoeny commented 2 years ago

Would also appreciate this feature

orlandothoeny commented 2 years ago

This is what I used to configure network peering with GCP:

resource "google_compute_network_peering" "peering" {
  name                                = "cloudamqp-peering"
  network                             = var.google_vpc_id
  /* TODO: Do not hardcode CloudAMQP VPC name. Use "data.cloudamqp_vpc_info.rabbitmq.name" instead.
  There is currently a bug inside the provider. See https://github.com/cloudamqp/terraform-provider-cloudamqp/issues/131.
  //peer_network                        = "projects/cloudamqp/global/networks/${data.cloudamqp_vpc_info.rabbitmq.name}" */
  peer_network                        = "projects/cloudamqp/global/networks/MY_CLOUD_AMQP_VPC_NAME"
  export_custom_routes                = false
  import_custom_routes                = true
  export_subnet_routes_with_public_ip = false
  import_subnet_routes_with_public_ip = true
}

resource "null_resource" "cloudamqp_vpc_peering" {
  triggers = {
    cloudamqp_instance            = cloudamqp_instance.rabbitmq.id
    cloudamqp_instance_vpc_subnet = cloudamqp_instance.rabbitmq.vpc_subnet
    google_vpc_id                 = var.google_vpc_id
    google_vpc_subnet             = var.google_vpc_subnet
    google_vpc_peering_state      = google_compute_network_peering.peering.state_details
  }

  provisioner "local-exec" {
    command = "curl --location --request POST 'https://api.cloudamqp.com/api/vpc-peering' --header 'Authorization: Basic ${base64encode(cloudamqp_instance.rabbitmq.apikey)}' --header 'Content-Type: application/json' --data-raw '{\"peer_network_uri\": \"${var.google_vpc_id}\",\"peer_subnet\": \"${var.google_vpc_subnet}\"}'"
  }
}
tbroden84 commented 2 years ago

Finally come around to fix this issue. We have added a new resource dealing with the GCP VPC peering configuration. Documentatio found at: https://registry.terraform.io/providers/cloudamqp/cloudamqp/latest/docs/resources/vpc_gcp_peering

Basically configure the VPC peering from the network to which the CloudAMQP instance should connect to. Extract the network uri (var.google_vpc_id) from the VPC peering configuration and use it in the new resource to connect the VPC for the CloudAMQP instance.

Made this available in the latest release v1.15.0.