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

Error using on the bucket that does not exist yet. #63

Open
mikhail-khodorovskiy opened this issue Oct 1, 2019 · 10 comments
Open

Error using on the bucket that does not exist yet. #63

mikhail-khodorovskiy opened this issue Oct 1, 2019 · 10 comments
Assignees
Labels
bug Something isn't working P3 medium priority issues triaged Scoped and ready for work

Comments

@mikhail-khodorovskiy
Copy link

resource "google_storage_bucket" "logsinc_bucket_tools" {
  name    = "${var.environment_name}-log-sink"
  project = data.google_project.tools_project.project_id
}

module "logsinc_bucket_iam_bindings" {
  source  = "terraform-google-modules/iam/google//modules/storage_buckets_iam"
  version = "~> 3.0"

  storage_buckets = [google_storage_bucket.logsinc_bucket_tools.id]

  mode = "additive"

  bindings = {
    "roles/storage.objectCreator" = [
      "group:[email protected]",
    ]

    "roles/storage.objectViewer" = [
      "group:[email protected]",
    ]
  }
}

Causes an error:

Error: Invalid count argument

on .terraform/modules/hsq-uat.logsinc_bucket_iam_bindings/terraform-google-modules-terraform-google-iam-ace2efe/modules/storage_buckets_iam/main.tf line 45, in resource "google_storage_bucket_iam_member" "storage_bucket_iam_additive":
45: count = var.bindings_num > 0 ? var.bindings_num * local.additive * local.storage_bucket_count : length(local.bindings_formatted) * local.additive

@aaron-lane aaron-lane added the bug Something isn't working label Oct 9, 2019
@mikhail-khodorovskiy
Copy link
Author

Any progress on that - it's prevents us from using the module when the bucket is first created.

@morgante
Copy link
Contributor

This is unfortunately a bit of a bug in Terraform.

However, I believe we can make this work for the singular case where only a single bucket is being managed (using the same approach as projects).

@cray0000 please take this on.

@morgante morgante added triaged Scoped and ready for work P3 medium priority issues labels Dec 10, 2019
@cray0000
Copy link
Contributor

cray0000 commented Dec 10, 2019

Sure, @morgante

I think this should already be working without additional work though. Even though there is a separate option to specify one project, it's not being used to make the configuration behave in a static way.

One can already specify only a single element to the array of entities and in this case it will ignore it when doing the for_each (which is replacing the old count we used for iam in version 3.0 which @mikhail-khodorovskiy is getting an error about).

At least it behaves this way in the static-and-dynamic unit tests, which are testing this same dynamically created resources for projects

@mikhail-khodorovskiy I'm going to add a similar test for the dynamically created bucket to confirm whether it's working or not and will let you know. In case it doesn't, I'll try to find a workaround.

@cray0000 cray0000 self-assigned this Dec 10, 2019
@morgante
Copy link
Contributor

Good point. @mikhail-khodorovskiy It's probably also worth upgrading to version 5.0 and seeing if that fixes your problems.

@mikhail-khodorovskiy
Copy link
Author

I tried, it did not.

@mikhail-khodorovskiy
Copy link
Author

Actually I have a different error:

Terraform v0.12.8
+ provider.external v1.2.0
+ provider.google v2.13.0
+ provider.google-beta v2.13.0
+ provider.null v2.1.2
+ provider.random v2.1.2

Error: Invalid for_each argument

The "for_each" 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 for_each depends on.

@mikhail-khodorovskiy
Copy link
Author

Even for the existing bucket when I migrate 2.20.0 google provider to 3.5.0 google provider I get the same error even on existing buckets in both adaptive and authoritative modes.

@morgante
Copy link
Contributor

Were you not getting this error before?

@pcasteran
Copy link

pcasteran commented Jan 29, 2020

Same issue here with a configuration declaring a custom role and using the module (version 5.1.0) to create IAM bindings to it:

Error: Invalid for_each argument

  on .terraform\modules\project-iam-bindings\terraform-google-modules-terraform-google-iam-01965a1\modules\projects_iam\main.tf line 44, in resource "google_project_iam_member" "project_iam_additive":
  44:   for_each = module.helper.set_additive

The "for_each" 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 for_each depends on.

@mikhail-khodorovskiy
Copy link
Author

I filed a different issue regarding this since this seems unrelated: #92.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working P3 medium priority issues triaged Scoped and ready for work
Projects
None yet
Development

No branches or pull requests

5 participants