Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

panic: not a string #266

Closed
JohnLahr opened this issue Jan 16, 2023 · 2 comments
Closed

panic: not a string #266

JohnLahr opened this issue Jan 16, 2023 · 2 comments

Comments

@JohnLahr
Copy link

Current Behavior

Running terragrunt-atlantis-config generate with any combination of flags/arguments causes a panic: not a string error and fails. I first noticed this on a repository I've been using with Atlantis for over a year, and no changes have been made to the Atlantis configuration or to the root terragrunt.hcl file. This started happening after an update to the latest version of terragrunt-atlantis-config.

Expected Behavior

Running terragrunt-atlantis-config generate should generate the atlantis.yaml file necessary for Atlantis to properly read the Terragrunt repository.

Steps To Reproduce

From the Atlantis container, run terragrunt-atlantis-config generate --output=atlantis.yaml --autoplan=false --workflow=terragrunt --ignore-parent-terragrunt --parallel=false --ignore-dependency-blocks (the same command I've been using for a year) in the root of the Terragrunt repository.

Environment

OS: Ubuntu 22.04 (Docker host running the Atlantis container)
Dockerfile:

FROM ghcr.io/runatlantis/atlantis:v0.22.2
# https://github.com/runatlantis/atlantis/releases

# --------------------------------------------------------------------------- #
# Configuration                                                               #
# --------------------------------------------------------------------------- #

ARG VERSION=1.0.0

# https://github.com/gruntwork-io/terragrunt/releases
ARG TERRAGRUNT_VERSION=0.42.7

# https://github.com/transcend-io/terragrunt-atlantis-config/releases
ARG TERRAGRUNT_ATLANTIS_CONFIG_VERSION=1.16.0

# --------------------------------------------------------------------------- #
# Installation                                                                #
# --------------------------------------------------------------------------- #

# Install Terragrunt
ADD https://github.com/gruntwork-io/terragrunt/releases/download/v${TERRAGRUNT_VERSION}/terragrunt_linux_amd64 /usr/local/bin/terragrunt

# Install Terragrunt Atlantis config
ADD https://github.com/transcend-io/terragrunt-atlantis-config/releases/download/v${TERRAGRUNT_ATLANTIS_CONFIG_VERSION}/terragrunt-atlantis-config_${TERRAGRUNT_ATLANTIS_CONFIG_VERSION}_linux_amd64.tar.gz /tmp/terragrunt-atlantis-config.tar.gz
RUN tar xf /tmp/terragrunt-atlantis-config.tar.gz -C /tmp \
    && mv \
      /tmp/terragrunt-atlantis-config_${TERRAGRUNT_ATLANTIS_CONFIG_VERSION}_linux_amd64/terragrunt-atlantis-config_${TERRAGRUNT_ATLANTIS_CONFIG_VERSION}_linux_amd64 \
      /tmp/terragrunt-atlantis-config \
    && install /tmp/terragrunt-atlantis-config /usr/local/bin

ADD files/terragrunt_quiet.sh /usr/local/bin/terragrunt_quiet.sh

RUN chmod +x /usr/local/bin/terragrunt \
    /usr/local/bin/terragrunt_quiet.sh \
    /usr/local/bin/terragrunt-atlantis-config

# --------------------------------------------------------------------------- #

CPU architecture

x86-64

How is Atlantis deployed?

Using docker-compose:

  atlantis:
    depends_on:
      - gitlab
    hostname: atlantis
    domainname: ${DOMAIN_NAME}
    container_name: atlantis
    image: registry.${DOMAIN_NAME}/myorg/atlantis:latest
    restart: unless-stopped
    command:
      - server
      - --atlantis-url=https://atlantis.${DOMAIN_NAME}
      - --disable-autoplan
      - --gitlab-user=atlantis
      - --repo-allowlist=gitlab.${DOMAIN_NAME}/infrastructure/infrastructure-live
      - --gitlab-hostname=gitlab.${DOMAIN_NAME}
    networks:
      proxy-network:
        ipv4_address: 172.30.2.52
    volumes:
      - ${CONTAINER_STORAGE_ROOT}/atlantis/.aws:/home/atlantis/.aws
      - ${CONTAINER_STORAGE_ROOT}/atlantis/.ssh:/home/atlantis/.ssh
      - ${CONTAINER_STORAGE_ROOT}/atlantis/data:/home/atlantis/.atlantis
    environment:
      - "ATLANTIS_GITLAB_TOKEN=${ATLANTIS_GITLAB_TOKEN}"
      - "ATLANTIS_GITLAB_WEBHOOK_SECRET=${ATLANTIS_GITLAB_WEBHOOK_SECRET}"
      - 'ATLANTIS_REPO_CONFIG_JSON={"repos":[{"id":"/.*/","allowed_overrides":["workflow"],"apply_requirements":["mergeable"],"pre_workflow_hooks":[{"run":"terragrunt-atlantis-config generate --output=atlantis.yaml --autoplan=false --workflow=terragrunt --ignore-parent-terragrunt --parallel=false --ignore-dependency-blocks"}]}],"workflows":{"terragrunt":{"plan":{"steps":[{"run":"rm -rf .terragrunt-cache && terragrunt_quiet.sh $$PLANFILE"}]},"apply":{"steps":[{"run":"terragrunt apply -compact-warnings -no-color $$PLANFILE"}]}}}}'
      - "ATLANTIS_WEB_PASSWORD=${ATLANTIS_WEB_PASSWORD}"
      - "ATLANTIS_WEB_USERNAME=atlantis"

Container logs

atlantis:/home/atlantis/.atlantis/repos/infrastructure/infrastructure-live/33/default# terragrunt-atlantis-config generate --output=atlantis.yaml --autoplan --parallel --create-workspace
INFO[0000] Could not find an old config file. Starting from scratch
panic: not a string

runtime/debug.Stack()
	/opt/hostedtoolcache/go/1.19.1/x64/src/runtime/debug/stack.go:24 +0x65
golang.org/x/sync/singleflight.newPanicError({0x1076660?, 0x14f8860})
	/home/runner/go/pkg/mod/golang.org/x/sync@v0.0.0-20210220032951-036812b2e83c/singleflight/singleflight.go:35 +0x2c
golang.org/x/sync/singleflight.(*Group).doCall.func2.1()
	/home/runner/go/pkg/mod/golang.org/x/sync@v0.0.0-20210220032951-036812b2e83c/singleflight/singleflight.go:188 +0x3b
panic({0x1076660, 0x14f8860})
	/opt/hostedtoolcache/go/1.19.1/x64/src/runtime/panic.go:884 +0x212
github.com/zclconf/go-cty/cty.Value.AsString({{{0x15080e8?, 0xc0007e5dc0?}}, {0x10e89c0?, 0xc000901b90?}})
	/home/runner/go/pkg/mod/github.com/zclconf/go-cty@v1.8.3/cty/value_ops.go:1256 +0x138
github.com/transcend-io/terragrunt-atlantis-config/cmd.resolveLocals({{{0x15080e8?, 0xc000973bc0?}}, {0x10e89c0?, 0xc00057eb10?}})
	/home/runner/work/terragrunt-atlantis-config/terragrunt-atlantis-config/cmd/parse_locals.go:188 +0x625
github.com/transcend-io/terragrunt-atlantis-config/cmd.parseLocals({0xc000048d80, 0x5b}, 0xc0005a82a0?, 0xc0002fc0f0)
	/home/runner/work/terragrunt-atlantis-config/terragrunt-atlantis-config/cmd/parse_locals.go:129 +0x2a5
github.com/transcend-io/terragrunt-atlantis-config/cmd.parseLocals({0xc000663580, 0x7d}, 0x0?, 0x0)
	/home/runner/work/terragrunt-atlantis-config/terragrunt-atlantis-config/cmd/parse_locals.go:125 +0x62e
github.com/transcend-io/terragrunt-atlantis-config/cmd.getDependencies.func1()
	/home/runner/work/terragrunt-atlantis-config/terragrunt-atlantis-config/cmd/generate.go:167 +0x312
golang.org/x/sync/singleflight.(*Group).doCall.func2(0xc00094595e, 0xc00059acc0, 0x60?)
	/home/runner/go/pkg/mod/golang.org/x/sync@v0.0.0-20210220032951-036812b2e83c/singleflight/singleflight.go:193 +0x6f
golang.org/x/sync/singleflight.(*Group).doCall(0x10e6380?, 0xc00057f2c0?, {0xc000663580?, 0x7d?}, 0xfc5edd?)
	/home/runner/go/pkg/mod/golang.org/x/sync@v0.0.0-20210220032951-036812b2e83c/singleflight/singleflight.go:195 +0xa5
golang.org/x/sync/singleflight.(*Group).Do(0x1d19cc0, {0xc000663580, 0x7d}, 0x31?)
	/home/runner/go/pkg/mod/golang.org/x/sync@v0.0.0-20210220032951-036812b2e83c/singleflight/singleflight.go:108 +0x165
github.com/transcend-io/terragrunt-atlantis-config/cmd.getDependencies({0xc000663580?, 0x7d?}, 0x0?)
	/home/runner/work/terragrunt-atlantis-config/terragrunt-atlantis-config/cmd/generate.go:127 +0x67
github.com/transcend-io/terragrunt-atlantis-config/cmd.createProject({0xc000663580, 0x7d})
	/home/runner/work/terragrunt-atlantis-config/terragrunt-atlantis-config/cmd/generate.go:330 +0xf4
github.com/transcend-io/terragrunt-atlantis-config/cmd.main.func1()
	/home/runner/work/terragrunt-atlantis-config/terragrunt-atlantis-config/cmd/generate.go:737 +0xa5
golang.org/x/sync/errgroup.(*Group).Go.func1()
	/home/runner/go/pkg/mod/golang.org/x/sync@v0.0.0-20210220032951-036812b2e83c/errgroup/errgroup.go:57 +0x67
created by golang.org/x/sync/errgroup.(*Group).Go
	/home/runner/go/pkg/mod/golang.org/x/sync@v0.0.0-20210220032951-036812b2e83c/errgroup/errgroup.go:54 +0x8d


goroutine 26 [running]:
golang.org/x/sync/singleflight.(*Group).doCall.func1()
	/home/runner/go/pkg/mod/golang.org/x/sync@v0.0.0-20210220032951-036812b2e83c/singleflight/singleflight.go:165 +0x29b
golang.org/x/sync/singleflight.(*Group).doCall(0x10e6380?, 0xc00057f2c0?, {0xc000663580?, 0x7d?}, 0xfc5edd?)
	/home/runner/go/pkg/mod/golang.org/x/sync@v0.0.0-20210220032951-036812b2e83c/singleflight/singleflight.go:200 +0xc2
golang.org/x/sync/singleflight.(*Group).Do(0x1d19cc0, {0xc000663580, 0x7d}, 0x31?)
	/home/runner/go/pkg/mod/golang.org/x/sync@v0.0.0-20210220032951-036812b2e83c/singleflight/singleflight.go:108 +0x165
github.com/transcend-io/terragrunt-atlantis-config/cmd.getDependencies({0xc000663580?, 0x7d?}, 0x0?)
	/home/runner/work/terragrunt-atlantis-config/terragrunt-atlantis-config/cmd/generate.go:127 +0x67
github.com/transcend-io/terragrunt-atlantis-config/cmd.createProject({0xc000663580, 0x7d})
	/home/runner/work/terragrunt-atlantis-config/terragrunt-atlantis-config/cmd/generate.go:330 +0xf4
github.com/transcend-io/terragrunt-atlantis-config/cmd.main.func1()
	/home/runner/work/terragrunt-atlantis-config/terragrunt-atlantis-config/cmd/generate.go:737 +0xa5
golang.org/x/sync/errgroup.(*Group).Go.func1()
	/home/runner/go/pkg/mod/golang.org/x/sync@v0.0.0-20210220032951-036812b2e83c/errgroup/errgroup.go:57 +0x67
created by golang.org/x/sync/errgroup.(*Group).Go
	/home/runner/go/pkg/mod/golang.org/x/sync@v0.0.0-20210220032951-036812b2e83c/errgroup/errgroup.go:54 +0x8d
@JohnLahr JohnLahr changed the title Panic: panic: not a string Jan 16, 2023
@JohnLahr
Copy link
Author

Closing this issue as I've realized it was entirely user error. I'll post my fix here, although it's highly unlikely that someone else will stumble across this issue for the same reason.

At some point in my Git history (presumably through a bad find/replace operation), I added a yamldecode(file()) operation to every file in my top-level extra_atlantis_dependencies block. My fix, as seen in the diff below, was simply to remove this again.

  extra_atlantis_dependencies = [
-    yamldecode(file(find_in_parent_folders("account.yaml", "empty.yaml"))),
-    yamldecode(file(find_in_parent_folders("aws.yaml", "empty.yaml"))),
-    yamldecode(file(find_in_parent_folders("gitlab.yaml", "empty.yaml"))),
-    yamldecode(file(find_in_parent_folders("region.yaml", "empty.yaml"))),
-    yamldecode(file(find_in_parent_folders("root.yaml", "empty.yaml"))),
-    yamldecode(file(find_in_parent_folders("versions.yaml", "empty.yaml"))),
+    find_in_parent_folders("account.yaml", "empty.yaml"),
+    find_in_parent_folders("aws.yaml", "empty.yaml"),
+    find_in_parent_folders("gitlab.yaml", "empty.yaml"),
+    find_in_parent_folders("region.yaml", "empty.yaml"),
+    find_in_parent_folders("root.yaml", "empty.yaml"),
+    find_in_parent_folders("versions.yaml", "empty.yaml"),
  ]
}

@bmbferreira
Copy link

👋 despite being a user error the error message could be more explicit. I just lost a ton of time because of this same problem and decided to improve the error message to make it easier to troubleshoot this problem when this happens again: #367

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants