fun getResource()

in engine/src/main/kotlin/io/kotless/gen/factory/aws/route/AbstractRouteFactory.kt [23:49]


    fun getResource(resourcePath: URIPath, api: RestAPIFactory.Output, context: GenerationContext): ResourceDescriptor {
        val resources = context.storage.getOrPut(resource) { HashMap() }

        if (URIPath() !in resources) {
            resources[URIPath()] = ResourceDescriptor(api.ref, api.root_resource_id)
        }

        var path = URIPath()
        for (part in resourcePath.parts) {
            val prev = path
            path = URIPath(path, part)

            if (path !in resources) {
                val resource = api_gateway_resource(context.names.tf(path.parts)) {
                    depends_on = arrayOf(link(resources[prev]!!.ref))

                    rest_api_id = api.rest_api_id
                    parent_id = resources[prev]!!.id
                    path_part = part
                }
                context.entities.register(resource)
                resources[path] = ResourceDescriptor(resource.hcl_ref, resource::id.ref)
            }
        }

        return resources[path]!!
    }