boltops-tools / terraspace

Terraspace: The Terraform Framework
https://terraspace.cloud
Apache License 2.0
674 stars 46 forks source link

Pass-File not working for modules, only stacks #221

Open silasmahler opened 2 years ago

silasmahler commented 2 years ago

Checklist

My Environment

Software Version
Operating System osx
Terraform 1.1.7
Terraspace 1.1.7
Ruby ruby 2.6.8p205 (2021-07-07 revision 67951) [universal.x86_64-darwin21]

Expected Behaviour

As stated in the docs the pass file folder "files" (either in modules or stacks) shall be used to place files that will be used from the terraform code e.g. for aws_instance user_data or provisioners. https://terraspace.cloud/docs/config/pass-files/

It's not working correctly.

When calling terraspace up mystack the provisioner or file-function cant find the file, even thought the cache structure is just fine, one can clearly see the files which work in a normal environment flawlessly.

Current Behavior

When put in module:

│ Error: Invalid function argument │ │ on ../../modules/testmodule/main.tf line 9, in resource "aws_instance" "server": │ 9: user_data = file("files/test.sh") │ │ Invalid value for "path" parameter: no file exists at "files/test.sh"; this │ function works only with files that are distributed as part of the │ configuration source code, so if this file will be created by a resource in │ this configuration you must instead obtain this result from an attribute of │ that resource.

In a stack however all the files are copied without the need for any folder, then they are magically picked up on the root folder of the stack, but then i don't need the feature of file passing, that id like to use.

Code Sample

Not working:

Not Working: (This is module code)

resource "aws_instance" "server" {
  ami                         = var.server_ami
  instance_type                          = var.server_instance_type
  key_name                                 = aws_key_pair.key.key_name
  associate_public_ip_address = var.server_associate_public_ip_address
  vpc_security_group_ids          = [aws_security_group.security_group.id]
  subnet_id                                  = var.subnet_id
  user_data                                  = file("./files/test.sh")
}

Working: (This is module code)

resource "aws_instance" "server" {
  ami                         = var.server_ami
  instance_type                          = var.server_instance_type
  key_name                                 = aws_key_pair.key.key_name
  associate_public_ip_address = var.server_associate_public_ip_address
  vpc_security_group_ids          = [aws_security_group.security_group.id]
  subnet_id                                  = var.subnet_id
  user_data                                  = file("../../stacks/demo/test.sh")
}