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

aborting a long running terraform apply operation results in empty state file #17282

Closed
matti opened this issue Feb 6, 2018 · 3 comments · Fixed by #17323
Closed

aborting a long running terraform apply operation results in empty state file #17282

matti opened this issue Feb 6, 2018 · 3 comments · Fixed by #17323
Assignees

Comments

@matti
Copy link

matti commented Feb 6, 2018

Terraform Version

0.11.3

Terraform Configuration Files

module "testing" {
  source = "github.com/matti/terraform-google-kubernetes-engine"

  settings = {
    region_name            = "europe-west1"
    zone_amount            = 1
    cluster_name           = "tf-testing"
    gke_min_master_version = "1.8.6-gke.0"
  }
}

# ------------ nodepool
locals {
  node_pool_common_settings = {
    cluster_name = "${module.testing.cluster_name}"
    cluster_zone = "${module.testing.cluster_zone}"

    machine_type = "n1-highcpu-4"
  }

  node_pool_default_settings = {
    name       = "default"
    node_count = 1
  }

  node_pool_scaling_settings = {
    name = "scaling"

    autoscaling_min_node_count = 0
    autoscaling_max_node_count = 3
  }
}

module "testing_node_pool" {
  source = "github.com/matti/terraform-google-kubernetes-node-pool"

  settings = "${merge(local.node_pool_common_settings, local.node_pool_default_settings)}"
}

module "testing_node_pool_autoscale" {
  source = "github.com/matti/terraform-google-kubernetes-node-pool"

  settings = "${merge(local.node_pool_common_settings, local.node_pool_scaling_settings)}"
}

Debug Output

I've made a repository that can be used to repro, it also contains trace: https://github.com/matti/terraform-repro-abort-empties-state

Expected Behavior

When the operation runs extremely long (and prob won't complete) I've hit ^C that prints out "Please wait for Terraform to exit or data loss may occur." - then after waiting some more I'm hitting ^C again. I don't think that the state file should not be empty after this.

Actual Behavior

State file is empty. Needs to restore from the backup.

Steps to Reproduce

I've made a repository that can be used to repro: https://github.com/matti/terraform-repro-abort-empties-state

This happens after the google_container_cluster and google_container_node_pool has been created. To repro this (100% success rate in my ~7 tests):

  1. Apply and wait for cluster and node pool to be created
  2. Change the number of nodes in google_container_node_pool or add a new node_pool
  3. Run apply again and let it run for couple of minutes and then ^C that forcefully.
  4. The state file is empty

Faster alternative:

  1. Apply and wait, hit ^C, hit ^C
  2. State file is empty, backup contains the initial state

References

@jbardin
Copy link
Member

jbardin commented Feb 7, 2018

Hi @matti,

Thanks for the reproduction case. Unfortunately I'm not able to reproduce this locally, and I'm not able to get your example to run correctly yet (though that is probably just inexperience with this provider on my part). The Google provider shouldn't be able to do anything specific on its own to cause the state to be empty, but my initial attempts at recreating this with a test provider never truncate the state to 0 bytes.

While I wrangle with my test account credentials, could you let me know what you mean by an "empty" state file? Does the state file contain a basic JSON structure but with no resource data, or is it completely empty file containing 0 bytes?

@matti
Copy link
Author

matti commented Feb 8, 2018

Completely empty containing 0 bytes.

@ghost
Copy link

ghost commented Apr 4, 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 4, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants