Skip to content

Commit

Permalink
terraform_data resource only shifts the problem, use null_data_source…
Browse files Browse the repository at this point in the history
… instead
  • Loading branch information
YannickEvers committed Jul 18, 2024
1 parent 1f6d436 commit 3ef5507
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
11 changes: 11 additions & 0 deletions modules/ionos-mongodb-cluster/data.tf
Original file line number Diff line number Diff line change
@@ -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 ]
}
11 changes: 1 addition & 10 deletions modules/ionos-mongodb-cluster/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ resource ionoscloud_mongo_cluster "mongo_cluster" {
cidr_list = local.cidrs
}

template_id = terraform_data.template_id_workaround.output
template_id = data.null_data_source.template_workaround.outputs["mongo_template_id"]
edition = var.resource_template == null ? "enterprise" : null

maintenance_window {
Expand All @@ -25,15 +25,6 @@ resource ionoscloud_mongo_cluster "mongo_cluster" {
}
}

# 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 resource is in between and the output is unknown in the initial plan, solving the problem.
resource "terraform_data" "template_id_workaround" {
input = var.resource_template == null ? null : data.ionoscloud_mongo_template.mongo_template[0].id
depends_on = [ data.ionoscloud_mongo_template.mongo_template ]
}

resource "ionoscloud_mongo_user" "initial_mongo_user" {
for_each = var.users
cluster_id = ionoscloud_mongo_cluster.mongo_cluster.id
Expand Down

0 comments on commit 3ef5507

Please sign in to comment.