hashicorp / waypoint

A tool to build, deploy, and release any application on any platform.
https://waypointproject.io
Other
4.76k stars 327 forks source link

dynamic("terraform-cloud") variable fails silently #3675

Open thiskevinwang opened 2 years ago

thiskevinwang commented 2 years ago

Describe the bug

When using a variable with dynamic("terraform-cloud"..., waypoint up fails and says that no default value was set for the variable.

waypoint up -local=false
There are local changes that do not match the remote repository. By default,
Waypoint will perform this operation using a remote runner that will use the
remote repository’s git ref and not these local changes. For these changes
to be used for future operations, either commit and push, or run the operation
locally with the -local flag.

» Operation is queued waiting for job "01GAA4SYFB9JQWPMQFHZYS38ED". Waiting
for runner assignment...
  If you interrupt this command, the job will still run in the
background.
  Performing operation on "kubernetes" with runner profile
"kubernetes-bootstrap-profile"

» Cloning data from Git
  URL: https://github.com/thiskevinwang/waypoint-web-lambda.git
  Ref: refs/heads/waypoint-terraform-hook
! /kaniko/tmp/waypoint569871409/go/gin/waypoint.hcl:13,1-18: Unset variable
  "FOOBAR"; A variable must be set or have a default value; see
  https://www.waypointproject.io/docs/waypoint-hcl/variables/input for
details.

Steps to Reproduce

  1. Install Waypoint on K8s
  2. Configure a project with Git source
  3. waypoint up -local=false
variable "FOOBAR" {
  type = string
  default = dynamic("terraform-cloud", {
    organization = "waypoint"
    workspace    = "go-gin"
    output       = "foobar"
  })
}

# ...
  deploy {
    use "aws-lambda" {
      region = var.region
      memory = 512
      static_environment = {
        FOOBAR = var.FOOBAR
      }
    }
  }

Expected behavior

A helpful/actionable Console UI output would be a nice improvement

Waypoint Platform Versions

CLI: v0.9.1 (9562f453c)
Server: v0.9.0-211-g2d06a4360

Additional context

N/A

briancain commented 2 years ago

Hey @thiskevinwang! I've noticed this too, sometimes the dynamic config sourcer plugin ends up failing in the runner log which doesn't end up surfacing to the CLI, only that the dynamic var was unset. If you have the runner log handy, could you share that too? It might have the actual log for what the TFC lookup failed. Thank you!

thiskevinwang commented 2 years ago

@briancain - I was able to reproduce this fairly easily with a fresh server install on K8s! Here's the gist and a snippet:

2022-08-15T23:03:52.568Z [WARN]  waypoint.runner.agent.runner.watchloop: error configuring config source: 
  job_id=01GAHVZE666A9XDGWMCVM3F9CY 
  job_op=*gen.Job_Up 
  source=terraform-cloud 
  err="<nil>: Missing required argument; The argument "token" is required, but was not set."
briancain commented 2 years ago

@thiskevinwang thank you! That error makes sense, I think you must need to set the token var to access your terraform cloud data? https://tip.waypointproject.io/plugins/terraform-cloud#token

izaaklauer commented 2 years ago

When the runner tried to evaluate that dynamic config sourcer plugin and fails, we should fail the job, rather than warn log and skip resolving the variable as it appears that we're doing now.

This needs to be a noisier failure: https://github.com/hashicorp/waypoint/blob/d6194c5451b90c79fc7e3cebdd35f66a8314f2f5/internal/appconfig/watcher.go#L735