Closed shazi57 closed 1 year ago
Hi, thanks for opening this issue. I can reproduce your issue where Terraform is not able to find the correct folder once it reaches our custom Makefile solution. This seems to be related to how we prepare the artifacts for SAM CLI since we copy the current directory to a scratch folder. In your case, this will end up missing the modules/lambda
folder. Let me consult with some team members for some next steps.
This is currently a limitation of our Terraform integration. Our artifact script expects all project assets and resources to be within the project folder. You can see some more discussion within our Terraform discussion thread: https://github.com/aws/aws-sam-cli/discussions/4553#discussioncomment-4745959
As a potential workaround for now, you can try moving your modules/lambda
folder to be under environments/dev
if it is possible for your project.
yeah this is kind of a big deal. Its very common to want to have multiple modules and different build targets in a single repo
+1 for me
Any updates?
I am getting a similar error although with a slightly different error message. aws sam
is unable to detect the root directory of the project and instead defaults to C:\Users\user\AppData
. I am on windows, using go
1.20
.
My error message is:
Error: CustomMakeBuilder:MakeBuild - Make Failed: Copy/Unzip unsuccessful!
Traceback (most recent call last):
File "C:\Users\<user>\AppData\Local\Temp\<tmp_folder>\.aws-sam-iacs\iacs_metadata\copy_terraform_built_artifacts.py", line 259, in find_and_copy_assets
copytree(abs_attribute_path, directory_path)
File "C:\Users\<user>\AppData\Local\Temp\<tmp_folder>\.aws-sam-iacs\iacs_metadata\copy_terraform_built_artifacts.py", line 194, in copytree
for item in os.listdir(src):
NotADirectoryError: [WinError 267] The directory name is invalid: 'C:\\Users\\<user>\\AppData\\Local\\Temp\\<tmp_folder>\\bin\\subscription\\main'
make.exe[1]: *** [build-AwsLambdaFunctionFnSubscription45C9D248] Error 1
make: *** [sam] Error 1
Any Updates?
I agree with another thread and this thread, an existing production release would look more like the below for a standard python application.
/project
/infrastructure
envrionment/
dev/
dev.tfvars
test/
test.tfvars
main.tf
providers.tf
/src
... (lambda code) ...
/tests
... (lambda tests) ...
I am surprised though, that if the original_source_code is declared in the metadata that this could not simply be pulled through as a provisional requirement during the sam build process. i guess it just a thought.
resource "null_resource" "sam_metadata_..." {
triggers = {
original_source_code = original_source_code
}
}
Another process could be adding it to the samconfig.toml
as an include
parameter.
version = 0.1
[default]
[default.build.parameters]
hook_name = "terraform"
beta_features = true
I think all things possible, but it would be good to see a more supportive approach for structured repositories and multi environment deployments. The work around for exporting TF_ARGS can work for now, but it would be nice to declare a backend and default tf_file to.
Hey, We released a feature in latest SAM CLI release to support the Terraform project that has a nested directories structure like the following:
/project
/infrastructure
main_mondule
main.tf
providers.tf
other_modules
module1
module2
.....
/src
... (lambda code) ...
You can run sam build
from the main_module directory, and add the new property --terraform-project-root-path
and set its value to be a relative path to the project root directory like ./../..
or the absolute path, so the command will look like
sam build --hook-name terraform --beta-features --terraform-project-root-path ./../..
Please try the new feature, and let us know your feedback.
closing this issue, as this feature got released in SAM CLI version 1.96.0. Please open new issues if you have any new requests.
Comments on closed issues are hard for our team to see. If you need more assistance, please either tag a team member or open a new issue that references this one. If you wish to keep having a conversation with other community members under this issue feel free to do so.
Description:
Relative paths provided in the source for modules throw errors when sam build command is run.
Steps to reproduce:
Observed result:
Expected result:
Expected it to build functions without an issue because running terraform init in the root directory doesn't cause any issue.
Additional environment details (Ex: Windows, Mac, Amazon Linux etc)