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

Missing provider failure case leaves s3 lock in place #23318

Closed
joe-bowman opened this issue Nov 8, 2019 · 3 comments · Fixed by #24120
Closed

Missing provider failure case leaves s3 lock in place #23318

joe-bowman opened this issue Nov 8, 2019 · 3 comments · Fixed by #24120
Assignees
Labels
bug cli v0.12 Issues (primarily bugs) reported against v0.12 releases

Comments

@joe-bowman
Copy link

Terraform v0.12.13
+ provider.aws v2.34.0
+ provider.google v2.18.1
+ provider.template v2.1.2
+ provider.vault v2.2.0

Terraform Configuration Files

Attempt to use a Google Cloud resource without a relevant provider being declared

Expected Behavior

Lock should be removed in event of failure case.

Actual Behavior

Error on terraform import (correct)

Error: provider.google-beta: no suitable version installed
  version requirements: "(any version)"
  versions installed: none

And next operation:

Error: Error locking state: Error acquiring the state lock: ConditionalCheckFailedException: The conditional request failed
	status code: 400, request id: SL3JPK86NVLJITHD2I5E6D9PHJVV4KQNSO5AEMVJF66Q9ASUAAJG
Lock Info:
  ID:        53b7efb8-a7a7-a0c3-f55f-73aee25c8472
  Path:      [redacted].tfstate
  Operation: OperationTypeInvalid
  Who:       [email protected]
  Version:   0.12.13
  Created:   2019-11-08 10:55:32.551892 +0000 UTC
  Info:

Lock never gets releases after the import failure.

Steps to Reproduce

  1. Create a state stored in s3
  2. Create a new google resource, without a appropriate provider
  3. Run (in my case terraform import on the google resource.
@hashibot hashibot added bug cli v0.12 Issues (primarily bugs) reported against v0.12 releases labels Nov 8, 2019
@alisdair
Copy link
Contributor

Thanks for filing this! I was able to confirm this behaviour with 0.12.20. My reproduction steps:

  1. Create main.tf:

    resource null_resource example {
      count = 1
    
      triggers = {
        index = count.index
      }
    }
    
    # resource example_resource whatever {}
    
    terraform {
      backend "s3" {
        bucket = "your-bucket"
        key = "remote-state/tf-example"
        region = "us-east-1"
        dynamodb_table = "your-dynamodb-table"
      }
    }
  2. terraform init, terraform apply to create a state version

  3. Uncomment the example resource

  4. terraform import example_resource.whatever abc123 to trigger a missing provider error

This last step fails and leaves a dangling lock.

@alisdair alisdair self-assigned this Feb 14, 2020
alisdair added a commit that referenced this issue Feb 14, 2020
If an error occurs on creating the context for console or import, we
would fail to unlock the state. Fix this by unlocking slightly earlier.
Affects console, graph, and import commands.

Fixes #23318
alisdair added a commit that referenced this issue Feb 14, 2020
If an error occurs on creating the context for console or import, we
would fail to unlock the state. Fix this by unlocking slightly earlier.
Affects console and import commands.

Fixes #23318
alisdair added a commit that referenced this issue Feb 14, 2020
If an error occurs on creating the context for console or import, we
would fail to unlock the state. Fix this by unlocking slightly earlier.
Affects console and import commands.

Fixes #23318
@alisdair
Copy link
Contributor

Thanks for reporting this issue! A fix has been merged and will be part of the next 0.12 release.

@ghost
Copy link

ghost commented Apr 1, 2020

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 and limited conversation to collaborators Apr 1, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug cli v0.12 Issues (primarily bugs) reported against v0.12 releases
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants