Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Terraform provider data archive #76

Open
Ramneekkhurana opened this issue Jul 6, 2020 · 1 comment
Open

Terraform provider data archive #76

Ramneekkhurana opened this issue Jul 6, 2020 · 1 comment

Comments

@Ramneekkhurana
Copy link

Hi there,

I am trying to dynamically build go code from source code, zip it and create a lambda out of it. Problem starts because we do not want to keep binaries with IAC code and hence build and archive has to happen in terraform dynamically but terraform data resource causes issues as described below.

Terraform Version

Terraform v0.12.24

  • provider.archive v1.3.0
  • provider.aws v2.67.0
  • provider.helm v1.2.3
  • provider.kubernetes v1.11.3
  • provider.local v1.4.0
  • provider.null v2.1.2
  • provider.random v2.2.1
  • provider.template v2.1.2

Affected Resource(s)

Please list the resources as a list, for example:

  • null_resource.builder
  • null_data_resource.wait_for_builder
  • data.archive_file.zip_file

If this issue appears to affect multiple resources, it may be an issue with Terraform's core, so please mention this.

Terraform Configuration Files

resource "null_resource" "builder" {
  count = var.enabled == true ? 1 : 0

  triggers = {
    generated_hash = filemd5("${path.module}/lambda/eks-monitor/main.go")
  }

  provisioner "local-exec" {
    working_dir = "${path.module}/lambda/eks-monitor"
    command     = "go build main.go"
  }

}

data "null_data_source" "wait_for_builder" {
  count = var.enabled == true ? 1 : 0

  inputs = {
    # This ensures that this data resource will not be evaluated until
    # after the null_resource has been created.
    builder_id = null_resource.builder.0.id

    # This value gives us something to implicitly depend on
    # in the archive_file below.
    source_file = "${path.module}/lambda/eks-monitor/main"
  }
}


data "archive_file" "zip_file" {
  count = var.enabled == true ? 1 : 0

  type        = "zip"
  source_file = data.null_data_source.wait_for_builder.0.outputs["source_file"]
  output_path = "${path.module}/lambda/eks-monitor/main.zip"
}

Expected Behavior

Ideally data should know that it's archive_file and should not try to run it during refresh.

Actual Behavior

During the refresh it runs again and causes an issue because null_resource has built the file once and during second run binary doesn't exist ( we use Jenkins to deploy and worker nodes underneath keep changing and binary file is not there during the seond run.

So I get this error

Error: error archiving file: could not archive missing file: ../modules/aws-eks-add-on/aws-eks-monitor/lambda/eks-monitor/main

on ../modules/aws-eks-add-on/aws-eks-monitor/lambda.tf line 58, in data "archive_file" "zip_file":
58: data "archive_file" "zip_file" {

Steps to Reproduce

Please list the steps required to reproduce the issue, for example:

  1. terraform apply
  2. Make sure main and main.zip is deleted because that's where the issue starts ( build and deploy environments are dynamic container and do not store dynamically build artifacts )
  3. terraform apply again
@ranmeekkhsc
Copy link

Can someone please help

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants