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

Add [PATH] argument to taint command #15447

Closed
spanktar opened this issue Jun 30, 2017 · 11 comments
Closed

Add [PATH] argument to taint command #15447

spanktar opened this issue Jun 30, 2017 · 11 comments
Assignees

Comments

@spanktar
Copy link

Terraform Version

0.9.6-0.9.10

We use subdirectories to isolate AWS Accounts (not environments) so they can have their own state and tfvars files. I cannot seem to get taint to work in this setup.

Expected Behavior

terraform taint some.resource .. should taint the resource

Actual Behavior

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.

Important Factoids

Remote state in S3, backend properly initialized. Running terraform apply .. works fine.

I have tried to use the -state flag like so, to no avail:

terraform taint -state=FOLDER/.terraform/terraform.tfstate some.resource in the root directory where all the terraform files are. Same issue.

@spanktar
Copy link
Author

spanktar commented Jul 5, 2017

I've tried multiple variants on using -state from different locations to no avail. I've resorted to temporarily moving my state directory into the root and manually passing the path to ENV/terraform.tfvars, which is needless to say, inconvenient.

@jbardin
Copy link
Member

jbardin commented Jul 5, 2017

Terraform creates its initialization structures relative to the current working directory where you run terraform init. Running terraform outside of this directory will prevent it from finding the files it needs to use a backend or in upcoming releases, even find providers.

You should always run terraform from within the directory where you ran init.

You should also note that .terraform/terraform.tfstate does not contain any of your resources. While it happens to share the state structure to store some related configuration details, it is not your state, and should not be manipulated as such.

@jbardin
Copy link
Member

jbardin commented Jul 5, 2017

@spanktar,

After re-reading this, it appears that you're expecting taint to have a PATH argument, which it does not. That might be something we can add to make it work more like plan and apply.

@jbardin jbardin changed the title Can't taint from subdirectory Add [PATH] argument to taint command Jul 5, 2017
@spanktar
Copy link
Author

spanktar commented Jul 5, 2017

Yes, that's exactly what I'm saying :) thanks!

And yes, we are running from the directory we ran init in. That directory is a subdirectory of the root (which contains all of the TF files).

@spanktar
Copy link
Author

spanktar commented Jul 6, 2017

Same goes for all commands that don't take a path. Just ran across output also not working in this fashion.

@lig
Copy link

lig commented Mar 23, 2018

@jbardin any update on this?

@markgossa
Copy link

I also have the same problem with terraform output running from the same directory as terraform init, plan, apply which all worked fine. I am using remote state and could copy down the state file but this isn't ideal.

Is there any update on this?

@rafik-eh
Copy link

Hi,
I am currently having the same initialization problem using a different Terraform workspace layout.
My workspace is as follow:

my_workspace/
  |-- resources/
  |     |-- rds.tf
  |     |-- ecs.tf
  |     |-- ....tf
  |
  |-- env1/
  |     |-- variables.tfvars
  |
  |-- env2/
  |     |-- variables.tfvars

At every deployment, I run:

# 1- I cd to the environment folder
cd my_workspace/envX/

# 2- I init everytime using a script so that if someone clones the repo, everything will be automated even if my environment already exist
terraform init -backend=true ....  ../resources

# 3- from the same folder I run a taint to make sure I got my environment variables recreated
terraform taint -module=../resources  null_resource.ansible

The last one fails with the same error:

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.

I assume that is related to the variables.tfstate file not being read.

Any help on this one?

Thanks

@samuel-begin
Copy link

same thing for the import command

@jbardin
Copy link
Member

jbardin commented Mar 9, 2021

Hello all!

This is now handled globally by the -chdir= flag, since path arguments are no longer supported.

Thanks!

@jbardin jbardin closed this as completed Mar 9, 2021
@ghost
Copy link

ghost commented Apr 9, 2021

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@ghost ghost locked as resolved and limited conversation to collaborators Apr 9, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

6 participants