Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Error "value of 'count' cannot be computed" #10

Closed
ghost opened this issue Jun 5, 2018 · 7 comments
Closed

Error "value of 'count' cannot be computed" #10

ghost opened this issue Jun 5, 2018 · 7 comments

Comments

@ghost
Copy link

ghost commented Jun 5, 2018

So I'm mostly copied the code from cloudwatch-alerts-to-slack example.
And I'm getting error:

Error: Error refreshing state: 1 error(s) occurred:

* module.notify_slack.data.aws_iam_policy_document.lambda: data.aws_iam_policy_document.lambda: value of 'count' cannot be computed

Here's the copied code:

resource "aws_kms_key" "this" {
  description = "KMS key for notify-slack test"
}

resource "aws_kms_alias" "this" {
  name          = "alias/kms-test-key"
  target_key_id = "${aws_kms_key.this.id}"
}

data "aws_kms_ciphertext" "slack_url" {
  # i'm aware this is wrong :)
  plaintext = "https://hooks.slack.com/services/AAA/BBB/CCC"
  # or?
  # key_id    = "${aws_kms_key.this.key_id}"
  key_id    = "${aws_kms_key.this.arn}"
}

module "notify_slack" {
  source = "terraform-aws-modules/notify-slack/aws"
  version = "1.3.0"

  sns_topic_name = "slack-topic"

  slack_webhook_url = "${data.aws_kms_ciphertext.slack_url.ciphertext_blob}"
  slack_channel     = "aws-notification"
  slack_username    = "reporter"

  kms_key_arn = "${aws_kms_key.this.arn}"
}

resource "aws_cloudwatch_metric_alarm" "LambdaDuration" {
  alarm_name          = "NotifySlackDuration"
  comparison_operator = "GreaterThanOrEqualToThreshold"
  evaluation_periods  = "1"
  metric_name         = "Duration"
  namespace           = "AWS/Lambda"
  period              = "60"
  statistic           = "Average"
  threshold           = "5000"
  alarm_description   = "Duration of notifying slack exceeds threshold"

  alarm_actions = ["${module.notify_slack.this_slack_topic_arn}"]

  dimensions {
    FunctionName = "${module.notify_slack.notify_slack_lambda_function_name}"
  }
}

Am I missing something?

@ghost
Copy link
Author

ghost commented Jun 18, 2018

It's something with Option 3 setup:

resource "aws_kms_key" "this" {
  description = "KMS key for notify-slack test"
}

resource "aws_kms_alias" "this" {
  name          = "alias/kms-test-key"
  target_key_id = "${aws_kms_key.this.id}"
}

// kms_key_arn = "${aws_kms_key.this.arn}"

becasue Option 1 works:

variable "kms_key_arn" {
  default = "arn:aws:kms:eu-west-1:835367859851:key/054b4846-95fe-4537-94f2-1dfd255238cf"
}

// kms_key_arn = "${var.kms_key_arn}"

@ghost
Copy link
Author

ghost commented Jun 18, 2018

The problem is with this line:

count = "${var.kms_key_arn == "" ? 0 : 1}"

because when I set the count to fixed 0 or 1 (and use this module as sources) like

data "aws_iam_policy_document" "lambda" {
  #count = "${var.kms_key_arn == "" ? 0 : 1}"
  count = 1 # or 0
  source_json = "${data.aws_iam_policy_document.lambda_basic.json}"

  statement {
..

Everything works

Related issue: hashicorp/terraform#17421

@antonbabenko
Copy link
Member

@xliiv sorry for the delay in my response.

Yes, HCL2 will have it fixed. Meanwhile, you have to specify key using any of available options (static var, data-source, or pass from tfvars, or from CLI). Everything will work except computed values (${aws_kms_key.this.arn}).

There is not much this module can do about it to keep in an easy-maintainable condition.

@ghost
Copy link
Author

ghost commented Jun 21, 2018

Does this mean that example doesn't work?
There is used ${aws_kms_key.this.arn}.

@antonbabenko
Copy link
Member

You are right, it does not work as it is now in that example. My bad.

I will make a PR now which will fix this.

antonbabenko added a commit that referenced this issue Jun 21, 2018
* Allow computed KMS key value (fixed #10)

* Fixed example with kms

* Fixed formatting
@antonbabenko
Copy link
Member

v1.9.0 has been released. I've updated examples there.

Thanks a lot for opening this issue!

@github-actions
Copy link

github-actions bot commented Nov 9, 2022

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 9, 2022
# for free to subscribe to this conversation on GitHub. Already have an account? #.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant