awscc Terraform provider changing the lambda file structure on terraform apply

I am simply trying to deploy a sample awscc lambda function using the code as below - reference- Terraform Registry

my main.tf-

# Copyright (c) HashiCorp, Inc.
# SPDX-License-Identifier: MPL-2.0


terraform {
  required_version = ">= 0.12"
}

provider "aws" {
region = var.aws_region
}

provider "awscc" {
region = var.aws_region
}


resource "awscc_iam_role" "main" {
  description = "AWS IAM role for lambda function"
  assume_role_policy_document = jsonencode({
    Version = "2012-10-17"
    Statement = [
      {
        Action = "sts:AssumeRole"
        Effect = "Allow"
        Sid    = ""
        Principal = {
          Service = "lambda.amazonaws.com"
        }
      },
    ]
  })
}

data "archive_file" "main" {
  type        = "zip"
  source_file = "main.py"
  output_path = "lambda_function_payload.zip"
}

resource "awscc_lambda_function" "main" {
  function_name = "lambda_function_name"
  description   = "AWS Lambda function"
  code = {
    zip_file = data.archive_file.main.output_path
  }
  package_type  = "Zip"
  handler       = "main.lambda_handler"
  runtime       = "python3.10"
  timeout       = "300"
  memory_size   = "128"
  role          = awscc_iam_role.main.arn
  architectures = ["arm64"]
}

The lambda creates and runs fine when I use inline code in my main.tf. but I want to be able to use a zip file that is located in the same folder as my main.tf. As soon as I do terraform apply and my lambda gets created, I see in the lambda console that the file is now -

is there any solution or workaround for this?

(lambda_function_payload.zip is the name of my zipfile that is in the same folder as main.tf. It only contains one file which is main.py)

I want to be able to deploy the lambda using the zip file using the awscc provider. I tried the same thing using the aws provider and it works file.

I think the zip_file reference is incorrect. I will update that in a PR. The way I would handle this is via an S3 bucket reference.

data "archive_file" "main" {
  type        = "zip"
  source_file = "index.py"
  output_path = "index.zip"
}
resource "awscc_s3_bucket" "lambda_assets" {
}

resource "aws_s3_object" "zip" {
  source = data.archive_file.main.output_path
  bucket = awscc_s3_bucket.lambda_assets.id
  key    = "index.zip"
}

resource "awscc_lambda_function" "main" {
  function_name = "main"
  description   = "AWS Lambda function"
  code = {
    s3_bucket = awscc_s3_bucket.lambda_assets.id
    s3_key    = aws_s3_object.zip.key
  }
  package_type  = "Zip"
  handler       = "index.handler"
  runtime       = "python3.10"
  timeout       = "300"
  memory_size   = "128"
  role          = awscc_iam_role.main.arn
  architectures = ["arm64"]
}

Okay, so you mean to say that the way I can create the zipfile within the main.tf and reference it in lambda ‘code’ in the aws terraform provider, I cannot do the same way here?

That is right. The zip_file on the service schema refers to zipping an inline code reference to upload to lambda compared to the aws provider.