1
resposta

Error: Error acquiring the state lock

Estava recebendo o seguinte erro ao executar "terraform init"

gabrielamorim@Gabriels-MacBook-Air 03-terraform % terraform init 

Initializing the backend...
╷
│ Error: Error acquiring the state lock
│ 
│ Error message: resource not found
│ 
│ Terraform acquires a state lock to protect the state from being written
│ by multiple users at the same time. Please resolve the issue above and try
│ again. For most commands, you can disable locking with the "-lock=false"
│ flag, but this is not recommended.

Ao executar o mesmo comando, utilizando o "-lock=false", recebia a seguinte mensagem de erro:

gabrielamorim@Gabriels-MacBook-Air 03-terraform % terraform init -lock=false

Initializing the backend...
Do you want to copy existing state to the new backend?
  Pre-existing state was found while migrating the previous "local" backend to the
  newly configured "remote" backend. No existing state was found in the newly
  configured "remote" backend. Do you want to copy this state to the new "remote"
  backend? Enter "yes" to copy and "no" to start with an empty state.

  Enter a value: yes

╷
│ Error: Error copying state from the previous "local" backend to the newly configured 
│ "remote" backend:
│     Error uploading state: Conflict
│ 
│ This workspace is not locked and will only accept state uploads
│ when locked
│ 
│ The state in the previous backend remains intact and unmodified. Please resolve
│ the error above and try again.
│ 
│ 
╵

Solução: eu havia criado o Organization Token, não o User Tokens. O Organization token chega a criar o workspace, então passa a falsa impressão de que não é ali o problema.

O endereço correto para criar seu token de usuário é: https://app.terraform.io/app/settings/tokens

Fiquem atentos! ;-)

1 resposta

Olá, Gabriel. Tudo bem?

Obrigado por compartilhar seu problema e a solução!

Bons estudos!

Quer mergulhar em tecnologia e aprendizagem?

Receba a newsletter que o nosso CEO escreve pessoalmente, com insights do mercado de trabalho, ciência e desenvolvimento de software