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

Facing an issue while using the custom workspace from default #1861

Closed
Jenishk56 opened this issue Oct 15, 2021 · 2 comments
Closed

Facing an issue while using the custom workspace from default #1861

Jenishk56 opened this issue Oct 15, 2021 · 2 comments
Labels
bug Something isn't working

Comments

@Jenishk56
Copy link

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request. Searching for pre-existing feature requests helps us consolidate datapoints for identical requirements into a single place, thank you!
  • Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for issue followers and do not help prioritize the request.
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment.

�[31m│�[0m �[0m�[1m�[31mError: �[0m�[0m�[1mBackend initialization required, please run "terraform init"�[0m
�[31m│�[0m �[0m
�[31m│�[0m �[0m�[0mReason: Initial configuration of the requested backend "gcs"
�[31m│�[0m �[0m
�[31m│�[0m �[0mThe "backend" is the interface that Terraform uses to store state,
�[31m│�[0m �[0mperform operations, etc. If this message is showing up, it means that the
�[31m│�[0m �[0mTerraform configuration you're using is using a custom configuration for
�[31m│�[0m �[0mthe Terraform backend.
�[31m│�[0m �[0m
�[31m│�[0m �[0mChanges to backend configurations require reinitialization. This allows
�[31m│�[0m �[0mTerraform to set up the new configuration, copy existing state, etc. Please
�[31m│�[0m �[0mrun
�[31m│�[0m �[0m"terraform init" with either the "-reconfigure" or "-migrate-state" flags
�[31m│�[0m �[0mto
�[31m│�[0m �[0muse the current configuration.
�[31m│�[0m �[0m
�[31m│�[0m �[0mIf the change reason above is incorrect, please verify your configuration
�[31m│�[0m �[0mhasn't changed and try again. At this point, no changes to your existing
�[31m│�[0m �[0mconfiguration or state have been made.
�[31m╵�[0m�[0m
�[0m�[0m```
This is how the atlantis.yaml configuration looks like
  • name: xyz
    dir: xyz
    workflow: xyz
    workspace: xyz
    terraform_version: 0.13.7

xyz:
plan:
steps:
- run: "terraform workspace new $WORKSPACE || true; rm -rf .terraform/"=
- init:
extra_args: ["-lock=false", "-reconfigure"]
- plan:
extra_args: ["-lock=false"]
apply:
steps:
- apply:
extra_args: ["-lock=false"]


### Overview of the Issue

I was using the `default` workspace and recently started using the custom workspace, e.g. `xyz`
I have copied the state file in the gcs bucket from `default.tfstate` to `xyz.tfstate`
It works fine from the local system while using the workspace `xyz`. While using the atlantis, I see above weird output. 
However, Atlantis plan and apply works fine but I don't want to see that irrelevant output in my plan. 

I am using Terraform `0.13.7`
@Jenishk56 Jenishk56 added the bug Something isn't working label Oct 15, 2021
@ganeshk1928
Copy link

@Jenishk56 I too ran into trouble when switching from default to a new workspace. This is because atlantis is setting the TF_WORKSPACE env. There is a PR open #1578 to fix this. Meanwhile instead of running terraform workspace new $WORKSPACE || true; rm -rf .terraform/" you can unset the TF_WORKSPACE env variable in your atlantis.yalm file. I'm adding my sample atlantis.yaml file here.

version: 3
projects:
- name: project-1
  dir: .
  workspace: staging
  autoplan:
    when_modified: ["*.tf"]
    enabled: false
  apply_requirements: [mergeable, approved]
  workflow: default
workflows:
  default:
    plan:
      steps:
      - env:
          name: TF_WORKSPACE
          value:
      - init
      - plan:
          extra_args: ["-var-file", "common.tfvars"]
    apply:
      steps:
      - run: echo "Performing Terraform apply"
      - env:
          name: TF_WORKSPACE
          value:
      - apply

@jamengual
Copy link
Contributor

fixed in #2006

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants