opendevstack / ods-quickstarters

Contains project quickstarters (boilerplates) for Nginx, Go, Java (Spring Boot), Python (Flask), Rust (Axum), Scala (Play), TypeScript (Express), Angular, Ionic, Jupyter, RShiny - all including CI/CD integration & Jenkins build agents
Apache License 2.0
27 stars 39 forks source link

AWS Quickstarter: Stage Smoke will be executed though Stage Deploy raised an AlreadyExistsException #680

Closed nichtraunzer closed 2 years ago

nichtraunzer commented 2 years ago

When deploying a CloudFormation Stack with the QS, and a Stack with the same name exists already terraform raises an "AlreadyExistsException" Error: creating CloudFormation stack failed: AlreadyExistsException: Stack [stack-aws-quickstarter] already exists That behavior is expected and correct. But this error is not handled by Jenkins, because it still proceeds, calls the next stage (smoke) and finally fails in this stage. It seems that either the terraform apply does not recognize that as an error or the error handling inside Jenkins has an issue.

Steps to reproduce the behavior:

  1. create a cloud formation stack called stack-aws-quickstarter in your AWSaccount manually
  2. run the default AWS QS in the same account via ODS
  3. Verify console output

Expected behavior Stack should stop in the deploy stage already

Affected version

Log Output Stage Deploy

TF_IN_AUTOMATION=1 TF_WORKSPACE="default" terraform apply -auto-approve -input=false -no-color tfplan | tee "./reports/install/tf_apply.log"
aws_cloudformation_stack.cft-s3: Creating...

Error: creating CloudFormation stack failed: AlreadyExistsException: Stack [stack-aws-quickstarter] already exists
    status code: 400, request id: d04164de-a237-46db-a93d-47a12a8aa672

  with aws_cloudformation_stack.cft-s3,
  on main.tf line 14, in resource "aws_cloudformation_stack" "cft-s3":
  14: resource "aws_cloudformation_stack" "cft-s3" {

Stage Smoke

for profile in $inspec_profiles; do \
    JSON_VARS_FILE="/tmp/workspace/azure-cd/azure-cd-aaws-master/terraform.tfvars.json" bundle exec cinc-auditor exec ./test/integration/$profile --no-create-lockfile --no-distinct-exit --input-file ./test/integration/$profile/files/inputs-from-tfo-stack.yml --reporter=cli junit2:build/test-results/test/$profile.xml json:reports/install/data/inspec/post-install/$profile.json --target aws://; \
done
[2021-11-24T16:54:40+00:00] ERROR: Failed to load profile stack: Failed to load source for controls/default.rb: No such file or directory @ rb_sysopen - .terraform-data.json

Profile:         stack
Version:         (not specified)
Failure Message: Failed to load source for controls/default.rb: No such file or directory @ rb_sysopen - .terraform-data.json
Target:          aws://

     No tests executed.
nichtraunzer commented 2 years ago

terraform apply throws exit code 1

TF_IN_AUTOMATION=1 TF_WORKSPACE="default" terraform apply -auto-approve -input=false -no-color tfplan || (echo "tf apply exit status $?").

Error: creating CloudFormation stack failed: AlreadyExistsException: Stack [stack-aws-quickstarter] already exists

tf apply exit status 1
nichtraunzer commented 2 years ago

Will verify exit status in Jenkins file. Also check what the @ in the makefile means https://github.com/opendevstack/ods-quickstarters/blob/3fa162e5eebca1f4b425fa67b899afa5b0f2d45e/inf-terraform-aws/files/Makefile#L82