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
242 stars 168 forks source link

mongodbatlas_access_list_api_key fails to import #1064

Closed SamuelMolling closed 1 year ago

SamuelMolling commented 1 year ago

Terraform CLI and Terraform MongoDB Atlas Provider Version

terragrunt version v0.42.3
Terraform v1.3.6
on darwin_arm64
+ provider registry.terraform.io/mongodb/mongodbatlas v1.8.0

Terraform Configuration File

resource "mongodbatlas_api_key" "default" {
  description   = var.description
  org_id        = "xpto"
  role_names    = var.role_names
}

resource "mongodbatlas_access_list_api_key" "default" {
  org_id        = mongodbatlas_api_key.default.org_id
  api_key_id    = mongodbatlas_api_key.default.api_key_id

  for_each      = toset(var.ip_address)
  ip_address    = each.value

  depends_on    = [mongodbatlas_api_key.default]
}
terraform {
  source = "${find_in_parent_folders("modules/mongodb-atlas-api-key")}///"
}

include {
  path = find_in_parent_folders()
}

inputs = {
    description = "test"
    role_names = ["ORG_MEMBER","ORG_READ_ONLY"]
    cidr_block = ["1.2.3.4/32", "1.2.3.5/32"]
}

Steps to Reproduce

Expected Behavior

Basically the import succeeds, but it doesn't import the ips and when I try to run apply, it says that the ip already exists

╷
│ Error: error create API key: POST https://cloud.mongodb.com/api/atlas/v1.0/orgs/xpto/apiKeys/apikeyID/accessList: 500 (request "UNEXPECTED_ERROR") Unexpected error.
│ 
│   with mongodbatlas_access_list_api_key.default["1.2.3.4/32"],
│   on main.tf line 7, in resource "mongodbatlas_access_list_api_key" "default":
│    7: resource "mongodbatlas_access_list_api_key" "default" {
│ 
╵

Actual Behavior

I try to import, the import succeeds, but it doesn't try to change the resource, just create it.

Debug Output

Attached

Additional Context

The apikey import works, but not the access list

SamuelMolling commented 1 year ago

debug.txt

martinstibbe commented 1 year ago

@SamuelMolling Was able to duplicate skipped terragrunt portion will track issue in engineering ticket INTMDB-597

SamuelMolling commented 1 year ago

I'm waiting. Thanks!

martinstibbe commented 1 year ago

@SamuelMolling I did a bit more testing and found way to import to make state file apply properly I used IP addresses to match your use of ip_address in example you provided If I include index_id [\"1.2.3.4\"] to import it will build a proper state that works on next apply without [\"1.2.3.4\"] it imports a single value and it trips over next IP Address

terraform import mongodbatlas_access_list_api_key.default[\"1.2.3.4\"] orgid-apikeyid-1.2.3.4 terraform import mongodbatlas_access_list_api_key.default[\"1.2.3.5\"] orgid-apikeyid-1.2.3.5

Zuhairahmed commented 1 year ago

closing this issue, but feel free to re-open if you need anything else here.