Terraform v0.11.3
+ provider.aws v1.8.0
# aws-stack/backend.tf
terraform {
backend "s3" {
bucket = "my-project"
key = "state.tfstate"
region = "us-east-1"
}
}
# aws-stack/provider.tf
provider "aws" {
region = "us-east-1"
}
$ terraform output # or terraform output aws-stack/
~/Desktop/projects/my-project (master) $ terraform output
Backend reinitialization required. Please run "terraform init".
Reason: Unsetting the previously set backend "s3"
The "backend" is the interface that Terraform uses to store state,
perform operations, etc. If this message is showing up, it means that the
Terraform configuration you're using is using a custom configuration for
the Terraform backend.
Changes to backend configurations require reinitialization. This allows
Terraform to setup the new configuration, copy existing state, etc. This is
only done during "terraform init". Please run that command now then try again.
If the change reason above is incorrect, please verify your configuration
hasn't changed and try again. At this point, no changes to your existing
configuration or state have been made.
Failed to load backend: Initialization required. Please see the error message above.
Same for terraform output aws-stack/
It seems that command output does not recognize .tf files directory as a last argument (https://www.terraform.io/docs/commands/output.html). Other commands allow to pass configuration files directory as a last param like terraform apply aws-stack/
. Because it does not see any .tf files and in local state file there is already info about remote state it wants me to reinit. Reinitialization does not work (terraform init aws-stack/
works but issue with output command remains the same).
I guess this is because output is saved in local state file so there was not any purpose of passing .tf files to output command since it just prints data from local state file. However, It does not work when using remote state, as I described.
It seems that right now it's not possible to use output command when also using remote state?
@alekbarszczewski,
Yes, the output
command is in the group of commands that take string arguments, like taint
, import
, state *
, etc. which don't accept a directory argument.
Because terraform configures itself relative to the working directory, we highly encourage running terraform from within the target configuration directory, rather than with the legacy "directory" argument.
We hope to address a number of these issues together and do a general cleanup of the UI.
@jbardin thanks for info. Support for file like .terraformrc
inside the root project directory where user could define location of .tf files would be useful. I know that you support .terraformrc
file but AFAIK it must be located in user home directory and it's not possible to define .tf files location there.
getting similar issue when trying to use backend as storage for tfstate.
`"terraform" output public_ip_address -input=false -no-color d:\a\1\s/build2770.tfplan
The output command expects exactly one argument with the name
of an output variable or no arguments to show all outputs.
Usage: terraform output [options] [NAME]
Reads an output variable from a Terraform state file and prints
the value. With no additional arguments, output will display all
the outputs for the root module. If NAME is not specified, all
outputs are printed.
Options:
-state=path Path to the state file to read. Defaults to
"terraform.tfstate".`
running as part of pipeline so backend configured like below and stored is remote storage
-backend-config="key=ukwest.$(name_prefix).terraform.tfstate"
How can the output of the terraform apply for public ip address be retrieved from tfstate stored on backend ? I can see the IP in the output of the apply. require the ip address for next steps
@jbardin:
rather than with the legacy "directory" argument
Is this documented somewhere? Didn't know that the directory argument is "legacy" (slated for deprecation?)
Especially in 0.12, where terraform init -from-module=...
no longer supports initialization of a directory containing dot-files, this has proved useful workaround whereby we init a .module
folder. That means when we need to run terraform output
we need a way for it to work. It appears that by your comment this "works as designed" and will not be fixed. Is that the correct understanding?
@osterman
It's only deprecated in the sense that we don't actively suggest the usage, and there are commands and use cases which don't work using the directory argument. Terraform requires information stored in the current working directory, so there is less practical use for this argument because switching between directories can result in conflicting stored configuration forcing some level of re-initialization.
Yes, this is currently working as designed, and while there's a possibility that unifying the commands will result in the removal of that option, there could also eventually be some larger refactoring of how the CLI works to somehow facilitate working in other directories.
I'd vote for the latter. The directory argument is quite valuable and helps simplify workflows and project structures.
I have running into this issue. What is the status?
Also ran into this, and also using this workflow as it allows for easy re-use in terms of a folder structure for multiple environments.
@gsdevme @JWDobken the current status is that this issue has not been worked on. I do understand why it is frustrating. Can you please confirm to me what terraform versions you're running when you reproduce this? It sounded like this is still an issue in 0.12.x but it was originally filed against 0.11 so I want to make sure it's labeled correctly.
Hi,
Yes I'm using the latest 0.12.x. I've been resorting to just applying terraform even when I just want to see the output (not ideal but works)
Yes I am also using the latest 0.12.x and are seeing this issue. But I can't even run the apply to get the output due to this other bug!
https://github.com/terraform-providers/terraform-provider-aws/issues/9453
I am currently working with version 0.13.1. Same behavior here. My workaround is to move everything in one directory. Afterwards the terraform output
command is working as expected. Hopefully there will be a fix in the future.
Most helpful comment
I'd vote for the latter. The directory argument is quite valuable and helps simplify workflows and project structures.