From 2e28fe981304f997e7011ac081b960687e1d23a9 Mon Sep 17 00:00:00 2001
From: YannickEvers <112076936+YannickEvers@users.noreply.github.com>
Date: Thu, 25 Jul 2024 13:08:17 +0200
Subject: [PATCH] OPS-6704-mongodb-template-workaround (#32)
Workaround for a problem with the ionoscloud_mongo_template DataSource.
---
modules/ionos-mongodb-cluster/README.md | 2 ++
modules/ionos-mongodb-cluster/data.tf | 11 +++++++++++
modules/ionos-mongodb-cluster/main.tf | 2 +-
3 files changed, 14 insertions(+), 1 deletion(-)
diff --git a/modules/ionos-mongodb-cluster/README.md b/modules/ionos-mongodb-cluster/README.md
index 1568db0..741712c 100644
--- a/modules/ionos-mongodb-cluster/README.md
+++ b/modules/ionos-mongodb-cluster/README.md
@@ -5,6 +5,7 @@
| Name | Version |
|------|---------|
| [ionoscloud](#provider\_ionoscloud) | 6.4.18 |
+| [null](#provider\_null) | n/a |
## Modules
| Name | Source | Version |
@@ -52,4 +53,5 @@
| [ionoscloud_mongo_cluster.mongo_cluster](https://registry.terraform.io/providers/ionos-cloud/ionoscloud/6.4.18/docs/resources/mongo_cluster) | resource |
| [ionoscloud_mongo_user.initial_mongo_user](https://registry.terraform.io/providers/ionos-cloud/ionoscloud/6.4.18/docs/resources/mongo_user) | resource |
| [ionoscloud_mongo_template.mongo_template](https://registry.terraform.io/providers/ionos-cloud/ionoscloud/6.4.18/docs/data-sources/mongo_template) | data source |
+| [null_data_source.template_workaround](https://registry.terraform.io/providers/hashicorp/null/latest/docs/data-sources/data_source) | data source |
\ No newline at end of file
diff --git a/modules/ionos-mongodb-cluster/data.tf b/modules/ionos-mongodb-cluster/data.tf
index 0644a1c..e7d4cd1 100644
--- a/modules/ionos-mongodb-cluster/data.tf
+++ b/modules/ionos-mongodb-cluster/data.tf
@@ -1,4 +1,15 @@
data "ionoscloud_mongo_template" "mongo_template" {
count = var.resource_template == null ? 0 : 1
name = var.resource_template
+}
+
+# Workaround
+# There's probably a bug in the IONOS Provider: The DataSource ionoscloud_mongo_template doesn't define id
+# as computed, leading to an inconsistent final plan (id is null instead of unknown in the initial plan)
+# This null_data_source is in between and the output is unknown in the initial plan, solving the problem.
+data "null_data_source" "template_workaround" {
+ inputs = {
+ mongo_template_id = var.resource_template == null ? null : data.ionoscloud_mongo_template.mongo_template[0].id
+ }
+ depends_on = [ data.ionoscloud_mongo_template.mongo_template ]
}
\ No newline at end of file
diff --git a/modules/ionos-mongodb-cluster/main.tf b/modules/ionos-mongodb-cluster/main.tf
index 7c6e674..2182229 100644
--- a/modules/ionos-mongodb-cluster/main.tf
+++ b/modules/ionos-mongodb-cluster/main.tf
@@ -16,7 +16,7 @@ resource ionoscloud_mongo_cluster "mongo_cluster" {
cidr_list = local.cidrs
}
- template_id = var.resource_template == null ? null : data.ionoscloud_mongo_template.mongo_template[0].id
+ template_id = data.null_data_source.template_workaround.outputs["mongo_template_id"]
edition = var.resource_template == null ? "enterprise" : null
maintenance_window {