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

[Bug]: Provider produced inconsistent result after apply (mongodbatlas_project_ip_access_list) #2313

Closed RaniAgus closed 1 month ago

RaniAgus commented 1 month ago

Is there an existing issue for this?

Provider Version

~> 1.0

Terraform Version

v1.8.4

Terraform Edition

Terraform Open Source (OSS)

Current Behavior

I know this isn't production-ready, but I wanted to try out Terraform + MongoDB for an university project and tried to allow all IP addresses to access the project I've created in MongoDB Atlas.

It is applied correctly, however, terraform throws a "Provider produced inconsistent result after apply" error saying that the allowed IP address is an empty string.

Also tried replacing the IP value with an empty string, but it throws an "Invalid Attribute Value" error with this message: "Attribute ip_address string value must be defined as a valid IP Address., got: "

Terraform configuration to reproduce the issue

variable "mongodbatlas_public_key" {
  type = string
  nullable = false
  sensitive = true
}

variable "mongodbatlas_private_key" {
  type = string
  nullable = false
  sensitive = true
}

variable "mongodbatlas_project_name" {
  type        = string
  description = "The MongoDB Atlas Project Name"
  default     = "project"
}

variable "mongodb_allowed_ip_address" {
  type        = string
  description = "The IP Address to add to the IP Access List"
  default     = "0.0.0.0"
}

terraform {
  required_providers {
    mongodbatlas = {
      source  = "mongodb/mongodbatlas"
      version = "~> 1.0"
    }
  }
  required_version = ">= 1.0"
}

provider "mongodbatlas" {
  public_key = var.mongodbatlas_public_key
  private_key  = var.mongodbatlas_private_key
}

data "mongodbatlas_roles_org_id" "project" {
}

resource "mongodbatlas_project" "project" {
  name   = var.mongodbatlas_project_name
  org_id = data.mongodbatlas_roles_org_id.project.org_id
}

resource "mongodbatlas_project_ip_access_list" "ip" {
  project_id = mongodbatlas_project.project.id
  ip_address = var.mongodb_allowed_ip_address
  comment    = "IP Address for accessing the cluster"
}

Steps To Reproduce

  1. Run terraform apply
  2. Provide API public key and private key (could be provided using a terraform.tvars file too)
  3. Enter yes

Logs

│ Error: Provider produced inconsistent result after apply
│
│ When applying changes to mongodbatlas_project_ip_access_list.ip, provider "provider[\"registry.terraform.io/mongodb/mongodbatlas\"]" produced an unexpected new value: .ip_address:  
│ was cty.StringVal("0.0.0.0"), but now cty.StringVal("").
│
│ This is a bug in the provider, which should be reported in the provider's own issue tracker.

Code of Conduct

github-actions[bot] commented 1 month ago

Thanks for opening this issue! Please make sure you've followed our guidelines when opening the issue. In short, to help us reproduce the issue we need:

The ticket CLOUDP-251134 was created for internal tracking.

RaniAgus commented 1 month ago

Nevermind! It works after replacing:

resource "mongodbatlas_project_ip_access_list" "ip" {
  project_id = mongodbatlas_project.project.id
  ip_address = "0.0.0.0"
  comment    = "IP Address for accessing the cluster"
}

With:

resource "mongodbatlas_project_ip_access_list" "ip" {
  project_id = mongodbatlas_project.project.id
  cidr_block = "0.0.0.0/0"
  comment    = "CIDR Block for accessing the cluster"
}