Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Provider produced inconsistent final plan in github actions pipeline #158

Closed
@jack-dunleavy

Description

@jack-dunleavy

Description

I'm seeing an issue deploying a lambda function using Github actions CI/CD. Specifically we have the pipeline set up to perform terraform plan, store the output, then run terraform apply in a later step. The issue appears to be due to the source_code_hash attribute that is calculated during plan not matching the hash during apply:

│ Error: Provider produced inconsistent final plan
│ 
│ When expanding the plan for module.test_lambda.aws_lambda_function.this[0] to include new values learned so far during apply, provider "registry.terraform.io/hashicorp/aws" produced an invalid new value for .source_code_hash:
│ was cty.StringVal("3mMv+AOi71OKcWRJFwQpJodzz13sdQ8U+W1DLqYnS+8="), but now cty.StringVal("L60e+m5YKaMuYvyjOS+J0HlXynS/xy072jqcLlArcY8=").
│ 
│ This is a bug in the provider, which should be reported in the provider's own issue tracker.

Versions

Terraform v0.15.1
on darwin_amd64

  • provider registry.terraform.io/hashicorp/aws v3.44.0
  • provider registry.terraform.io/hashicorp/external v2.1.0
  • provider registry.terraform.io/hashicorp/local v2.1.0
  • provider registry.terraform.io/hashicorp/null v3.1.0
  • provider registry.terraform.io/hashicorp/random v3.1.0

Reproduction

Steps to reproduce the behavior:

Are you using workspaces? : No

I think this is to do with the source files being checked out twice (once for plan and again for apply) and so having different metadata in each of the phases. I've been able to reproduce this issue locally by performing the following steps:

  1. Run terraform plan: TF_RECREATE_MISSING_LAMBDA_PACKAGE=false terraform plan -out sandbox.plan
  2. Create a copy of the lambda handler: cp src/index.js src/index_1.js
  3. Delete the lambda handler: rm src/index.js
  4. Rename the copy: mv src/index_1.js src/index.js
  5. Run terraform apply: TF_RECREATE_MISSING_LAMBDA_PACKAGE=false terraform apply sandbox.plan

Code Snippet to Reproduce

main.tf

module "test_lambda" {
  source  = "terraform-aws-modules/lambda/aws"
  version = "2.0.0"

  function_name              = "test-lambda"
  handler                           = "index.handler"
  runtime                           = "nodejs14.x"
  publish                           = true
  cloudwatch_logs_retention_in_days = 90

  source_path = "./src"
}

providers.tf

terraform {
  required_providers {
    aws = {
      source  = "hashicorp/aws"
      version = "~> 3.40"
    }
  }
}

provider "aws" {
  region = "eu-west-2"
}

src/index.js

exports.handler = async (event) => {
  return event;
};

Expected behavior

The new lambda is applied by Terraform

Actual behavior

The new lambda deployment fails with Error: Provider produced inconsistent final plan

Terminal Output Screenshot(s)

Screenshot 2021-06-07 at 12 23 20
Screenshot 2021-06-07 at 12 43 41

Additional context

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions