ionos-cloud/terraform-provider-ionoscloud

[bug]: terraform apply crashing when attempting to create mongo db cluster

grieshaber opened this issue · 4 comments

Description

When trying to create a MongoDB Cluster in our Subcontract, the terraform apply steps fails with the following message

ionoscloud_mongo_cluster.mongodb_cluster: Creating...
╷
│ Error: Provider produced inconsistent result after apply
│
│ When applying changes to ionoscloud_mongo_cluster.mongodb_cluster, provider "provider[\"registry.terraform.io/ionos-cloud/ionoscloud\"]" produced an unexpected new value: Root resource was present, but now absent.
│
│ This is a bug in the provider, which should be reported in the provider's own issue tracker.

Expected behavior

Expected a MongoDB Cluster to be created

Environment

Terraform version:

v1.3.9

Provider version:

v6.3.5...

OS:

macOS (local test), ubuntu (CI)

Configuration Files

Minimal reproducible tf-setup:

# mongo.tf
locals {
  datacenter_id = "e58b36bf-5981-475e-9097-64e6c01b504c"
}

resource "ionoscloud_lan" "mongodb_lan" {
  datacenter_id = local.datacenter_id
  public        = false
  name          = "mongodb-lan"
}

resource "ionoscloud_mongo_cluster" "mongodb_cluster" {
  maintenance_window {
    day_of_the_week = "Sunday"
    time            = "09:00:00"
  }

  mongodb_version = "6.0"
  instances       = 1
  display_name    = "test-mongodb"
  location        = "de/txl"
  connections {
    datacenter_id = local.datacenter_id
    lan_id        = ionoscloud_lan.mongodb_lan.id
    cidr_list     = ["10.7.222.4/24"]
  }
  # template_id = data.ionoscloud_mongo_template.template.id
  template_id = "6b78ea06-ee0e-4689-998c-fc9c46e781f6"
  credentials {
    username = "mongodb-user"
    password = random_password.cluster_password.result
  }
}

resource "random_password" "cluster_password" {
  length           = 16
  special          = true
  override_special = "!#$%&*()-_=+[]{}<>:?"
}

# terraform.tf
terraform {
  required_version = "~> 1.0"

  required_providers {
    ionoscloud = {
      source  = "ionos-cloud/ionoscloud"
      version = "~> 6.1"
    }
  }
}

provider "ionoscloud" {
  endpoint = "https://api.ionos.com/cloudapi/v6/" 
}

How to Reproduce

Run tf apply on the sources provided above.

Error and Debug Output

# tf apply with debug logs
ionoscloud_mongo_cluster.mongodb_cluster: Creating...
2023-02-24T16:08:37.090+0100 [INFO]  Starting apply for ionoscloud_mongo_cluster.mongodb_cluster
2023-02-24T16:08:37.090+0100 [DEBUG] ionoscloud_mongo_cluster.mongodb_cluster: applying the planned Create change
2023-02-24T16:08:37.213+0100 [INFO]  provider.terraform-provider-ionoscloud_v6.3.5: 2023/02/24 16:08:37 [DEBUG] operation : ClustersPost: timestamp=2023-02-24T16:08:37.213+0100
2023-02-24T16:08:37.213+0100 [INFO]  provider.terraform-provider-ionoscloud_v6.3.5: 2023/02/24 16:08:37 [DEBUG] response status code : 404: timestamp=2023-02-24T16:08:37.213+0100
2023-02-24T16:08:37.222+0100 [ERROR] vertex "ionoscloud_mongo_cluster.mongodb_cluster" error: Provider produced inconsistent result after apply
╷
│ Error: Provider produced inconsistent result after apply
│
│ When applying changes to ionoscloud_mongo_cluster.mongodb_cluster, provider "provider[\"registry.terraform.io/ionos-cloud/ionoscloud\"]" produced an unexpected new value: Root resource was present, but now absent.
│
│ This is a bug in the provider, which should be reported in the provider's own issue tracker.
╵
2023-02-24T16:08:37.229+0100 [DEBUG] provider.stdio: received EOF, stopping recv loop: err="rpc error: code = Unavailable desc = error reading from server: EOF"

Additional Notes

Additionally, how do we effectively get the information about the subnet, that is assigned to us by the IONOS DHCP server?

The documentation states, that one should check the NICs assigned IP - but, in our case, there is no separete nic "upfront".

I managed to create a MongoDB with the exact same settings via the dcd to validate our properties.

Hello, I will take a look and came up with a response as soon as possible. Thanks for reporting us this bug

Hi, please remove the endpoint configuration and try again:
provider "ionoscloud" { endpoint = "https://api.ionos.com/cloudapi/v6/" }
This is the /v6 - Compute endpoint, but you're also trying to reach the DBaaS mongo endpoint, which is https://api.ionos.com/databases/mongodb/clusters. You don't actually need to define an endpoint, the SDK will know how to route the request.

We will add a better error message for the scenario.

Thanks - i'll try immediately! :)

i can confirm @cristiGuranIonos, that i could create the db now successfully. Thanks for your help!