atlantis: runtime error: invalid memory address or nil pointer dereference

Hi,

I am trying to integrate atlantis (v0.17.4) with gitlab (free self managed ver. 11.9.6).

It is working fine till autoplan Comment output:
Ran Plan for project: preprod dir: environments/preprod workspace: default

Terraform used the selected providers to generate the following execution
plan. Resource actions are indicated with the following symbols:
+ create

Terraform will perform the following actions:

  # module.eks_1.null_resource.test0 will be created
+ resource "null_resource" "test0" {
      + id = (known after apply)
    }

  # module.eks_1.null_resource.test1 will be created
+ resource "null_resource" "test1" {
      + id = (known after apply)
    }

Plan: 2 to add, 0 to change, 0 to destroy.
  • ▶️ To apply this plan, comment:

    • atlantis apply -p preprod
  • 🚮 To delete this plan click ***

  • 🔁 To plan this project again, comment:

    • atlantis plan -p preprod
  • ⏩ To apply all unapplied plans from this pull request, comment:

    • atlantis apply
  • 🚮 To delete all plans and locks for the PR, comment:

    • atlantis unlock

But fails when I do “atlantis apply -p preprod”: Error: goroutine panic. This is a bug.

runtime error: invalid memory address or nil pointer dereference
/usr/local/go/src/runtime/panic.go:221 (0x449106)
/usr/local/go/src/runtime/signal_unix.go:735 (0x4490d6)
/home/circleci/project/server/events/vcs/gitlab_client.go:208 (0x96c66a)
/home/circleci/project/server/events/vcs/proxy.go:72 (0x96dbd4)
/home/circleci/project/server/events/apply_command_runner.go:101 (0xe436b4)
/home/circleci/project/server/events/command_runner.go:214 (0xe476a3)
/usr/local/go/src/runtime/asm_amd64.s:1581 (0x463f40)
Following is the request body sent by gitlab

{
  "object_kind": "note",
  "event_type": "note",
  "user": {
    "name": "***",
    "username": "***",
    "avatar_url": "***/uploads/-/system/user/avatar/503/avatar.png"
  },
  "project_id": 953,
  "project": {
    "id": 953,
    "name": "terraform",
    "description": "",
    "web_url": "***",
    "avatar_url": null,
    "git_ssh_url": "***",
    "git_http_url": "***",
    "namespace": "***",
    "visibility_level": 0,
    "path_with_namespace": "***",
    "default_branch": "master",
    "ci_config_path": null,
    "homepage": "***",
    "url": "***",
    "ssh_url": "***",
    "http_url": "***"
  },
  "object_attributes": {
    "attachment": null,
    "author_id": 503,
    "change_position": null,
    "commit_id": null,
    "created_at": "2021-10-12 15:07:52 UTC",
    "discussion_id": "82fd2f394e41ef45062f5b20021d35caa8eea8af",
    "id": 117876,
    "line_code": null,
    "note": "atlantis apply -p preprod",
    "noteable_id": 33736,
    "noteable_type": "MergeRequest",
    "original_position": null,
    "position": null,
    "project_id": 953,
    "resolved_at": null,
    "resolved_by_id": null,
    "resolved_by_push": null,
    "st_diff": null,
    "system": false,
    "type": null,
    "updated_at": "2021-10-12 15:07:52 UTC",
    "updated_by_id": null,
    "description": "atlantis apply -p preprod",
    "url": "***/terraform/merge_requests/7#note_117876"
  },
  "repository": {
    "name": "terraform",
    "url": "***",
    "description": "",
    "homepage": "***/terraform"
  },
  "merge_request": {
    "assignee_id": null,
    "author_id": 503,
    "created_at": "2021-10-12 15:06:48 UTC",
    "description": "",
    "head_pipeline_id": 15358,
    "id": 33736,
    "iid": 7,
    "last_edited_at": null,
    "last_edited_by_id": null,
    "merge_commit_sha": null,
    "merge_error": null,
    "merge_params": {
      "force_remove_source_branch": "0"
    },
    "merge_status": "can_be_merged",
    "merge_user_id": null,
    "merge_when_pipeline_succeeds": false,
    "milestone_id": null,
    "source_branch": "div-fb",
    "source_project_id": 953,
    "state": "opened",
    "target_branch": "master",
    "target_project_id": 953,
    "time_estimate": 0,
    "title": "check1",
    "updated_at": "2021-10-12 15:07:52 UTC",
    "updated_by_id": null,
    "url": "***/terraform/merge_requests/7",
    "source": {
      "id": 953,
      "name": "terraform",
      "description": "",
      "web_url": "***/terraform",
      "avatar_url": null,
      "git_ssh_url": "***",
      "git_http_url": "***",
      "namespace": "***",
      "visibility_level": 0,
      "path_with_namespace": "***/terraform",
      "default_branch": "master",
      "ci_config_path": null,
      "homepage": "***/terraform",
      "url": "***/terraform.git",
      "ssh_url": "***/terraform.git",
      "http_url": "***"
    },
    "target": {
      "id": 953,
      "name": "terraform",
      "description": "",
      "web_url": "***/terraform",
      "avatar_url": null,
      "git_ssh_url": "***/terraform.git",
      "git_http_url": "***/terraform.git",
      "namespace": "***",
      "visibility_level": 0,
      "path_with_namespace": "***/terraform",
      "default_branch": "master",
      "ci_config_path": null,
      "homepage": "***/terraform",
      "url": "***/terraform.git",
      "ssh_url": "***/terraform.git",
      "http_url": "***/terraform.git"
    },
    "last_commit": {
      "id": "5facef328360f37b26da3268d9cdc438fcc30cd4",
      "message": "check1\n",
      "timestamp": "2021-10-12T15:02:49Z",
      "url": "***/terraform/commit/5facef328360f37b26da3268d9cdc438fcc30cd4",
      "author": {
        "name": "***",
        "email": "***"
      }
    },
    "work_in_progress": false,
    "total_time_spent": 0,
    "human_total_time_spent": null,
    "human_time_estimate": null
  }
}

Installation repoConfig
repoConfig: |
  ---
  repos:
  - id: ***/terraform
    # apply_requirements: [mergeable]
    allowed_overrides: [apply_requirements, workflow, delete_source_branch_on_merge]
    allowed_workflows: [preprod_workflow]
    delete_source_branch_on_merge: true

  # workflows lists server-side custom workflows
  workflows:
    preprod_workflow:
      plan:
        steps:
        - init:
            extra_args: ["-input=false", "-no-color"]
        - plan:
            extra_args: ["-input=false", "-no-color", "-refresh=false", "-parallelism=30"]
      apply:
        steps:
        - apply:
            extra_args: ["-no-color", "-input=false", "-parallelism=30"]
atlantis.yaml at repo's root
version: 3
automerge: true
projects:
- name: preprod
  dir: ./environments/preprod
  workspace: default
  terraform_version: v1.0.2
  autoplan:
    when_modified: ["./*.tf"]
    enabled: true
  workflow: preprod_workflow

Thanks for any help!

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 9
  • Comments: 30 (16 by maintainers)

Commits related to this issue

Most upvoted comments

For me removing the .terraform.lock.hcl solved the issue.

In my case, the problem disappeared after changing the role of the access token from “reporter” to “developer”. I don’t know if it has anything to do with the error, but I hope it helps someone!

following this workaround helped me out https://github.com/runatlantis/atlantis/issues/2606#issuecomment-1300908417

$ cat .gitlab-ci.yml
dummy:
  script:
    - echo "dummy job for atlantis to trigger pipelineID"

@c0da for us it was always developer, but somehow we had to renew tokens for every gitlab update…

I observed the same issue with our gitlab instance after updating atlantis to 0.19.2. I downgraded back to 0.17.4, the version we had before the update, and everything currently works again. So while its almost definitely an issue with the gitlab api, older versions do seem to be fine with the api issue.

The error on atlantis:

runtime error: invalid memory address or nil pointer dereference
runtime/panic.go:221 (0x449366)
runtime/signal_unix.go:735 (0x449336)
github.com/runatlantis/atlantis/server/events/vcs/gitlab_client.go:208 (0x98598a)

after some troubleshooting using the same gitlab project, branch and commit id with two separate merge request i got two distinct results calling the GitLab API: https://gitlab.com/api/v4/projects/:id/merge_requests/:iid for the field that is used by the go-gitlab module to retrieve the value for mr.HeadPipeline

...
    "first_deployed_to_production_at": null,
    "pipeline": null,
    "head_pipeline": null,
    "diff_refs": {
        "base_sha": "844 ...

and

    "first_deployed_to_production_at": null,
    "pipeline": {
        "id": 47 ...
    },
    "head_pipeline": {
        "id": 47 ...

Which means there is not issue with the token used because i’m using the same one and i got the two results, one with data on head_pipeline field and the other one with null (that causes the panic error on atlantis)

This discards that there is an issue on the module used to access the Gitlab API (github.com/xanzy/go-gitlab) that is doing the expected work or issues on permission access caused by the token.

IF the row 208 requires the SHA of the commit for the head_pipeline, maybe that value can be found under diff_refs property head_sha

Having same issue, using TF Cloud as backend