title: How to resolve this "error archiving directory: could not archive missing directory"
body: <p>At the beginning of my project, there are two terraform modules: <code>base</code> and <code>reusable_module</code>.</p>
  
  <p><strong>base/main.tf</strong></p>
  
  <pre><code># Provide abstraction to define a lambda function
  terraform {
    required_version = "0.11.7"
  }
  
  variable "env" {}
  variable "role" {}
  variable "function_name" {
    default = ""
  }
  variable "lambda_filename" {}
  variable "script_env_vars" {
    type = "map"
  }
  
  data "archive_file" "package_zip" {
    type = "zip"
    # There is a bug in Terraform which does not allow '..' in source_dir, thus we use path.root:
    # https://github.com/terraform-providers/terraform-provider-archive/issues/5
    source_dir = "${path.root}/scripts/"  # Path from top level module.
    # The output path has to be relative. Otherwise the buildkite will always show a diff.
    output_path = "./.terraform/${var.env}-${var.lambda_filename}.zip"
  }
  
  resource "aws_lambda_function" "lambda" {
    function_name = "${var.function_name}"
    description = "Simple function"
    role = "${var.role}"
  
    runtime = "python3.6"
    timeout = 300  // seconds. Max hard limit is 5 min.
  
    filename = "${data.archive_file.package_zip.output_path}"
    // The handler is always the file name + function name "handler".
    handler = "${var.lambda_filename}.handler"
    source_code_hash = "${data.archive_file.package_zip.output_base64sha256}"
  
    // Environment variables for the script.
    environment {
      variables = "${var.script_env_vars}"
    }
  }
  </code></pre>
  
  <p><strong>reusable_module/main.tf</strong></p>
  
  <pre><code>variable "env" {}
  variable "region" {}
  variable "function_name" {}
  
  provider "aws" {
    region = "${var.region}"
  }
  
  resource "aws_iam_role" "mylambda_role" {
    name = "${var.env}-mylambda-role"
  
    assume_role_policy = &lt;&lt;EOF
  {
    "Version": "2012-10-17",
    "Statement": [
      {
        "Action": "sts:AssumeRole",
        "Principal": {
          "Service": "lambda.amazonaws.com"
        },
        "Effect": "Allow",
        "Sid": ""
      }
    ]
  }
  EOF
  }
  
  locals {
      default_function_name = "${var.env}-mylambda"
      final_function_name = "${var.function_name != "" ? var.function_name : local.default_function_name}"
  }
  
  module "mylambda" {
      source = "../base"
      lambda_filename = "mylambda"
      function_name = "${local.final_function_name}"
      env = "${var.env}"
      role = "${aws_iam_role.mylambda_role.arn}"
      script_env_vars = {
        DUMMY = "123"
      }
  }
  </code></pre>
  
  <p>Module <code>mylambda</code> uses <code>base/main.tf</code> to create a lambda function.</p>
  
  <p>Under <code>reusable_module</code>, there is a <code>scripts</code> directory where all the python scripts live.</p>
  
  <p>Now I want to extend my project by reusing and instantiating this <code>reusable_module/main.tf</code> for different teams.</p>
  
  <p><strong>team_template/main.tf</strong></p>
  
  <pre><code>variable "env" {}
  variable "region" {}
  variable "team" {}
  
  
  module "team_template" {
    source = "../reusable_module"
    env = "${var.env}"
    region = "${var.region}"
    function_name = "${var.team}-essential-function"
  }
  
  # More resources specific to team_template
  </code></pre>
  
  <p><strong>team-sales/main.tf</strong></p>
  
  <p>For creating a lambda per team</p>
  
  <pre><code>variable "env" {}
  variable "region" {}
  
  module "realdeal" {
    source = "../team_template"
    env = "${var.env}"
    region = "${var.region}"
    team = "sales"
  }
  # More stuff tailored for each teams
  </code></pre>
  
  <p>When I run <code>terraform plan -var-file=dev.tfvars</code> in team-sales, I got this error:</p>
  
  <blockquote>
    <p>data.archive_file.package_zip: Refreshing state...</p>
    
    <p>Error: Error refreshing state: 1 error(s) occurred:</p>
    
    <ul>
    <li><p>module.realdeal.module.team_template.module.mylambda.data.archive_file.package_zip:
    1 error(s) occurred:</p></li>
    <li><p>module.realdeal.module.team_template.module.mylambda.data.archive_file.package_zip:
    data.archive_file.package_zip: error archiving directory: could not
    archive missing directory:
    /Users/antkong/Documents/Personal/wd/StackoverflowCode/terraform/lambda/team/scripts/</p></li>
    </ul>
  </blockquote>
  
  <p>The problem is the <code>data.archive_file.package_zip</code> is looking for scripts in <code>team_template/scripts</code>. </p>
  
  <p>But in this case I actually have no python code in <code>team_template</code>. I simply want to continue to use the python code in <code>reusable_module/script</code>.</p>
  
  <p>The separation of files must be maintained. (Conway's law etc etc)</p>
  
  <p>How can I do it?</p>