terraform-google-modules / terraform-example-foundation

Shows how the CFT modules can be composed to build a secure cloud foundation
https://cloud.google.com/architecture/security-foundations
Apache License 2.0
1.23k stars 721 forks source link

Bootstrap - CRLF line endings in entrypoint.bash leads to failing Cloud Build job due to no such file or directory error #694

Closed harrytsee closed 2 years ago

harrytsee commented 2 years ago

TL;DR

When deploying the CFT Bootstrap (step 0) locally on a Windows machine to a fresh organisation the following error occurs during the Cloud Build submit step after running the terraform apply:

module.cloudbuild_bootstrap.null_resource.cloudbuild_terraform_builder (local-exec): Step #1: Already have image: [europe-west2-docker.pkg.dev/prj-b-cicd-c727/prj-tf-runners/terraform](http://europe-west2-docker.pkg.dev/prj-b-cicd-c727/prj-tf-runners/terraform)
module.cloudbuild_bootstrap.null_resource.cloudbuild_terraform_builder (local-exec): Step #1: standard_init_linux.go:228: exec user process caused: no such file or directory
module.cloudbuild_bootstrap.null_resource.cloudbuild_terraform_builder (local-exec): Finished Step #1
module.cloudbuild_bootstrap.null_resource.cloudbuild_terraform_builder (local-exec): ERROR
module.cloudbuild_bootstrap.null_resource.cloudbuild_terraform_builder (local-exec): ERROR: build step 1 "[europe-west2-docker.pkg.dev/prj-b-cicd-c727/prj-tf-runners/terraform](http://europe-west2-docker.pkg.dev/prj-b-cicd-c727/prj-tf-runners/terraform)" failed: step exited with non-zero status: 1
module.cloudbuild_bootstrap.null_resource.cloudbuild_terraform_builder (local-exec): --------------------------------------------------------------------------------
╷
│ Error: local-exec provisioner error
│
│   with module.cloudbuild_bootstrap.null_resource.cloudbuild_terraform_builder,
│   on .terraform\modules\cloudbuild_bootstrap\modules\cloudbuild\[main.tf](http://main.tf/) line 194, in resource "null_resource" "cloudbuild_terraform_builder":
│  194:   provisioner "local-exec" {
│
│ Error running command '      gcloud builds submit .terraform/modules/cloudbuild_bootstrap/modules/cloudbuild/cloudbuild_builder/ --project prj-b-cicd-c727
│ --config=.terraform/modules/cloudbuild_bootstrap/modules/cloudbuild/cloudbuild_builder/cloudbuild.yaml
│ --substitutions=_TERRAFORM_VERSION=0.13.7,_TERRAFORM_VERSION_SHA256SUM=4a52886e019b4fdad2439da5ff43388bbcc6cce9784fde32c53dcd0e28ca9957,_TERRAFORM_VALIDATOR_RELEASE=v0.6.0,_REGION=europe-west2,_REPOSITORY=prj-tf-runners

[...]

│ Step #0: Step 12/12 : ENTRYPOINT ["/builder/entrypoint.bash"]
│ Step #0:  ---> Running in 83aaa6d5192e
│ Step #0: Removing intermediate container 83aaa6d5192e
│ Step #0:  ---> 77e0355a169d
│ Step #0: Successfully built 77e0355a169d
│ Step #0: Successfully tagged [europe-west2-docker.pkg.dev/prj-b-cicd-c727/prj-tf-runners/terraform:latest](http://europe-west2-docker.pkg.dev/prj-b-cicd-c727/prj-tf-runners/terraform:latest)
│ Finished Step #0
│ Starting Step #1
│ Step #1: Already have image: [europe-west2-docker.pkg.dev/prj-b-cicd-c727/prj-tf-runners/terraform](http://europe-west2-docker.pkg.dev/prj-b-cicd-c727/prj-tf-runners/terraform)
│ Step #1: standard_init_linux.go:228: exec user process caused: no such file or directory
│ Finished Step #1
│ ERROR
│ ERROR: build step 1 "[europe-west2-docker.pkg.dev/prj-b-cicd-c727/prj-tf-runners/terraform](http://europe-west2-docker.pkg.dev/prj-b-cicd-c727/prj-tf-runners/terraform)" failed: step exited with non-zero status: 1
│ --------------------------------------------------------------------------------

Solution:

Update entrypoint bash to LF by default or add documentation to troubleshooting steps to update entrypoint.bash CRLF end of line conversion to LF following these steps for any "no such file or directory" errors.

Expected behavior

Successful terraform apply following run, this error should not occur as is all steps are executed following instructions and run from an up to date clone of the repo.

Observed behavior

Key Errors:

(local-exec): Step #1: standard_init_linux.go:228: exec user process caused: no such file or directory

│ Error: local-exec provisioner error
│
│   with module.cloudbuild_bootstrap.null_resource.cloudbuild_terraform_builder,
│   on .terraform\modules\cloudbuild_bootstrap\modules\cloudbuild\[main.tf](http://main.tf/) line 194, in resource "null_resource" "cloudbuild_terraform_builder":
│  194:   provisioner "local-exec" {
│
│ Error running command '      gcloud builds submit .terraform/modules/cloudbuild_bootstrap/modules/cloudbuild/cloudbuild_builder/ --project prj-b-cicd-c727
│ --config=.terraform/modules/cloudbuild_bootstrap/modules/cloudbuild/cloudbuild_builder/cloudbuild.yaml
│ --substitutions=_TERRAFORM_VERSION=0.13.7,_TERRAFORM_VERSION_SHA256SUM=4a52886e019b4fdad2439da5ff43388bbcc6cce9784fde32c53dcd0e28ca9957,_TERRAFORM_VALIDATOR_RELEASE=v0.6.0,_REGION=europe-west2,_REPOSITORY=prj-tf-runners

ERROR: build step 1 "[europe-west2-docker.pkg.dev/prj-b-cicd-c727/prj-tf-runners/terraform](http://europe-west2-docker.pkg.dev/prj-b-cicd-c727/prj-tf-runners/terraform)" failed: step exited with non-zero status: 1

Terraform Configuration

n/a - error stems from entrypoint.bash

Terraform Version

1.1.7

Additional information

No response

daniel-cit commented 2 years ago

Hi @harrytsee Thanks for the report.

Downloading a zip file with the source code for the bootstrap module (the source of the entrypoint.bash file) it is possible to check that the line ending used in the file is LF.

Maybe the issue is been caused by the automatic substitution that git does with the line ending of the files in the Windows SO?

github-actions[bot] commented 2 years ago

This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 7 days