Giter VIP home page Giter VIP logo

Comments (16)

tophercullen avatar tophercullen commented on July 26, 2024 9

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 taint the 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:

  1. Change module source from terraform registry to github (e.g. source = "github.com/terraform-aws-modules/terraform-aws-notify-slack.git?ref=v2.4.0")
  2. Manually taint the resource e.g. terraform taint "<nested-resource-path>.module.notify_slack.aws_lambda_function.notify_slack[0]"
  3. Run terraform plan/apply

Now if you change module version, it will update properly without manual intervention

from terraform-aws-notify-slack.

walterheck avatar walterheck commented on July 26, 2024 5

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.

from terraform-aws-notify-slack.

ndarwincorn avatar ndarwincorn commented on July 26, 2024 2

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.

from terraform-aws-notify-slack.

antonbabenko avatar antonbabenko commented on July 26, 2024 1

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):

  1. Append -refresh=false to prevent it from updating the state before planning changes.
  2. Append -target=module.databases.module.rds_notify_slack.module.notify_slack.aws_lambda_function.notify_slack to limit the scope of changes you want to plan and apply.
  3. Use terraform taint within a module.
  4. If you don't mind doing surgery on json file (which is often not needed), you can use 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.

from terraform-aws-notify-slack.

rraub avatar rraub commented on July 26, 2024 1

I just ran into the same issue, fixed by removing this line:
https://github.com/terraform-aws-modules/terraform-aws-notify-slack/blob/master/main.tf#L80

FYI line 80 in main.tf is a moving target, I think you were referring to this specific version:

Removing filename from the lifecycle looks like this:

  lifecycle {
    ignore_changes = [
      "last_modified",
    ]
  }

And for what its worth that solved this problem for me as well. However it was added to address: #6

from terraform-aws-notify-slack.

stephgosling avatar stephgosling commented on July 26, 2024

@cgomestw had you just upgraded/re-get'd the module? I've just seen the same behaviour as you and it's because my state had an hard-coded path to that zip file that no longer matched the hash for the module. If you edit your state file to use the correct hash you can then successfully apply the module.

There does appear to be a breaking change in there at some point in the past. My local module here (written on the 28th of April 2018) was referencing this version in the state:

b3572a382f5c288bd459b66424b0ae78/terraform-aws-modules-terraform-aws-notify-slack-5cdd039/ 

which corresponds to this commit or version 1.1.0 of the module from what I can see.

from terraform-aws-notify-slack.

walterheck avatar walterheck commented on July 26, 2024

@antonbabenko this is biting us also, any chance it can be fixed?

from terraform-aws-notify-slack.

cgomestw avatar cgomestw commented on July 26, 2024

from terraform-aws-notify-slack.

antonbabenko avatar antonbabenko commented on July 26, 2024

@walterheck I'd like to help, but I don't know how. Example code works, I've just run https://github.com/terraform-aws-modules/terraform-aws-notify-slack/tree/master/examples/notify-slack-simple and it works as expected.

Can you try the low-level fix and see whether it helps - rm -rf .terraform && terraform init?

@cgomestw If you can investigate and fix the problem it would very nice.

from terraform-aws-notify-slack.

walterheck avatar walterheck commented on July 26, 2024

@antonbabenko it has something to do with first having an older version fo the module, running terraform apply to write it to state, then updating the module and seeing the error.

rm -rf .terraform doesn't work as the statefile has an entry that mentions a path for the zip file, but once you upgrade the module the path in the statefile goes to the old directory and that doesn't exist anymore.

I got around it with a slightly different fix then @stephgosling: I created the old directory it was looking for manually and copied the slack_notify.zip file there. Pretty nasty, but it saved me from having to edit a remote terraform state file for a prod environment. Hope this gives more insight?

from terraform-aws-notify-slack.

RupertExact avatar RupertExact commented on July 26, 2024

We are having the same issue. But it doesn't always happen on every apply. Sometimes it works, sometimes it doesn't. We almost never change the code that calls or uses the module so it's not like there's a change that causes the issue.And we do have other terraformed lambda functions that don't cause this issue.
Just in case it was an issue with the way the file gets called, I re-wrote that part but without any success

resource "aws_lambda_function" "notify_slack" {
  count = "${var.create}"

  filename = "functions/notify_slack.zip"

  function_name = "${var.lambda_function_name}"

  role             = "${aws_iam_role.lambda.arn}"
  handler          = "notify_slack.lambda_handler"
  source_code_hash = "${base64sha256(file("${path.module}/functions/notify_slack.zip"))}"

from terraform-aws-notify-slack.

ldormoy avatar ldormoy commented on July 26, 2024

I just ran into the same issue, fixed by removing this line:
https://github.com/terraform-aws-modules/terraform-aws-notify-slack/blob/master/main.tf#L80

from terraform-aws-notify-slack.

richardj-bsquare avatar richardj-bsquare commented on July 26, 2024

I just ran into the same issue, fixed by removing this line:
https://github.com/terraform-aws-modules/terraform-aws-notify-slack/blob/master/main.tf#L80

Confirmed, thanks!

from terraform-aws-notify-slack.

noqqe avatar noqqe commented on July 26, 2024

Also affected by this issue all the time. Been using this module since years, always the same problem. Frustrating.

from terraform-aws-notify-slack.

antonbabenko avatar antonbabenko commented on July 26, 2024

Please give a try v3.0.0 which has been just released. There I use a new dedicated Lambda module, which has a lot of improvements when working with Lambda resources.

Closing this issue. Please open a new one if you find any issues with v3.0+

from terraform-aws-notify-slack.

github-actions avatar github-actions commented on July 26, 2024

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.

from terraform-aws-notify-slack.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.