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
241 stars 167 forks source link

Documentation incorrect about accessing connection_strings from clusters? #219

Closed mpaluchowski closed 4 years ago

mpaluchowski commented 4 years ago

The documentation for accessing connection_strings for mongodbatlas_cluster resources says I should be able to do this:

output "database_connection_string" {
  value = mongodbatlas_cluster.default.connection_strings.standard
}

but this returns an error:

Error: Unsupported attribute

  on infrastructure/atlasdb/cluster/outputs.tf line 7, in output "database_connection_string":
   7:   value = mongodbatlas_cluster.default.connection_strings.standard

This value does not have any attributes.

and it works only when I do this:

output "database_uri_template" {
  value = mongodbatlas_cluster.default.connection_strings.0.standard
}

Is this a bug in the code? Or in documentation? I'm suspecting the former, because accessing the property via a 0 index looks odd.

themantissa commented 4 years ago

I don't think it's either though we could likely make it clearer in the doc. I believe that returns a list and so the 0 is normal for specifying a value in the list. I've seen similar in other terraform outputs. @PacoDw or @coderGo93 can you confirm and if so I'll include a clarification in the docs for next release (and if not can you provide guidance)

mpaluchowski commented 4 years ago

Why would that return a list if there's only one element? Would it be possible to return a map instead and just access the keys without the extra 0 index?

marinsalinas commented 4 years ago

@mpaluchowski, the reason what we have to use this attribute as a list is due to some Terraform limitations, we cannot have a map (k/v) with non-primitive types (int, bool, string) and, since we have two non-primitive attributes (aws_private_link and aws_private_link_srv) the generic workaround is to use a list with max value = 1.

mpaluchowski commented 4 years ago

Thanks for the explanation.

Could you update the documentation to show this clearly?

themantissa commented 4 years ago

Absolutely. I'll knock out a PR to improve it. Thank you @mpaluchowski