Am trying to call the value from list(objects), am unable to do so, am assigning count.index when am using var.service_account_id, but am not sure if this is the problem, could some one please help.
CSV data as below
name,example
test-0, one
test-1, two
MODULE
resource "confluent_api_key" "schema_reg_api_key" {
display_name = var.display_name
description = "Kafka API Key that is owned by 'app-manager' service account"
owner {
**id = var.service_account_id[count.index]**
api_version = var.api_version
kind = var.kind
}
managed_resource {
id = var.schema_registry_cluster_id
api_version = var.schema_registry_api_version
kind = var.schema_registry_kind
environment {
id = var.environment_id
}
}
lifecycle {
prevent_destroy = true
}
}
variable "service_account_id" {
description = "The Service Account ID of the owner that the API Key belongs to"
type = list(object({
name = string
example = string
}))
}
MAIN.tf
locals {
sa-test = csvdecode(file(".//projects/project-1/test.csv"))
displayname = { for test in local.sa-test : test.name => test }
}
module "confluent_service_account" {
for_each = { for test in local.sa-test : test.name => test }
source = ".//modules/confluent_service_account"
display_name = each.key.name
}
module "api_key" {
for_each = { for test in local.sa-test : test.name => test }
source = ".//modules/confluent_api_key"
depends_on = [ module.confluent_service_account ]
display_name = each.key.name
**service_account_id = module.confluent_service_account.id**
}
OUTPUT
│ Error: Invalid value for module argument
│
│ on main.tf line 25, in module "api_key":
│ 25: service_account_id = module.confluent_service_account.id
│
│ The given value is not suitable for child module variable
│ "service_account_id" defined at
│ modules/confluent_api_key/variables.tf:6,1-30: list of string required.
╵
╷
│ Error: Invalid value for module argument
│
│ on main.tf line 33, in module "schema_reg_api_key":
│ 33: service_account_id = module.confluent_service_account.id
│
│ The given value is not suitable for child module variable
│ "service_account_id" defined at modules/
│ confluent_schema_registry_api_key/variables.tf:6,1-30: list of string
│ required.