Skip to content

Instantly share code, notes, and snippets.

@tongueroo
Created March 9, 2021 21:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tongueroo/5e64bdc6d2fd74d71520d294a20f32e8 to your computer and use it in GitHub Desktop.
Save tongueroo/5e64bdc6d2fd74d71520d294a20f32e8 to your computer and use it in GitHub Desktop.

Reproduction of issue where .terraform.lock.hcl loses info with terraform version v0.14.4

$ terraspace clean all -y
Removed .terraspace-cache
Removed /tmp/terraspace
Removing all files in log/
Logs removed
$ TS_ENV=dev terraspace plan project
Building .terraspace-cache/us-central1/dev/stacks/project
Built in .terraspace-cache/us-central1/dev/stacks/project
Current directory: .terraspace-cache/us-central1/dev/stacks/project
=> terraform init -get -input=false >> /tmp/terraspace/log/init/project.log
Syncing to Terraform Cloud: project => demo-project-dev
=> terraform plan -input=false
Running plan in the remote backend. Output will stream here. Pressing Ctrl-C
will stop streaming the logs, but will not stop the plan running remotely.

Preparing the remote plan...

The remote workspace is configured to work with configuration at
.terraspace-cache/us-central1/dev/stacks/project relative to the target repository.

Terraform will upload the contents of the following directory,
excluding files or directories as defined by a .terraformignore file
at /home/ec2-user/environment/qa/terraspace-demo-bug/.terraformignore (if it is present),
in order to capture the filesystem context the remote workspace expects:
    /home/ec2-user/environment/qa/terraspace-demo-bug

To view this run in a browser, visit:
https://app.terraform.io/app/demo-qa/demo-project-dev/runs/run-bAgw4C95jSbA1gd1

Waiting for the plan to start...

Terraform v0.14.4
Configuring remote state backend...
Initializing Terraform configuration...

An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:
  + create

Terraform will perform the following actions:

  # module.project.random_id.random_project_id_suffix will be created
  + resource "random_id" "random_project_id_suffix" {
      + b64         = (known after apply)
      + b64_std     = (known after apply)
      + b64_url     = (known after apply)
      + byte_length = 2
      + dec         = (known after apply)
      + hex         = (known after apply)
      + id          = (known after apply)
    }

Plan: 1 to add, 0 to change, 0 to destroy.
$ TS_ENV=staging terraspace plan project
Building .terraspace-cache/us-central1/staging/stacks/project
Built in .terraspace-cache/us-central1/staging/stacks/project
Current directory: .terraspace-cache/us-central1/staging/stacks/project
=> terraform init -get -input=false >> /tmp/terraspace/log/init/project.log
Syncing to Terraform Cloud: project => demo-project-staging
=> terraform plan -input=false
Running plan in the remote backend. Output will stream here. Pressing Ctrl-C
will stop streaming the logs, but will not stop the plan running remotely.

Preparing the remote plan...

The remote workspace is configured to work with configuration at
.terraspace-cache/us-central1/staging/stacks/project relative to the target repository.

Terraform will upload the contents of the following directory,
excluding files or directories as defined by a .terraformignore file
at /home/ec2-user/environment/qa/terraspace-demo-bug/.terraformignore (if it is present),
in order to capture the filesystem context the remote workspace expects:
    /home/ec2-user/environment/qa/terraspace-demo-bug

To view this run in a browser, visit:
https://app.terraform.io/app/demo-qa/demo-project-staging/runs/run-bvHRqG821Xh3Nf8w

Waiting for the plan to start...

Terraform v0.14.4
Configuring remote state backend...
Initializing Terraform configuration...

An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:
  + create

Terraform will perform the following actions:

  # module.project.random_id.random_project_id_suffix will be created
  + resource "random_id" "random_project_id_suffix" {
      + b64         = (known after apply)
      + b64_std     = (known after apply)
      + b64_url     = (known after apply)
      + byte_length = 2
      + dec         = (known after apply)
      + hex         = (known after apply)
      + id          = (known after apply)
    }

Plan: 1 to add, 0 to change, 0 to destroy.
$ find .terraspace-cache -name '.terraform.lock.hcl'
.terraspace-cache/us-central1/dev/stacks/project/.terraform.lock.hcl
.terraspace-cache/us-central1/staging/stacks/project/.terraform.lock.hcl
$ cat .terraspace-cache/us-central1/dev/stacks/project/.terraform.lock.hcl
# This file is maintained automatically by "terraform init".
# Manual edits may be lost in future updates.

provider "registry.terraform.io/hashicorp/google" {
  version = "3.59.0"
  hashes = [
    "h1:7x2UH/RLmpk0NXJx5fu38hi0bQYauzobNuedKZCJmFk=",
    "zh:1210d60719470b32d979390a73fa2405ceb9702f2728854cac3c3804bf774442",
    "zh:1e0cec25c527cd09d94ddcea55522e3d75a600745f3d8cd46296e610dde41abf",
    "zh:3eff1094a52a680d044ed8182ca1b70a8a509e4200fd89deae220b21503832a2",
    "zh:604c5fdb7d15268e4a5210cfcc5630f34c9a0a06d8ef5f6f3a93513aad278e11",
    "zh:6c02ff804cfa2fd7dda4c090f06ee999ce6fed2bc7fe408fa3ba312d57b64d56",
    "zh:8954c3691d665f44ed7bda1c7f5d02f4980698657b6518b4445842f80c146481",
    "zh:8e1f53a315341285b04aa50dda086be1f84d02ab92a9f4a3875e648374829a7b",
    "zh:e0b1f047f65a8403ea16157d4f3f8492d4b23ceab85b939f2bcd368e2d8f0252",
    "zh:f795a80a734d7730fe0b876f16705964a80bd155925aecc60026c0e8dab145ca",
    "zh:ffdcdebaabc34467db790a8c3e769fa6e44f580e4a162de1ad4f7156e54064fd",
  ]
}

provider "registry.terraform.io/hashicorp/random" {
  version     = "2.3.1"
  constraints = "~> 2.2"
  hashes = [
    "h1:bPBDLMpQzOjKhDlP9uH2UPIz9tSjcbCtLdiJ5ASmCx4=",
    "zh:322ec2b56765162c193d0ff0f7634351bf4ca09d719558df82b92d31059995a1",
    "zh:34c500857d14148bc6f7f21f9fc0d832ba31d00e1b911b0437d99dda29aeb108",
    "zh:a3372514add474fcb07d2026a49b0c0d8a699e365f540e43e5f590eb924b95f7",
    "zh:a54acd50f13f38a86454acad16b3487701608188fd2cc454fd48beee00127ae5",
    "zh:b1285c47ab01fc11b6086f080da7d17b9155b3fac6a4175948a2abb5d52c60af",
    "zh:c7e7bd46218cf504ca31d8a1e4eab5cad625c9951fb89d4f56861d5bddec9afb",
    "zh:d9f95764480d7b884db7247a5ee9d1c72aaf1c1cde3d7b5e34bc33c4ef5ccf48",
    "zh:ddf11fb807d61ff93c08206733129bf9668fc0c4adedf8a6ac38a7c382a24b35",
    "zh:f631a0c1ffa94991d87cd5fe4e08c0dd6d36c780585f35a582c05ee2affb7e86",
    "zh:fb5f5fb19e8a9ff73dbdee85a97f548099e480497a7a1f4ca4725c83db300b8d",
  ]
}
$ cat .terraspace-cache/us-central1/staging/stacks/project/.terraform.lock.hcl
# This file is maintained automatically by "terraform init".
# Manual edits may be lost in future updates.

provider "registry.terraform.io/hashicorp/google" {
  version = "3.59.0"
  hashes = [
    "h1:7x2UH/RLmpk0NXJx5fu38hi0bQYauzobNuedKZCJmFk=",
  ]
}

provider "registry.terraform.io/hashicorp/random" {
  version     = "2.3.1"
  constraints = "~> 2.2"
  hashes = [
    "h1:bPBDLMpQzOjKhDlP9uH2UPIz9tSjcbCtLdiJ5ASmCx4=",
  ]
}
$ terraspace --version
0.6.2
$ terraform --version
Terraform v0.14.4

Your version of Terraform is out of date! The latest version
is 0.14.7. You can update by downloading from https://www.terraform.io/downloads.html
$
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment