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: Invalid count argument" when access_logs_s3_bucket_id is set #114

Open
razorsedge opened this issue Apr 29, 2022 · 1 comment
Open
Labels
bug 🐛 An issue with the system

Comments

@razorsedge
Copy link

razorsedge commented Apr 29, 2022

Describe the Bug

Similar to #103. When access_logs_s3_bucket_id = "bucketname" is set on this module, it produces the following error:

Error: Invalid count argument

  on .terraform/modules/alb.access_logs.s3_bucket/main.tf line 163, in resource "aws_s3_bucket_policy" "default":
 163:   count      = module.this.enabled && (var.allow_ssl_requests_only || var.allow_encrypted_uploads_only || var.policy != "") ? 1 : 0

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.

Expected Behavior

It should produce a valid plan.

Steps to Reproduce

Steps to reproduce the behavior:

  1. Run init and apply on the .tf file below
  2. The first time this runs, it says there are no changes, but each subsequent apply, will yield the error above
  3. Run apply again
  4. See error

Environment (please complete the following information):

$ terraform version
Terraform v0.13.7
+ provider registry.terraform.io/hashicorp/aws v3.74.2

Additional Context

Here's a simple .tf file to reproduce the issue

variable "vpc_id" {
  type        = string
  description = "The VPC ID"
}

variable "subnet_ids" {
  type        = list(string)
  description = "The Subnet IDs"
  default     = []
}

variable "bucket_id" {
  type        = string
  description = "The S3 Bucket ID"
}

variable "security_group_ids" {
  type        = list(string)
  description = "The Security Group IDs"
}

module "label" {
  source    = "cloudposse/label/null"
  version   = "0.25.0"
  namespace = "my"
  name      = "alb"
  stage     = "test"
}

module "alb" {
  source  = "cloudposse/alb/aws"
  version = "1.0.0"

  context    = module.label.context
  subnet_ids = var.subnet_ids
  vpc_id     = var.vpc_id

  access_logs_s3_bucket_id                = var.bucket_id
  access_logs_prefix                      = "${module.label.namespace}"
  alb_access_logs_s3_bucket_force_destroy = true
  deletion_protection_enabled             = true
  target_group_port                       = 8080
  internal                                = true
  health_check_path                       = "/health"
  target_group_name                       = module.label.id # Needed as our default name is too long.
  drop_invalid_header_fields              = true
  security_group_enabled                  = false
  security_group_ids                      = var.security_group_ids
}
@razorsedge razorsedge added the bug 🐛 An issue with the system label Apr 29, 2022
@sahotay
Copy link

sahotay commented Aug 3, 2022

I am facing the same issue, is there a workaround for this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 An issue with the system
Projects
None yet
Development

No branches or pull requests

2 participants