Terraform init displays only usage

Hi,

During my progress of updating terraform, im stuck at 0.15.5.
My CI has no problems in running terraform fmt and terraform validate, but the problems starts on using the init command.
When calling terraform init the output is only its usages and then exits with code 1.
Running init locally works just fine. I couldnt find any breaking changes in the changelog.

Is there any information usable to debug this? Everything works fine on 0.14.x

This is the command run

$ terraform -chdir=terraform/env/${STAGE} init -no-color
{"@level":"debug","@message":"Adding temp file log sink: /tmp/terraform-log325288379","@timestamp":"2021-11-11T15:09:11.605656Z"}
{"@level":"info","@message":"Terraform version: 0.15.5","@timestamp":"2021-11-11T15:09:11.606139Z"}
{"@level":"info","@message":"Go runtime version: go1.16.4","@timestamp":"2021-11-11T15:09:11.606324Z"}
{"@level":"info","@message":"CLI args: []string{\"/usr/local/bin/terraform\", \"-chdir=terraform/env/staging\", \"init\", \"-no-color\"}","@timestamp":"2021-11-11T15:09:11.606511Z"}
{"@level":"trace","@message":"Stdout is not a terminal","@timestamp":"2021-11-11T15:09:11.606773Z"}
{"@level":"trace","@message":"Stderr is not a terminal","@timestamp":"2021-11-11T15:09:11.606921Z"}
{"@level":"trace","@message":"Stdin is not a terminal","@timestamp":"2021-11-11T15:09:11.607081Z"}
{"@level":"debug","@message":"Attempting to open CLI config file: /builds/backend.tmp/TF_CLI_CONFIG_FILE","@timestamp":"2021-11-11T15:09:11.607230Z"}
{"@level":"info","@message":"Loading CLI configuration from /builds/backend.tmp/TF_CLI_CONFIG_FILE","@timestamp":"2021-11-11T15:09:11.607468Z"}
{"@level":"debug","@message":"Not reading CLI config directory because config location is overridden by environment variable","@timestamp":"2021-11-11T15:09:11.607644Z"}
{"@level":"debug","@message":"ignoring non-existing provider search directory terraform.d/plugins","@timestamp":"2021-11-11T15:09:11.607776Z"}
{"@level":"debug","@message":"ignoring non-existing provider search directory /home/nonroot/.terraform.d/plugins","@timestamp":"2021-11-11T15:09:11.607885Z"}
{"@level":"debug","@message":"ignoring non-existing provider search directory /home/nonroot/.local/share/terraform/plugins","@timestamp":"2021-11-11T15:09:11.607936Z"}
{"@level":"debug","@message":"ignoring non-existing provider search directory /usr/local/share/terraform/plugins","@timestamp":"2021-11-11T15:09:11.608003Z"}
{"@level":"debug","@message":"ignoring non-existing provider search directory /usr/share/terraform/plugins","@timestamp":"2021-11-11T15:09:11.608038Z"}
{"@level":"info","@message":"TF_CLI_ARGS_init value: \"-lock-timeout=10m\"","@timestamp":"2021-11-11T15:09:11.608520Z"}
{"@level":"info","@message":"CLI command args: []string{\"init\", \"-lock-timeout=10m\", \"-no-color\"}","@timestamp":"2021-11-11T15:09:11.608558Z"}
Usage: terraform [global options] init [options]
  Initialize a new or existing Terraform working directory by creating
  initial files, loading any remote state, downloading modules, etc.
  This is the first command that should be run for any new or existing
  Terraform configuration per machine. This sets up all the local data
  necessary to run Terraform that is typically not committed to version
  control.
  This command is always safe to run multiple times. Though subsequent runs
  may give errors, this command will never delete your configuration or
  state. Even so, if you have important information, please back it up prior
  to running this command, just in case.

Hi @defropi,

I can see a log line in what you shared saying that you have TF_CLI_ARGS_init set to -lock-timeout=10m. I think the problem here is that terraform init no longer supports that option in Terraform v0.15.

Unfortunately there was a wrinkle here in that we removed it in Terraform v0.15 in preparation for the v1.0 release but then later found a use for it and re-introduced it, so there was a window of releases which didn’t have that option but the latest stable release actually does have it again.

Given that the 1.0.x series was just a renamed continuation of the 0.15.x series, you should be able to skip directly to v1.0.11 here, without an intermediate stop at v0.15.5, and thus you can avoid using any of the releases which lacked that option.

(With that said, it’s worth noting that the -lock-timeout option for terraform init only actually takes effect in the unusual case of a state migration between different backend configurations, so while there’s no harm in setting it for v1.0.11, it also may not be doing anything useful for you unless you are routinely migrating states between different backend configurations.)

1 Like

Thanks!
Indeed the -lock-timeout was the culprit, even on 1.0.6. bumped to 1.0.11 and remove it. Its working.