mongodb / terraform-provider-mongodbatlas

Terraform MongoDB Atlas Provider: Deploy, update, and manage MongoDB Atlas infrastructure as code through HashiCorp Terraform
https://registry.terraform.io/providers/mongodb/mongodbatlas
Mozilla Public License 2.0
238 stars 167 forks source link

data source mongodbatlas_network_peering retrieves the same for id and connection_id #56

Closed ghost closed 4 years ago

ghost commented 4 years ago

Hi, I am requesting network peering from Atlas to my VPC and would like to accept it with aws_vpc_peering_connection_accepter. I tested many ways but still cannot get the pcx- identifier. Now I tried data source mongodbatlas_network_peering but it retrieves internal Atlas connection ID when I use the id and connection_id attribute of the data source.

Error: Error reading VPC Peering Connection: InvalidVpcPeeringConnectionId.Malformed: Invalid id: "5dbxxxxxxxxxxxxxxxx" (expecting "pcx-...")
    status code: 400, request id: 7a220e0c-6278-47ed-bffd-e3bbe55a85cc

I would like to get the pcx- identifier for the accepter resource but can't figure out how. I see that Atlas API doesn't return this value in the responses - can Atlas add this into the response so this could be retrieved with the data source? Or even better - refer to it as attribute of the mongodbatlas_network_peering resource?

themantissa commented 4 years ago

@Crusad once you create a container and a peer the request is made to AWS and the returned value from AWS is then contained in the connection_id returned value from mongodbatlas_network_peering. mongodbatlas_network_peering will have the pcx- value so you can use it with aws_vpc_peering_connection_accepter.

Also please do that per the README support is provided under MongoDB Atlas support agreements, Issues is for reporting bugs/issues with the provider.

themantissa commented 4 years ago

@Crusad - wanted to double check and yes, setting the following after creating both your container and peer for Atlas will auto accept on the AWS side:

  resource "aws_vpc_peering_connection_accepter" "peer" {
    vpc_peering_connection_id = "${mongodbatlas_network_peering.test.connection_id}"
    auto_accept = true
  }
ghost commented 4 years ago

Thanks, and I am sorry @themantissa - I had actually completely different problem in Terraform and it led me to believe there is something wrong with the resource. I confirm it works as desired/intended.