claranet / terraform-aws-lambda

Terraform module for AWS Lambda functions
MIT License
157 stars 126 forks source link

1.3.0 generates perpetual diffs when switching platform #77

Closed maur1th closed 3 years ago

maur1th commented 3 years ago

We run terraform commands on both MacOS (dev) and Linux (CI). Since version 1.3.0 when a stack calling this module is applied in either environment it diffs in the other one and vice versa. Had to pin 1.2.0 to fix it.

I would guess this behavior is a result of https://github.com/claranet/terraform-aws-lambda/commit/6632b895bd7ee86316787646289d16f55f517763 @pdecat.

pdecat commented 3 years ago

Could you please share the diff?

pdecat commented 3 years ago

Also, what version of terraform are you using?

maur1th commented 3 years ago

Using Terraform v0.14.6

Plan:

Terraform will perform the following actions:

  # module.lambda.data.external.built will be read during apply
  # (config refers to values not yet known)
 <= data "external" "built"  {
      ~ id      = "-" -> (known after apply)
      ~ query   = {
          ~ "build_command"  = "python build.py 'builds/3c15bcba4c4fddd688c45bad2e0da27153e994ad79f2fcdfd54361544a6d9b08.zip' 'python3.8' '/Users/tmaurin/Projects/terraform-infra-master/stacks/infra-alerts/lambda'" -> "python build.py 'builds/299e64cecd19e5346548a8c4cd264dd4e21fc38c3f7f4554ed5f0a2c6a7ff665.zip' 'python3.8' '/var/lib/jenkins/workspace/terraform-check-staleness/stacks/infra-alerts/lambda'"
          ~ "filename_new"   = "builds/3c15bcba4c4fddd688c45bad2e0da27153e994ad79f2fcdfd54361544a6d9b08.zip" -> "builds/299e64cecd19e5346548a8c4cd264dd4e21fc38c3f7f4554ed5f0a2c6a7ff665.zip"
          ~ "filename_old"   = "builds/3c15bcba4c4fddd688c45bad2e0da27153e994ad79f2fcdfd54361544a6d9b08.zip" -> "builds/299e64cecd19e5346548a8c4cd264dd4e21fc38c3f7f4554ed5f0a2c6a7ff665.zip"
            # (1 unchanged element hidden)
        }
      ~ result  = {
          - "filename" = ".terraform/modules/lambda/builds/3c15bcba4c4fddd688c45bad2e0da27153e994ad79f2fcdfd54361544a6d9b08.zip"
        } -> (known after apply)
        # (1 unchanged attribute hidden)
    }

  # module.lambda.aws_lambda_function.lambda will be updated in-place
  ~ resource "aws_lambda_function" "lambda" {
      ~ filename                       = ".terraform/modules/lambda/builds/3c15bcba4c4fddd688c45bad2e0da27153e994ad79f2fcdfd54361544a6d9b08.zip" -> (known after apply)
        id                             = "slack-infra-alerts"
      ~ last_modified                  = "2021-03-01T13:12:32.335+0000" -> (known after apply)
        tags                           = {
            "Application" = "infra-alerts"
            "Environment" = "staging"
            "Owner"       = "infrastructure"
            "Terraform"   = "true"
        }
        # (17 unchanged attributes hidden)

        # (2 unchanged blocks hidden)
    }

  # module.lambda.null_resource.archive must be replaced
-/+ resource "null_resource" "archive" {
      ~ id       = "104670142214346646" -> (known after apply)
      ~ triggers = { # forces replacement
          ~ "filename" = "builds/3c15bcba4c4fddd688c45bad2e0da27153e994ad79f2fcdfd54361544a6d9b08.zip" -> "builds/299e64cecd19e5346548a8c4cd264dd4e21fc38c3f7f4554ed5f0a2c6a7ff665.zip"
        }
    }

Plan: 1 to add, 1 to change, 1 to destroy.
pdecat commented 3 years ago

Note: https://github.com/claranet/terraform-aws-lambda/commit/6632b895bd7ee86316787646289d16f55f517763 is not part of https://github.com/claranet/terraform-aws-lambda/commits/v1.3.0 release

pdecat commented 3 years ago

Could you pin to 1.3.0 and retry?

maur1th commented 3 years ago

Well that did seem to fix it. That was unexpected. Thanks!

pdecat commented 3 years ago

Removing the pin, could you please inspect the generated zip files on both platforms and compare their contents to locate the actual diff?

They should be located in .terraform/modules/your-lambda-module/builds/*.zip.

pdecat commented 3 years ago

On second thought, my guess is that you did not run terraform init -upgrade on both platforms without the version pin. Pinning enforces re-init.

maur1th commented 3 years ago

I'm not able to reproduce anymore. So that's likely it. Thanks for the quick responses!