My resource from a module is getting created based on create variable like so:
resource "aws_api_gateway_rest_api" "ui_apigw_regional" {
count = var.create == true ? 1 : 0
I need the output value of it to be a string like this:
"comp_rest_api_id": {
"sensitive": false,
"type": "string",
"value": "8347123a"
}
Currently, it is coming like this:
"comp_rest_api_id": {
"sensitive": false,
"type": [
"tuple",
[
"string"
]
],
"value": [
"8347123a"
]
},
I assumed that referring to the first index would extract it as a string, but it is not so it seems. What can I change here to get the output value as a string?
output "rest_api_id" {
description = "The ids of the user pool clients"
value = var.create == true ? aws_api_gateway_rest_api.ui_apigw_regional[0].id : null
}
I have tried the one
function as well as mentioned here : Terraform outputs with count.index - #2 by apparentlymart
output "rest_api_id" {
description = "The ids of the user pool clients"
value = one(aws_api_gateway_rest_api.ui_apigw_regional[*].id)
}
output "comp_rest_api_id" {
value = module.comp.rest_api_id
}
But it also returns a list.