aws-samples / aws-security-reference-architecture-examples

Example solutions demonstrating how to implement patterns within the AWS Security Reference Architecture guide using CloudFormation (including Customizations for AWS Control Tower) and Terraform.
Other
965 stars 235 forks source link

[BUG] Installation issue with Terraform running on WSL (ubuntu) #217

Closed tantonjt-aws closed 3 months ago

tantonjt-aws commented 3 months ago

Describe the bug

While installing the common components using WSL(ubuntu), the packaging of the ssm_parameters lambda fails.

To Reproduce

Steps to reproduce the behavior:

  1. Go to {repo path} aws-security-reference-architecture-examples/aws_sra_examples/terraform/common
  2. Perform terraform init and then terraform apply
  3. See error

Expected behavior

A clear and concise description of what you expected to happen.

Screenshots

Plan: 11 to add, 0 to change, 1 to destroy. module.mangement_account_parameters.null_resource.package_lambda: Destroying... [id=7316659342117357428] module.mangement_account_parameters.null_resource.package_lambda: Destruction complete after 0s module.mangement_account_parameters.null_resource.package_lambda: Creating... module.mangement_account_parameters.null_resource.package_lambda: Provisioning with 'local-exec'... module.mangement_account_parameters.null_resource.package_lambda (local-exec): Executing: ["/bin/sh" "-c" " rm -rf ssm_parameters/lambda/package && mkdir ssm_parameters/lambda/package\r\n python3 -m pip install -r ./../../solutions/common/common_prerequisites/lambda/src/requirements.txt -t ssm_parameters/lambda/package\r\n cp ./../../solutions/common/common_prerequisites/lambda/src/*.py ssm_parameters/lambda/package/\r\n cd ssm_parameters/lambda/package\r\n zip -r ../lambda_function.zip .\r\n"] module.mangement_account_parameters.null_resource.package_lambda (local-exec): Collecting crhelper module.mangement_account_parameters.null_resource.package_lambda (local-exec): Using cached crhelper-2.0.11-py3-none-any.whl (14 kB) module.mangement_account_parameters.null_resource.package_lambda (local-exec): Installing collected packages: crhelper module.mangement_account_parameters.null_resource.package_lambda (local-exec): Successfully installed crhelper-2.0.11 module.mangement_account_parameters.null_resource.package_lambda (local-exec): cp: target 'ssm_parameters/lambda/package/'$'\r' is not a directory module.mangement_account_parameters.null_resource.package_lambda (local-exec): zip warning: name not matched: .

module.mangement_account_parameters.null_resource.package_lambda (local-exec): zip error: Nothing to do! (try: zip -r ../lambda_function.zip . -i . module.mangement_account_parameters.null_resource.package_lambda (local-exec): ) ╷ │ Error: local-exec provisioner error │ │ with module.mangement_account_parameters.null_resource.package_lambda, │ on ssm_parameters/main.tf line 38, in resource "null_resource" "package_lambda": │ 38: provisioner "local-exec" { │ │ Error running command ' rm -rf ssm_parameters/lambda/package && mkdir ssm_parameters/lambda/package │ python3 -m pip install -r ./../../solutions/common/common_prerequisites/lambda/src/requirements.txt -t ssm_parameters/lambda/package │ cp ./../../solutions/common/common_prerequisites/lambda/src/*.py ssm_parameters/lambda/package/ │ cd ssm_parameters/lambda/package │ zip -r ../lambda_function.zip . │ ': exit status 12. Output: Collecting crhelper │ Using cached crhelper-2.0.11-py3-none-any.whl (14 kB) │ Installing collected packages: crhelper │ Successfully installed crhelper-2.0.11 │ cp: target 'ssm_parameters/lambda/package/'$'\r' is not a directory │ zip warning: name not matched: . │ ) zip error: Nothing to do! (try: zip -r ../lambda_function.zip . -i . │ ╵ cp: target 'ssm_parameters/lambda/package/n' is not a directory zip warning: name not matched: .n

zip error: Nothing to do! (try: zip -r ../lambda_function.zip . -i .n)│

If applicable, add screenshots to help explain your problem.

Deployment Environment (please complete the following information)

Additional context

Add any other context about the problem here.

tantonjt-aws commented 3 months ago

Seems to append extra characters to package folder name. image

tantonjt-aws commented 3 months ago

The repo was cloned using CMD window and then the WSL window run the Terraform init/plan/apply. This was done to allow my environment to install required python libraries. This issue was resolved by doing a "git clone" on the WSL console and using my local home path ~/git/repo to execute the build.

I also had to do a 'terraform destroy' the failed attempt to cleanup and remove the Stackset "sra-stackset-execution-role" via the console.

tantonjt-aws commented 3 months ago

Issue has been resolved by using the correct build folder and git clone directly via WSL console.