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
242 stars 168 forks source link

Unable to use mongodbatlas_network_peering data source #377

Closed mbrancato closed 3 years ago

mbrancato commented 3 years ago

Terraform CLI and Terraform MongoDB Atlas Provider Version

% terraform version
Terraform v0.13.5
+ provider registry.terraform.io/mongodb/mongodbatlas v0.7.0

Terraform Configuration File

data "mongodbatlas_project" "default" {
  project_id = mongodbatlas_project.integration.id
}

data "mongodbatlas_network_peering" "default" {
  peering_id = mongodbatlas_network_peering.integration.id
  project_id = data.mongodbatlas_project.default.id
}

Steps to Reproduce

Expected Behavior

read the existing peering connection

Actual Behavior

Error: error reading MongoDB Network Peering Connection (cGVlcl9pZA==:...-...==:...-...==:R0NQ): GET https://cloud.mongodb.com/api/atlas/v1.0/groups/.../peers/cGVlcl9pZA==:...-...==:...-...==:R0NQ: 400 (request "Bad Request") One or more path parameter in the request URI /api/atlas/v1.0/groups/.../peers/cGVlcl9pZA==:...-...==:...-...==:R0NQ is malformed.

(base64 encoded project info replaced with ...)

Additional Context

I'm using this in a module. The project ID and peering ID are passed via variables to the module. I've simplified the above code to avoid the module / variable step but mongodbatlas_network_peering.integration.id is passed directly into the module variable and used in the data source, etc.

References

themantissa commented 3 years ago

@mbrancato thank you for the issue - just to note that project_id is the id and not id (which is an internal id, we plan to improve this later but that, at first glance, may be the issue). @nikhil-mongo could you take a look when you have time? Thanks!

nikhil-mongo commented 3 years ago

@mbrancato Please use the below example:

data "mongodbatlas_project" "default" {
  project_id = mongodbatlas_project.integration.id
}

data "mongodbatlas_network_peering" "default" {
  peering_id = mongodbatlas_network_peering.integration.connection_id
  project_id = data.mongodbatlas_project.integration.id
}

So basically, I made two changes here. In order to reference the peering_id, connection_id is used and I made change to the project in the second data section as you used default, which I believe is not the case as I see in the first data block, it is integration. Please revert if I am wrong.

And let us know if this does not works.

Thanks.

themantissa commented 3 years ago

@mbrancato we'll assume this is okay since we haven't heard back. If not let us know.