Terraform: Add [PATH] argument to taint command

Created on 30 Jun 2017  路  9Comments  路  Source: hashicorp/terraform

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.

enhancement

Most helpful comment

@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.

All 9 comments

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.

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.

@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.

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).

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

@jbardin any update on this?

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?

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

same thing for the import command

Was this page helpful?
0 / 5 - 0 ratings