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

TF 0.13 bug with The "count" value depends on resource attributes that cannot be determined until apply #26579

Closed
bharathkkb opened this issue Oct 14, 2020 · 3 comments
Labels
bug new new issue not yet triaged

Comments

@bharathkkb
Copy link
Contributor

Terraform Version

0.13.4

Terraform Configuration Files

  • Apply this config which will fail due to machine_type = "foo"
provider "google" {
  version = "~> 3.42.0"
  project  = var.project
}

variable "project" {
    type = string
}

resource "google_project_service" "container_api" {
  service                    = "container.googleapis.com"
  disable_on_destroy         = false
  disable_dependent_services = false
}

resource "google_container_cluster" "primary" {
  name     = "my-gke-cluster-1"
  location = "us-central1-a"
  remove_default_node_pool = true
  initial_node_count       = 1
  depends_on = [google_project_service.container_api]
}

resource "google_container_node_pool" "pools" {
  count = 2
  name       = "my-node-pool"
  location   = "us-central1-a"
  cluster    = google_container_cluster.primary.name
  node_count = 1
  node_config {
    machine_type = "foo"
  }
}

resource "random_pet" "pets" {
count = length([for pool in google_container_node_pool.pools : pool.name])
}
  • Subsequent terraform apply fails with
The "count" value depends on resource attributes that cannot be determined
until apply, so Terraform cannot predict how many instances will be created.
To work around this, use the -target argument to first apply only the
resources that the count depends on.

Debug Output

Crash Output

N/A

Expected Behavior

Plan should be successful as it is in 0.12.29

Actual Behavior

The "count" value depends on resource attributes that cannot be determined
until apply, so Terraform cannot predict how many instances will be created.
To work around this, use the -target argument to first apply only the
resources that the count depends on.

Steps to Reproduce

Listed above

Additional Context

For 0.13.4 using

terraform apply -refresh=false 

which bypasses the initial refresh seems to be a workaround.

References

x-ref: terraform-google-modules/terraform-google-kubernetes-engine#690
Might be related to

@bharathkkb bharathkkb added bug new new issue not yet triaged labels Oct 14, 2020
@Gael101
Copy link

Gael101 commented Oct 14, 2020

I do have the same behaviour when running "terraform destroy"on this resource

resource "aws_efs_mount_target" "efs_target" {
    count = local.subnet_count
    file_system_id = aws_efs_file_system.efs.id
    subnet_id      = element(data.terraform_remote_state.vpc_state.outputs.private_subnet_id, count.index)
    security_groups = [data.terraform_remote_state.sg_state.outputs.sg_back_web_id]
}
subnet_count="${length(data.terraform_remote_state.vpc_state.outputs.private_subnet_id)}"

From what i'm seeing in the console , the mount targets were destroyed during the destroy of the below resource

resource "aws_efs_file_system" "efs" {
    creation_token = "${local.project_name}-${local.workspace}-efs"
    tags = {
        project_name   = local.project_name
        env            = local.workspace
    }
}

But this should not rise an error

@jbardin
Copy link
Member

jbardin commented Oct 14, 2020

Thanks @bharathkkb

The fact that -refresh=false confirms that this is something resolved by the changes in 0.14. There will no longer be a separate refresh phase internally, and this type of skew between configuration and state should no longer be a factor.

Thanks!

@ghost
Copy link

ghost commented Nov 14, 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 as resolved and limited conversation to collaborators Nov 14, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug new new issue not yet triaged
Projects
None yet
Development

No branches or pull requests

3 participants