I am trying to create the aws_api_gateway resources using terraform, to avoid the hassle of adding the same code again and again, am trying to create a loop which create multiple resources for me in the order i specify. But, I am facing difficulties as I am new to this and it is always complaining of cyclic dependency.
The cyclic dependency is caused in "parent_id" while creating resources
Any Help would be greatly appreciated.
Here's what I have coded:
locals {
api_endpoints = [
{
path = "v0"
http_method = "GET"
integration_uri = "${uri_path}/v0"
},
{
path = "v0/expert/gen/btags"
http_method = "POST"
integration_uri = "${uri_path}/v0/expert/gen/btags"
},
{
path = "v0/expert/generate/tags"
http_method = "POST"
integration_uri = "${uri_path}/v0/expert/gen/tags"
},
{
path = "v0/expert/search"
http_method = "POST"
integration_uri = "${uri_path}/v0/expert/search"
},
]
resources_hierarchy = {
"v0" = aws_api_gateway_rest_api.gatewayh.root_resource_id
"expert" = "v0"
"gen" = "expert"
"search" = "expert"
"btags" = "gen"
"tags" = "gen"
}
}
resource "aws_api_gateway_resource" "api_resource" {
for_each = local.resources_hierarchy
rest_api_id = aws_api_gateway_rest_api.gatewayh.id
parent_id = each.value == aws_api_gateway_rest_api.gatewayh.root_resource_id ? each.value : aws_api_gateway_resource.api_resource[each.value].id
path_part = each.key
}