Hi Support Team,
Can someone please review this task? I get the following error message:
“Dev workspace API Gateway names are incorrect or missing”
However, I think I’ve created them correctly see the following screenshots and code snippets:
locals {
env = terraform.workspace
api_names = var.KKE_API_NAMES
api_gw = local.env == “dev” ? [local.api_names[0]] : local.env == “prod” ? [local.api_names[1]] : []
}
resource “aws_api_gateway_rest_api” “devops_api_gws” {
count = length(local.api_gw)
name = “${local.env}-${local.api_gw[count.index]}”
provisioner “local-exec” {
when = create
command = “echo "Created API Gateway ${self.name} in workspace ${terraform.workspace}" >> apigateway.log”
}
}
resource “aws_cloudwatch_log_group” “devops_log_groups” {
count = length(local.api_gw)
name = “/aws/apigateway/${aws_api_gateway_rest_api.devops_api_gws[count.index].name}”
provisioner “local-exec” {
when = create
command = “echo "Created Log Group ${self.name} in workspace ${terraform.workspace}" >> loggroups.log”
}
}
variable “KKE_API_NAMES” {
description = “Workspace API names”
type = list(string)
validation {
condition = length(var.KKE_API_NAMES) >= 2
error_message = “Provide at least two API names, e.g., ["devops-api-1","devops-api-2"].”
}
}
output “kke_api_gateway_names” {
description = “API Gateway names created in the current workspace”
value = [for api in aws_api_gateway_rest_api.devops_api_gws : api.name]
}
output “kke_log_group_names” {
description = “CloudWatch Log Group names created in the current workspace”
value = [for log in aws_cloudwatch_log_group.devops_log_groups : log.name]
}
terraform.tfvars
KKE_API_NAMES = [“devops-api-1”, “devops-api-2”]



