Skip to content

Support safe handling of shared project IP access list entries in Terraform (prevent deletes when the same IP is used by multiple services). #3689

@kandula229-rgb

Description

@kandula229-rgb

Is there an existing issue for this?

  • I have searched the existing issues

Provider Version

1.40.0

Terraform Version

1.8.5

Terraform Edition

Terraform Open Source (OSS)

Current Behavior

Description:
We are facing an issue managing project-level IP access lists in MongoDB Atlas when multiple services/profiles share the same IP address.

Scenario:

One Atlas Project.

Service is deployed with different cluster profiles (e.g., integration, testing).

Each profile’s Terraform stack provisions:

An Atlas cluster (mongodbatlasadvancedcluster)

A backup schedule (mongodbatlascloudbackup_schedule)

A project IP access list entry (mongodbatlasprojectipaccesslist) using the same IP address.

Behavior Observed:

Integration profile deployment:

Creates cluster, backup, and adds Gateway IP to the project access list.

Testing profile deployment (same service, different profile):

Creates a second cluster and backup.

Attempts to add the same Gateway IP.

Atlas API accepts it (idempotent) → no duplicate error, but no new entry is created either.

Terraform state for the testing profile still assumes ownership of that IP entry.

Delete testing profile:

Destroys cluster and backup.

Also deletes the Gateway IP from the Atlas project (because state thinks it owns it).

Result: the integration profile’s cluster loses access, since the shared IP entry is gone.

Problem:

mongodbatlasprojectipaccesslist does not support safe handling of shared IPs across multiple Terraform states.

Unlike AWS Security Group rules (which have unique IDs per rule, making deletes safe), Atlas identifies IPs only by the IP address string.

This creates a state ownership conflict: one stack can remove IPs required by another.

Terraform configuration to reproduce the issue

resource "mongodbatlas_project_ip_access_list" "this" {
  for_each = toset(local.GatewayIPs)
  project_id = "projectID"
  ip_address = each.value
  comment    = "Allow connection to cluster"

}

Steps To Reproduce

Try to create same project_ip_access_list IP with 2 terraform states, only one resource will be created.
Both will point to same Ip entry in atlas
delete one, so it deletes the entry. for other service we will get connection issue

Logs

Code of Conduct

  • I agree to follow this project's Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions