confluentinc / terraform-provider-confluent

Terraform Provider for Confluent
Apache License 2.0
118 stars 61 forks source link

Error: error fetching Kafka Cluster "lkc-xxxxxx"'s "rest_endpoint" attribute: error reading Kafka Cluster "lkc-xxxxx": 404 Not Found: Resource Not Found #364

Closed syydsohail closed 4 months ago

syydsohail commented 4 months ago

Hi Team,

I am trying to create Kafka API Key using terraform, getting following error.

_" Error: error fetching Kafka Cluster "lkc-xxxxxx"'s "restendpoint" attribute: error reading Kafka Cluster "lkc-xxxxx": 404 Not Found: Resource Not Found "

The confluent cloud cluster is up and running. Please find the below main.tf

_terraform { required_providers { confluent = { source = "confluentinc/confluent" version = "1.61.0" } } }

provider "confluent" { cloud_api_key = var.confluent_cloud_api_key cloud_api_secret = var.confluent_cloud_api_secret }

data "confluent_kafka_cluster" "standard" { id = var.kafkaid environment { id = var.environmentid } }

resource "confluent_service_account" "kafka-manager312" { display_name = "kafka-manager312" description = "Service account to for --- customer/TLA" }

resource "confluent_kafka_topic" "orders" { kafka_cluster { id = data.confluent_kafka_cluster.standard.id } topic_name = "orders" rest_endpoint = data.confluent_kafka_cluster.standard.rest_endpoint credentials { key = confluent_api_key.kafka-manager312-kafka-api-key.id secret = confluent_api_key.kafka-manager312-kafka-api-key.secret } }

resource "confluent_api_key" "kafka-manager312-kafka-api-key" { display_name = "kafka-manager312-kafka-api-key" description = "Kafka API Key that is owned by 'kafka-manager' service account" owner { id = confluent_service_account.kafka-manager312.id api_version = confluent_service_account.kafka-manager312.api_version kind = confluent_service_account.kafka-manager312.kind }

managed_resource { id = data.confluent_kafka_cluster.standard.id api_version = data.confluent_kafka_cluster.standard.api_version kind = data.confluent_kafka_cluster.standard.kind

environment {
  id = data.confluent_kafka_cluster.standard.id
}

} }_

Please suggest if any changes required in this code.

Kind Regards, Sohail

linouk23 commented 4 months ago

@syydsohail thanks for creating the issue!

Did you get a change to look at

It might be helpful to look at these examples to understand the relationship between API Keys, their owners, and corresponding roles.

Let us know if that helps!

syydsohail commented 4 months ago

Hi @linouk23 ,

Thank you for the reply.

Yes I was following the similar example (https://github.com/confluentinc/terraform-provider-confluent/blob/master/examples/configurations/standard-kafka-rbac/main.tf)

When I try to create kafka API key with cluster deployment, I am able to create it.

In my case the cluster is already deployed. Now I am trying to create Kafka API Key. During this second approach I am getting this error "Error: error fetching Kafka Cluster "lkc-xxxxxx"'s "rest_endpoint" attribute: error reading Kafka Cluster "lkc-xxxxx": 404 Not Found: Resource Not Found"

Maybe I am not able to pass the existing cluster details correctly.

managed_resource { id = data.confluent_kafka_cluster.standard.id api_version = data.confluent_kafka_cluster.standard.api_version kind = data.confluent_kafka_cluster.standard.kind

environment { id = data.confluent_kafka_cluster.standard.id } }

I am using Cloud API key with OrganizationAdmin role for this terraform execution.

Regards, Sohail

linouk23 commented 4 months ago

Oh I see, it seems like there's a typo in your current config @syydsohail.

Could you try

resource "confluent_api_key" "kafka-manager312-kafka-api-key" {
  display_name = "kafka-manager312-kafka-api-key"
  description  = "Kafka API Key that is owned by 'kafka-manager' service account"
  owner {
    id          = confluent_service_account.kafka-manager312.id
    api_version = confluent_service_account.kafka-manager312.api_version
    kind        = confluent_service_account.kafka-manager312.kind
  }

  managed_resource {
    id          = data.confluent_kafka_cluster.standard.id
    api_version = data.confluent_kafka_cluster.standard.api_version
    kind        = data.confluent_kafka_cluster.standard.kind

    environment {
      id = data.confluent_kafka_cluster.standard.environment[0].id
    }
  }
}

instead?

More specifically, you might want to use

    environment {
      id = data.confluent_kafka_cluster.standard.environment[0].id
    }

instead of

environment {
    id = data.confluent_kafka_cluster.standard.id
}

Let us know if that helps!

syydsohail commented 4 months ago

Hi @linouk23,

Thank you very much. Thank you for pointing out the error.

I am able to create Kafka API Key.

Kind Regards, Sohail