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

0.12 depends_on deleted from resources during destroying #21497

Closed
kustodian opened this issue May 28, 2019 · 1 comment · Fixed by #23252
Closed

0.12 depends_on deleted from resources during destroying #21497

kustodian opened this issue May 28, 2019 · 1 comment · Fixed by #23252
Assignees
Labels
bug core v0.12 Issues (primarily bugs) reported against v0.12 releases

Comments

@kustodian
Copy link

Terraform 0.12 removes depends_on from state file on resources that failed to delete. I'm not sure if that is exactly the problem, but it looks like that is the issue.

Terraform Version

Terraform v0.12.0
+ provider.google v2.7.0
+ provider.google-beta v2.7.0
+ provider.template v2.1.2

Terraform Configuration Files

In my main.tf I have this code which calls a module:

module "infrastructure" {
  source      = "../../../modules/structure-team"
  common_vars = local.common_vars
  team_name   = "Team1"
  team_prefix = "t1"
  admins      = ["group:t1-admins@example.com"]
  users       = ["group:t1-users@example.com"]
}

And in that module at the top we have:

# Create folders
resource "google_folder" "top_level" {
  display_name = var.team_name
  parent       = "${var.parent_type}s/${var.common_vars["org_id"]}"
}

resource "google_folder" "prod" {
  display_name = "Prod"
  parent       = google_folder.top_level.name
}

resource "google_folder" "test" {
  display_name = "Test"
  parent       = google_folder.top_level.name
}

resource "google_folder" "dev" {
  display_name = "Dev"
  parent       = google_folder.top_level.name
}

Which basically creates a top level folder and in it Prod, Test and Dev folders. After this there is more configuration that creates projects, etc, but that is not that important for this problem. So if I comment out the structure-team from main.tf and run terraform apply it should deleted all those folders and everything in them, but what happens is that folders Prod, Test and Dev don't get deleted (I guess its because of the same issue which I'm describing here). Then if I run apply again it TF tells me that it's going to delete these 4 folders because there is nothing else left, but what happens is that TF tries to delete all 4 folders at the same time, so deleting the top level folder fails and I have to run apply one more time so that it gets deleted.

What I found out is that in the state file this happens. Here is the Dev folder before running the first apply:

    {
      "module": "module.infrastructure",
      "mode": "managed",
      "type": "google_folder",
      "name": "dev",
      "provider": "provider.google",
      "instances": [
        {
          "schema_version": 0,
          "attributes": {
            "create_time": "2019-05-28T22:04:37.968Z",
            "display_name": "Dev",
            "id": "folders/45671841531",
            "lifecycle_state": "ACTIVE",
            "name": "folders/45671841531",
            "parent": "folders/467376871904"
          },
          "depends_on": [
            "google_folder.top_level"
          ]
        }
      ]
    },

As you can see there is a depends_on, but after I run the first apply, this Dev folder looks like this:

    {
      "module": "module.infrastructure",
      "mode": "managed",
      "type": "google_folder",
      "name": "dev",
      "provider": "provider.google",
      "instances": [
        {
          "schema_version": 0,
          "attributes": {
            "create_time": "2019-05-28T22:04:37.968Z",
            "display_name": "Dev",
            "id": "folders/45671841531",
            "lifecycle_state": "ACTIVE",
            "name": "folders/45671841531",
            "parent": "folders/467376871904"
          }
        }
      ]
    },

For some reason depends_on is removed.

Expected Behavior

TF should have deleted all 4 folders in the correct order.

Actual Behavior

TF tries to deleted them all at the same time, even though they have implicit dependencies.

Steps to Reproduce

Not 100% sure, because by just creating these 4 folders is not enough for TF to fail with this.

Additional Context

What is very interesting is that if I run terraform destroy on everything, all gets deleted without any issues. But by just deleting part of the code and running apply, it fails.

@hashibot hashibot added the v0.12 Issues (primarily bugs) reported against v0.12 releases label Aug 22, 2019
@jbardin jbardin self-assigned this Nov 6, 2019
@ghost
Copy link

ghost commented Mar 29, 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 Mar 29, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug core v0.12 Issues (primarily bugs) reported against v0.12 releases
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants