Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provider produced inconsistent final plan error when importing a schema into terraform state #384

Open
ismaila96 opened this issue May 13, 2024 · 2 comments

Comments

@ismaila96
Copy link

Hi,

We are facing an issue when importing a schema that is created through confluent cloud platform into terraform.

Terraform Version : latest
Confluent Provider Version : 1.74.0

Steps to reproduce the error:

  1. Create a a new schema test-import-topic in a schema registry either by creating a new one without a topic or setting a schema to an existing topic
  2. Download the created schema file test-import-topic.avsc and set it in schemas directory where the IaC terraform project is located
  3. Run the following code:

`topics = [
{
name = "test-import-topic"
partitions = 2
schema_file_name = "test-import-topic.avsc"
}
]

locals {
topics = merge({ for topic in var.topics : topic.name => topic })
}

variable "topics" {
type = any
}

resource "confluent_schema_registry_cluster" "this" {
package = data.confluent_schema_registry_region.this.package
environment {
id = confluent_environment.this.id
}
region {
id = data.confluent_schema_registry_region.this.id
}
lifecycle {
prevent_destroy = true
}
}

resource "confluent_schema" "this" {
for_each = local.topics
schema_registry_cluster {
id = confluent_schema_registry_cluster.this.id
}
rest_endpoint = confluent_schema_registry_cluster.this.rest_endpoint
subject_name = "${each.value.name}-value"
format = "AVRO"
schema = file("${var.SCHEMAS_DIRECTORY}/${each.value.schema_file_name}")
credentials {
key = confluent_api_key.schema_registry_api_key.id
secret = confluent_api_key.schema_registry_api_key.secret
}
lifecycle {
prevent_destroy = true
}
}

import {
for_each = local.topics
id = "${var.config.schema_registry.id}/${each.value.name}-value/latest"
to = confluent_schema.this[each.key]
}`

Error

Error: Provider produced inconsistent final plan │ │ When expanding the plan for confluent_schema.this["test-import-topic"] to │ include new values learned so far during apply, provider │ "registry.terraform.io/confluentinc/confluent" produced an invalid new │ value for .schema: was cty.StringVal("{\n \"doc\": \"Sample schema to │ help you get started.\",\n \"fields\": [\n {\n \"doc\": │ \"The id of the order.\",\n \"name\": \"orderId\",\n │ \"type\": \"int\"\n },\n {\n \"doc\": \"Timestamp of the │ order.\",\n \"name\": \"orderTime\",\n \"type\": \"int\"\n │ },\n {\n \"doc\": \"The address of the order.\",\n │ \"name\": \"orderAddress\",\n \"type\": \"string\"\n }\n │ ],\n \"name\": \"sampleRecord\",\n \"namespace\": │ \"com.mycorp.mynamespace\",\n \"type\": \"record\"\n}"), but now │ cty.StringVal("{\"type\":\"record\",\"name\":\"sampleRecord\",\"namespace\":\"com.mycorp.mynamespace\",\"doc\":\"Sample │ schema to help you get │ started.\",\"fields\":[{\"name\":\"orderId\",\"type\":\"int\",\"doc\":\"The │ id of the │ order.\"},{\"name\":\"orderTime\",\"type\":\"int\",\"doc\":\"Timestamp of │ the order.\"},{\"name\":\"orderAddress\",\"type\":\"string\",\"doc\":\"The │ address of the order.\"}]}"). │ │ This is a bug in the provider, which should be reported in the provider's │ own issue tracker.

@linouk23
Copy link
Collaborator

Thanks for creating the issue @ismaila96!

As a quick way to mitigate the issue, could you update test-import-topic.avsc to match its response / formatting from Get Schema API request?

We'll track the long term fix separately.

@ismaila96
Copy link
Author

Hi @linouk23

Thanks for your quick response. I have tried your suggested solution but the same error is showing up.

I have already tried the following approaches:

  • Copying the GET /schemas/ids//schema
  • Downloading the schema from confluent platform
  • Copying it manually
  • Copying the expected value that is know during terraform apply

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants