terraform-aws-notify-slack: Unable to load notify_slack.zip (no such file or directory)
When I run apply I have this error:
Error: Error applying plan:
1 error(s) occurred:
* module.databases.module.rds_notify_slack.module.notify_slack.aws_lambda_function.notify_slack: 1 error(s) occurred:
* aws_lambda_function.notify_slack: Unable to load ".terraform/modules/3a5c185cc1a32f4eca766d82a36b2ef2/functions/notify_slack.zip": open .terraform/modules/3a5c185cc1a32f4eca766d82a36b2ef2/functions/notify_slack.zip: no such file or directory
Terraform does not automatically rollback in the face of errors.
Instead, your Terraform state file has been partially updated with
any resources that successfully completed. Please address the error
above and apply again to incrementally change your infrastructure.
My module source is:
module "notify_slack" {
source = "git::https://github.com/terraform-aws-modules/terraform-aws-notify-slack?ref=tags/v1.10.0"
create = "${var.create}"
create_sns_topic = "${var.create_sns_topic}"
create_with_kms_key = "${var.create_with_kms_key}"
slack_webhook_url = "${var.slack_webhook_url}"
slack_channel = "${var.slack_channel}"
slack_username = "${var.slack_username}"
slack_emoji = "${var.slack_emoji}"
kms_key_arn = "${var.kms_key_arn}"
sns_topic_name = "${var.sns_topic_name}"
}
And I reference it using:
module "rds_notify_slack" {
source = "../notify_slack"
slack_webhook_url = "https://hooks.slack.com/services/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"
slack_channel = "aws-rds-backup"
slack_username = "aws-notify"
sns_topic_name = "${terraform.workspace}-rds-events"
create_sns_topic = true
}
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 8
- Comments: 16 (4 by maintainers)
Commits related to this issue
- notify-slack had a breaking change, using a workaround for now See https://github.com/terraform-aws-modules/terraform-aws-notify-slack/issues/21#issuecomment-565092931 — committed to simpledotorg/deployment by ssrihari 3 years ago
- Use a workaround for notify-slack breaking change (#366) See https://github.com/terraform-aws-modules/terraform-aws-notify-slack/issues/21#issuecomment-565092931 — committed to simpledotorg/deployment by ssrihari 3 years ago
I ran into this issue and found a permanent solution that doesn’t require modifying the module.
The issue is as @stephgosling describes. The module’s path is hard coded into the state. This is a problem because in the TF registry, each version of the module has a unique sha affixed path. So any time the module version changes, it will break. The only way to fix it, is to manually
terraform taintthe lambda function resource. Again, you must do this every time the module changes.However, this problem is caused exclusively by using the module via the terraform registry. Using any other module source (e.g. github) does not have this issue because the module path will not differ version to version, just the actual content (which is the only thing that matters)
So to fix this issue permanently:
source = "github.com/terraform-aws-modules/terraform-aws-notify-slack.git?ref=v2.4.0")terraform taint "<nested-resource-path>.module.notify_slack.aws_lambda_function.notify_slack[0]"Now if you change module version, it will update properly without manual intervention
In my opinion updating a module should never lead to a problem with a previously made state, this zipfile is the first i’ve seen that happen.
For folks running separate plan/applies in ephemeral CI/CD and not passing the .terraform directory between the two, this appears to be the cause of the issue.
FYI line 80 in main.tf is a moving target, I think you were referring to this specific version: https://github.com/terraform-aws-modules/terraform-aws-notify-slack/blob/1d2381abf0e0fc0a0159f06a3aba98b712520661/main.tf#L80
Removing
filenamefrom the lifecycle looks like this:And for what its worth that solved this problem for me as well. However it was added to address: https://github.com/terraform-aws-modules/terraform-aws-notify-slack/issues/6
I see, sometimes when you have to deal with existing (often corrupted) information in state file you can try these workarounds (starting from the easiest at the top):
-refresh=falseto prevent it from updating the state before planning changes.-target=module.databases.module.rds_notify_slack.module.notify_slack.aws_lambda_function.notify_slackto limit the scope of changes you want to plan and apply.terraform state pull, do changes,terraform state push. This is the most advanced way, so I put it at the end.Let’s see what @cgomestw thinks.