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

Error when creating `mongodbatlas_project_ip_whitelist` resource #266

Closed kirkiris closed 4 years ago

kirkiris commented 4 years ago

Hello,

I am trying to whitelist a number of public IPs which are divided in different lists according to their use case, so each mongodbatlas_project_ip_whitelist resource is configured similarly to the following example:

resource "mongodbatlas_project_ip_whitelist" "vpn" {
  count      = "${length(var.vpn_ips)}"
  project_id = "${mongodbatlas_project.my_project.id}"
  cidr_block = "${var.vpn_ips[count.index]}"
  comment    = "Some comment"
}

resource "mongodbatlas_project_ip_whitelist" "infrastructure" {
  count      = "${length(var.infrastructure_ips)}"
  project_id = "${mongodbatlas_project.my_project.id}"
  cidr_block = "${var.infrastructure_ips[count.index]}"
  comment    = "Some comment"
}

By running terraform apply I will have all the IPs whitelisted but sometimes it ends up with an error similar to the following (it can be for a different mongodbatlas_project_ip_whitelist resource and for a different number of IPs):

Error: Error applying plan:

2 errors occurred:
    * mongodbatlas_project_ip_whitelist.vpn[12]: 1 error occurred:
    * mongodbatlas_project_ip_whitelist.vpn.12: error creating Project IP Whitelist information: couldn't find resource (21 retries)

    * mongodbatlas_project_ip_whitelist.vpn[7]: 1 error occurred:
    * mongodbatlas_project_ip_whitelist.vpn.7: error creating Project IP Whitelist information: couldn't find resource (21 retries)

I tried to delete the corresponding entries from the UI and then re-run terraform apply which gave me the following output:

Terraform will perform the following actions:

  + mongodbatlas_project_ip_whitelist.vpn[7]
      id:                 <computed>
      aws_security_group: <computed>
      cidr_block:         "x.x.x.x/32"
      comment:            "Some comment"
      ip_address:         <computed>
      project_id:         "abcdef"

  + mongodbatlas_project_ip_whitelist.vpn[12]
      id:                 <computed>
      aws_security_group: <computed>
      cidr_block:         "y.y.y.y/32"
      comment:            "Some comment"
      ip_address:         <computed>
      project_id:         "abcdef"

Plan: 2 to add, 0 to change, 0 to destroy.

Do you want to perform these actions?
  Terraform will perform the actions described above.
  Only 'yes' will be accepted to approve.

  Enter a value: yes

but still got the same error (although the IPs were, again, whitelisted):

Error: Error applying plan:

2 errors occurred:
    * mongodbatlas_project_ip_whitelist.vpn[12]: 1 error occurred:
    * mongodbatlas_project_ip_whitelist.vpn.12: error creating Project IP Whitelist information: couldn't find resource (21 retries)

    * mongodbatlas_project_ip_whitelist.vpn[7]: 1 error occurred:
    * mongodbatlas_project_ip_whitelist.vpn.7: error creating Project IP Whitelist information: couldn't find resource (21 retries)

so I ended up importing them, which worked just fine:

$ terraform import mongodbatlas_project_ip_whitelist.vpn[7] abcdef-x.x.x.x/32

$ terraform import mongodbatlas_project_ip_whitelist.vpn[12] abcdef-y.y.y.y/32

I am not sure what can possibly be going wrong and I don't seem able to reproduce this behavior as it seems to be happening occasionally. Any ideas?

Terraform: v0.11.14 MongoDB Atlas Provider: tried with 0.6.0 and 0.6.2

themantissa commented 4 years ago

@kirkiris just looking quickly please note we do not support Terraform v0.11.14 and do not test for it. We support 0.12.x. I would start with ensuring the correct version.

Second, the IP whitelist resource is one we've continually iterated on as it's a bit different in how it's implemented in the underlying Atlas API. What has helped to continually improve it is having data from transient issues, like you describe here. Do you think it would be possible to run Terraform with DEBUG logs and provide those when you hit it again? Then we can see what exactly is occurring.

themantissa commented 4 years ago

@kirkiris checking in if you tried with a newer Terraform version?

kirkiris commented 4 years ago

Thanks for checking in @themantissa. No, I haven't tried it yet. I need to change the modules plus I don't seem to be able to reproduce it.

themantissa commented 4 years ago

@kirkiris sound good - if okay I'll close this for now and if you get the same issue or have more data we can reopen. Thank you!