Skip to Main Content

MongoByte MongoDB Logo

Welcome to the new MongoDB Feedback Portal!

{Improvement: "Your idea"}
We’ve upgraded our system to better capture and act on your feedback.
Your feedback is meaningful and helps us build better products.

Status Submitted
Categories Atlas
Created by Guest
Created on Dec 30, 2019

Add whitelist resource with proper count support

The documentation of the terraform provider advices to create whitelist in the following way: resource "mongodbatlas_project_ip_whitelist" "test" { project_id = whitelist { cidr_block = "1.2.3.4/32" comment = "cidr block for tf acc testing" } whitelist { ip_address = "2.3.4.5" comment = "ip address for tf acc testing" } whitelist { cidr_block = "3.4.5.6/32" comment = "cidr block for tf acc testing" } whitelist { ip_address = "4.5.6.7" comment = "ip address for tf acc testing" } } In my terraform example I create a number of VMs, and each has an IP. Now I want to whitelist every IP, and they could be a variable number. I tried the approach below that kind of works, but is not really reliable... Some IPs are not whitelisted, and it goes in error at destroy time as it tries to delete IP whitelists that were never created successfully. I would Imagine there must be a better way to do this? If not, I think this is a pretty important feature to consider resource "mongodbatlas_project_ip_whitelist" "confluent" { depends_on = ["mongodbatlas_cluster.confluent"] project_id = "${mongodbatlas_cluster.confluent.project_id}" count = "${var.resource_count}" whitelist { ip_address = "${element(google_compute_address.instance.*.address, count.index)}" comment = "ip address for tf acc testing" } } (see attached .tf for completeness)
  • Attach files
  • Guest
    Dec 30, 2019
    The documentation of the terraform provider advices to create whitelist in the following way: resource "mongodbatlas_project_ip_whitelist" "test" { project_id = whitelist { cidr_block = "1.2.3.4/32" comment = "cidr block for tf acc testing" } whitelist { ip_address = "2.3.4.5" comment = "ip address for tf acc testing" } whitelist { cidr_block = "3.4.5.6/32" comment = "cidr block for tf acc testing" } whitelist { ip_address = "4.5.6.7" comment = "ip address for tf acc testing" } } In my terraform example I create a number of VMs, and each has an IP. Now I want to whitelist every IP, and they could be a variable number. I tried the approach below that kind of works, but is not really reliable... Some IPs are not whitelisted, and it goes in error at destroy time as it tries to delete IP whitelists that were never created successfully. I would Imagine there must be a better way to do this? If not, I think this is a pretty important feature to consider resource "mongodbatlas_project_ip_whitelist" "confluent" { depends_on = ["mongodbatlas_cluster.confluent"] project_id = "${mongodbatlas_cluster.confluent.project_id}" count = "${var.resource_count}" whitelist { ip_address = "${element(google_compute_address.instance.*.address, count.index)}" comment = "ip address for tf acc testing" } } (see attached .txt for completeness)