JetBrains/kotless

Completely removing a Ktor route fails when attempting to deploy via Terraform [Kotless 0.2.0, Ktor 1.50, AWS]

v79 opened this issue · 2 comments

v79 commented

If I create a simple Ktor route in a Kotless project, e.g.:

get("/test-delete") {
call.respondText("This function needs to be deleted")
}

This deploys successfully to AWS and appears in the API gateway as expected.

But if I then delete the route entirely, and redeploy, the deployment fails. The stacktrace isn't particularly helpful:

org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':deploy'.
	at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.lambda$executeIfValid$1(ExecuteActionsTaskExecuter.java:188)
	at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter$$Lambda$481/0x0000000000000000.accept(Unknown Source)
...
	at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:48)
	at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:56)
Caused by: java.lang.IllegalStateException: Command failed: 'D:\Development\Experiments\Kotless\KotlessTestBeta\build\kotless-bin\terraform [apply, -auto-approve]'
	at io.kotless.plugin.gradle.utils.CommandLine.executeOrFail(CommandLine.kt:51)
	at io.kotless.plugin.gradle.tasks.terraform.TerraformOperationTask.act(TerraformOperationTask.kt:43)

To get more information, I tried executing terraform apply manually, which returned the following errors:

build\kotless-gen\deploy> ..\..\kotless-bin\terraform.exe apply
...
Plan: 1 to add, 10 to change, 12 to destroy.
Do you want to perform these actions? yes

Error: Cycle: aws_s3_bucket_object.test_delete_get (destroy), aws_api_gateway_resource.test_delete (destroy), aws_iam_role.test_delete_get (destroy), aws_api_gateway_deployment.root, aws_api_gateway_deployment.root (destroy deposed 8be2616a), aws_api_gateway_integration.test_delete_get (destroy), aws_lambda_function.test_delete_get (destroy)

Perhaps some sort of circular depedency?

Kotless 0.2.0, Ktor 1.5.0, AWS, Windows 10 x64.

v79 commented

The workaround is to manually delete the test_delete method from the API gateway manually, then redeploy.

I just encountered the same problem with the same technologies: Kotless 0.2.0, Ktor 1.5.0, AWS, Windows 10x64

Perhaps this can be of use: hashicorp/terraform-provider-aws#11344

@v79 Thanks for the workaround suggestion.