runatlantis / atlantis

Terraform Pull Request Automation
https://www.runatlantis.io
Other
7.82k stars 1.06k forks source link

Issue when communicating to Atlantis API of /api/plan and /api/apply #3606

Closed romelBen closed 1 year ago

romelBen commented 1 year ago

Community Note

Overview of the Issue

I am experimenting using Atlantis's API but I continue to receive 500 Internal Server Error. I use Istio as a reverse-proxy for traffic so I'm certain it's my pathing that is causing the issues.

Reproduction Steps

When running this script to test a PR, I receive 500 Internal Server Error.

curl --request POST 'https://atlantis.foofoo.com/api/plan' \
  -H 'X-Atlantis-Token: <PASSWORD_HERE>' \
  -H 'Content-Type: application/json' \
  -H 'Accept: application/json' \
  -d '{
    "Repository": "<REPO_NAME_HERE",
    "Ref": "master",
    "Type": "Github",
    "Paths": [{
      "Directory": "live/dev",
      "Workspace": "default"
    }],
    "PR": 1
  }'

Logs

No logs are shown for this command.

Environment details

Environment is run in K8s. I am able to run commands to /events but not /api/plan or /api/apply.

Would appreciate any help in my process of what I'm doing to receive this error.

jamengual commented 1 year ago

have you tried using a PR number that exist?

what about the atlantis pod logs?

On Fri, Jul 14, 2023 at 12:22 PM Romel Benavides @.***> wrote:

Community Note

  • Please vote on this issue by adding a 👍 reaction https://blog.github.com/2016-03-10-add-reactions-to-pull-requests-issues-and-comments/ to the original issue to help the community and maintainers prioritize this request. Searching for pre-existing feature requests helps us consolidate datapoints for identical requirements into a single place, thank you!
  • Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for issue followers and do not help prioritize the request.
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment.

Overview of the Issue

I am experimenting using Atlantis's API but I continue to receive 500 Internal Server Error. I use Istio as a reverse-proxy for traffic so I'm certain it's my pathing that is causing the issues. Reproduction Steps

When running this script to test a PR, I receive 500 Internal Server Error .

curl --request POST 'https://atlantis.foofoo.com/api/plan' \ -H 'X-Atlantis-Token: ' \ -H 'Content-Type: application/json' \ -H 'Accept: application/json' \ -d '{ "Repository": "<REPO_NAME_HERE", "Ref": "master", "Type": "Github", "Paths": [{ "Directory": "live/dev", "Workspace": "default" }], "PR": 1 }'

Logs

No logs are shown for this command. Environment details

Environment is run in K8s. I am able to run commands to /events but not /api/plan or /api/apply.

Would appreciate any help in my process of what I'm doing to receive this error.

— Reply to this email directly, view it on GitHub https://github.com/runatlantis/atlantis/issues/3606, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAQ3ERCVAYMYXNFARG743E3XQGMA3ANCNFSM6AAAAAA2KWUGQU . You are receiving this because you are subscribed to this thread.Message ID: @.***>

romelBen commented 1 year ago

I have tried using a PR that exist and did not exist. I have more information in regards to the logs that I just received now:

{"level":"warn","ts":"2023-07-14T19:07:54.297Z",
"caller":"logging/simple_logger.go:161",
"msg":"{\"error\":\"failed to build command: checking if workspace exists: stat 
/atlantis-data/repos/foo/tf-foofoo/0/default: no such file or directory\"}",
"json":{},"stacktrace":"github.com/runatlantis/atlantis/server/logging.
(*StructuredLogger).Log\n\tgithub.com/runatlantis/atlantis/server/logging/
simple_logger.go:161\ngithub.com/runatlantis/atlantis/server/controllers.(*APIController).
respond\n\tgithub.com/runatlantis/atlantis/server/controllers/api_controller.go:231\ngithub.com
/runatlantis/atlantis/server/controllers.(*APIController).apiReportError\n\tgithub.com/runatlantis
/atlantis/server/controllers/api_controller.go:78\ngithub.com/runatlantis/atlantis/server/controllers.
(*APIController).Plan\n\tgithub.com/runatlantis/atlantis/server/controllers/api_controller.go:92\nnet
/http.HandlerFunc.ServeHTTP\n\tnet/http/server.go:2122\ngithub.com/gorilla/mux.
(*Router).ServeHTTP\n\tgithub.com/gorilla/mux@v1.8.0/mux.go:210\ngithub.com/urfave/negroni/
v3.Wrap.func1\n\tgithub.com/urfave/negroni/v3@v3.0.0/negroni.go:59\ngithub.com/urfave/negroni/
v3.HandlerFunc.ServeHTTP\n\tgithub.com/urfave/negroni/v3@v3.0.0/negroni.go:33\ngithub.com/
urfave/negroni/v3.middleware.ServeHTTP\n\tgithub.com/urfave/negroni/v3@v3.0.0/negroni.go:51\
ngithub.com/runatlantis/atlantis/server.(*RequestLogger).ServeHTTP\n\tgithub.com/runatlantis/
atlantis/server/middleware.go:70\ngithub.com/urfave/negroni/v3.middleware.ServeHTTP\n\
tgithub.com/urfave/negroni/v3@v3.0.0/negroni.go:51\ngithub.com/urfave/negroni/v3.(*Recovery).
ServeHTTP\n\tgithub.com/urfave/negroni/v3@v3.0.0/recovery.go:210\ngithub.com/urfave/negroni/
v3.middleware.ServeHTTP\n\tgithub.com/urfave/negroni/v3@v3.0.0/negroni.go:51\ngithub.com/urfave/negroni/v3.
(*Negroni).ServeHTTP\n\tgithub.com/urfave/negroni/v3@v3.0.0/negroni.go:111\nnet/
http.serverHandler.ServeHTTP\n\tnet/http/server.go:2936\nnet/http.(*conn).serve\n\tnet/http/server.go:1995"}

Would the best approach be to run an atlantis plan initially? Where I create a PR out of the repo of what I am assuming from this process? (My Atlantis Server is a clean slate with no plans of itself.)

I should also mention I am trying to implement atlantis-drift-detection in my use.

jamengual commented 1 year ago

take a look at this : https://github.com/cresta/atlantis-drift-detection

you will need to create the PR outside yes.

On Fri, Jul 14, 2023 at 12:33 PM Romel Benavides @.***> wrote:

I have tried using a PR that exist and did not exist. I have more information in regards to the logs that I just received now:

{"level":"warn","ts":"2023-07-14T19:07:54.297Z","caller":"logging/simple_logger.go:161","msg":"{\"error\":\"failed to build command: checking if workspace exists: stat /atlantis-data/repos/foo/tf-foofoo/0/default: no such file or directory\"}","json":{},"stacktrace":"github.com/runatlantis/atlantis/server/logging.(StructuredLogger).Log\n\tgithub.com/runatlantis/atlantis/server/logging/simple_logger.go:161\ngithub.com/runatlantis/atlantis/server/controllers.(APIController).respond\n\tgithub.com/runatlantis/atlantis/server/controllers/api_controller.go:231\ngithub.com http://tgithub.com/runatlantis/atlantis/server/controllers/api_controller.go:231%5Cngithub.com/runatlantis/atlantis/server/controllers.(APIController).apiReportError\n\tgithub.com/runatlantis/atlantis/server/controllers/api_controller.go:78\ngithub.com/runatlantis/atlantis/server/controllers.(APIController).Plan\n\tgithub.com/runatlantis/atlantis/server/controllers/api_controller.go:92\nnet @./mux.go:210\ngithub.com/urfave/negroni/ @*.**@*./negroni.go:59\ngithub.com/urfave/negroni/ @*.**@*./negroni.go:33\ngithub.com/ @*.**@*./negroni.go:51\ngithub.com/runatlantis/atlantis/server.(RequestLogger).ServeHTTP\n\tgithub.com/runatlantis/ http://ngithub.com/runatlantis/atlantis/server.(*RequestLogger).ServeHTTP%5Cn%5Ctgithub.com/runatlantis/atlantis/server/middleware.go:70\ngithub.com/urfave/negroni/v3.middleware.ServeHTTP\n *@./negroni.go:51\ngithub.com/urfave/negroni/v3.(*Recovery) @.**@./recovery.go:210\ngithub.com/urfave/negroni/ @.**@./negroni.go:51\ngithub.com/urfave/negroni/v3 @.**@./negroni.go:111\nnet/ @.**/negroni.go:111%5Cnnet/>http.serverHandler.ServeHTTP\n\tnet/http/server.go:2936\nnet/http.(conn).serve\n\tnet/http/server.go:1995"}

Would the best approach be to run an atlantis plan initially? Where I create a PR out of the repo of what I am assuming from this process? (My Atlantis Server is a clean slate with no plans of itself.)

I should also mention I am trying to implement atlantis-drift-detection https://github.com/cresta/atlantis-drift-detection in my use.

— Reply to this email directly, view it on GitHub https://github.com/runatlantis/atlantis/issues/3606#issuecomment-1636325988, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAQ3ERFBRWNNCUKA75ASRP3XQGNHJANCNFSM6AAAAAA2KWUGQU . You are receiving this because you commented.Message ID: @.***>

romelBen commented 1 year ago

Ok, resolved it. I'm getting another issue but this has to do with downloading modules onto the GH actions. Will see about adding a custom workflow instead to be run prior to Atlantis build process.

What was happening is the PR is 0 which doesn't exist in the Atlantis Server. Had to manually create the directory since I'm on 5 and it worked.